Class ControlBase
Base class for all controls.
Inheritance
Inherited Members
Namespace: SadConsole.UI.Controls
Assembly: SadConsole.dll
Syntax
[DataContract]
public abstract class ControlBase
Constructors
ControlBase(int, int)
Creates a control.
Declaration
protected ControlBase(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
int | width | |
int | height |
Fields
MouseState_EnteredWithButtonDown
A cached value determined by OnMouseEnter(ControlMouseState). true when the mouse entered the control's bounds with the mouse button down.
Declaration
protected bool MouseState_EnteredWithButtonDown
Field Value
Type | Description |
---|---|
bool |
MouseState_IsMouseLeftDown
A cached value determined by OnMouseIn(ControlMouseState). true when the left mouse button is down.
Declaration
protected bool MouseState_IsMouseLeftDown
Field Value
Type | Description |
---|---|
bool |
MouseState_IsMouseOver
A cached value determined by OnMouseEnter(ControlMouseState). true when the mouse is over the bounds defined by MouseArea .
Declaration
protected bool MouseState_IsMouseOver
Field Value
Type | Description |
---|---|
bool |
MouseState_IsMouseRightDown
A cached value determined by OnMouseIn(ControlMouseState). true when the right mouse button is down.
Declaration
protected bool MouseState_IsMouseRightDown
Field Value
Type | Description |
---|---|
bool |
Properties
AbsolutePosition
Declaration
public Point AbsolutePosition { get; }
Property Value
Type | Description |
---|---|
Point |
AlternateFont
An alternate font used to render this control.
Declaration
[DataMember]
public IFont? AlternateFont { get; set; }
Property Value
Type | Description |
---|---|
IFont |
Bounds
The area of the host this control covers.
Declaration
public Rectangle Bounds { get; }
Property Value
Type | Description |
---|---|
Rectangle |
CanFocus
true to indicate this control can be focused, generally by clicking on the control or tabbing with the keyboard. Otherwise false.
Declaration
[DataMember]
public bool CanFocus { get; set; }
Property Value
Type | Description |
---|---|
bool |
CanResize
When true, indicates that this control can be resized with the Resize(int, int) method; otherwise false.
Declaration
[DataMember]
public bool CanResize { get; protected set; }
Property Value
Type | Description |
---|---|
bool |
FocusOnMouseClick
Gets or sets whether or not this control will become focused when the mouse is clicked.
Declaration
[DataMember]
public bool FocusOnMouseClick { get; set; }
Property Value
Type | Description |
---|---|
bool |
Height
The height of the control.
Declaration
public int Height { get; protected set; }
Property Value
Type | Description |
---|---|
int |
IsDirty
Indicates whether or not this control is dirty and should be redrawn.
Declaration
public bool IsDirty { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsEnabled
Gets or sets whether or not this control is enabled.
Declaration
[DataMember]
public bool IsEnabled { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsFocused
Gets or sets whether or not this control is focused.
Declaration
public bool IsFocused { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsMouseButtonStateClean
When true, indicates the mouse button state has only been set with this control and not another; othwerise false.
Declaration
public bool IsMouseButtonStateClean { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
This property is only set when the mouse enters the control with the buttons pressed. Once the buttons are let go, the mouse is considered clean for this control.
IsVisible
Indicates whether or not this control is visible.
Declaration
[DataMember]
public bool IsVisible { get; set; }
Property Value
Type | Description |
---|---|
bool |
MouseArea
The relative region the of the control used for mouse input.
Declaration
[DataMember]
public Rectangle MouseArea { get; set; }
Property Value
Type | Description |
---|---|
Rectangle |
Name
Represents a name to identify a control by.
Declaration
[DataMember]
public string? Name { get; init; }
Property Value
Type | Description |
---|---|
string |
Parent
Gets or sets the parent container of this control.
Declaration
public IContainer? Parent { get; set; }
Property Value
Type | Description |
---|---|
IContainer |
Position
The relative position of this control.
Declaration
[DataMember]
public Point Position { get; set; }
Property Value
Type | Description |
---|---|
Point |
State
The state of the control.
Declaration
public ControlStates State { get; protected set; }
Property Value
Type | Description |
---|---|
ControlStates |
Surface
The cell data to render the control. Controlled by a theme.
Declaration
public ICellSurface Surface { get; set; }
Property Value
Type | Description |
---|---|
ICellSurface |
TabIndex
Sets the tab index of this control.
Declaration
[DataMember]
public int TabIndex { get; set; }
Property Value
Type | Description |
---|---|
int |
TabStop
Indicates whether or not this control can be tabbed to.
Declaration
[DataMember]
public bool TabStop { get; set; }
Property Value
Type | Description |
---|---|
bool |
Tag
A user-definable data object.
Declaration
public object? Tag { get; set; }
Property Value
Type | Description |
---|---|
object |
ThemeState
The theme of the control based on its state.
Declaration
public ThemeStates ThemeState { get; set; }
Property Value
Type | Description |
---|---|
ThemeStates |
UseKeyboard
true to allow this control to respond to keyboard interactions when focused.
Declaration
[DataMember]
public bool UseKeyboard { get; set; }
Property Value
Type | Description |
---|---|
bool |
UseMouse
true to allow this control to respond to mouse interactions.
Declaration
[DataMember]
public bool UseMouse { get; set; }
Property Value
Type | Description |
---|---|
bool |
Width
The width of the control.
Declaration
public int Width { get; protected set; }
Property Value
Type | Description |
---|---|
int |
Methods
CreateControlSurface()
Generates the surface to be used by this control. This method is called internally to assign the Surface property a value.
Declaration
protected virtual ICellSurface CreateControlSurface()
Returns
Type | Description |
---|---|
ICellSurface | A surface that should be assigned to the Surface property. |
DetermineState()
Sets the appropriate theme for the control based on the current state of the control.
Declaration
public virtual void DetermineState()
Remarks
Called by the control as the mouse state changes, like when the mouse is clicked on top of the control or leaves the area of the control. This method is implemented by each derived control.
FindThemeColors()
Returns the colors assigned to this control, the parent, or the library default.
Declaration
public Colors FindThemeColors()
Returns
Type | Description |
---|---|
Colors | The found colors. |
FindThemeFont()
Returns the AlternateFont. If null, returns the host's console font or the default engine font.
Declaration
public IFont FindThemeFont()
Returns
Type | Description |
---|---|
IFont |
HasThemeColors()
Declaration
public bool HasThemeColors()
Returns
Type | Description |
---|---|
bool |
LostMouse(MouseScreenObjectState)
Called to trigger the state of losing mouse focus.
Declaration
public void LostMouse(MouseScreenObjectState state)
Parameters
Type | Name | Description |
---|---|---|
MouseScreenObjectState | state | The mouse state. |
OnFocused()
Called when the control is focused.
Declaration
protected virtual void OnFocused()
OnIsDirtyChanged()
Called when the IsDirty property changes value.
Declaration
protected virtual void OnIsDirtyChanged()
OnLeftMouseClicked(ControlMouseState)
Called when the left mouse button is clicked. Raises the MouseButtonClicked event and calls the DetermineState() method.
Declaration
protected virtual void OnLeftMouseClicked(ControlBase.ControlMouseState state)
Parameters
Type | Name | Description |
---|---|---|
ControlBase.ControlMouseState | state | The current mouse data |
OnMouseEnter(ControlMouseState)
Called when the mouse first enters the control. Raises the MouseEnter event and calls the DetermineState() method.
Declaration
protected virtual void OnMouseEnter(ControlBase.ControlMouseState state)
Parameters
Type | Name | Description |
---|---|---|
ControlBase.ControlMouseState | state | The current mouse data |
OnMouseExit(ControlMouseState)
Called when the mouse exits the area of the control. Raises the MouseExit event and calls the DetermineState() method.
Declaration
protected virtual void OnMouseExit(ControlBase.ControlMouseState state)
Parameters
Type | Name | Description |
---|---|---|
ControlBase.ControlMouseState | state | The current mouse data |
OnMouseIn(ControlMouseState)
Called as the mouse moves around the control area. Raises the MouseMove event and calls the DetermineState() method.
Declaration
protected virtual void OnMouseIn(ControlBase.ControlMouseState state)
Parameters
Type | Name | Description |
---|---|---|
ControlBase.ControlMouseState | state | The current mouse data |
OnParentChanged()
Called when the parent property is changed.
Declaration
protected virtual void OnParentChanged()
OnPositionChanged()
Called when the control changes position.
Declaration
protected virtual void OnPositionChanged()
OnResized()
Called when Resize(int, int) was called.
Declaration
protected virtual void OnResized()
OnRightMouseClicked(ControlMouseState)
Called when the right mouse button is clicked. Raises the MouseButtonClicked event and calls the DetermineState() method.
Declaration
protected virtual void OnRightMouseClicked(ControlBase.ControlMouseState state)
Parameters
Type | Name | Description |
---|---|---|
ControlBase.ControlMouseState | state | The current mouse data. |
OnStateChanged(ControlStates, ControlStates)
Declaration
protected virtual void OnStateChanged(ControlStates oldState, ControlStates newState)
Parameters
Type | Name | Description |
---|---|---|
ControlStates | oldState | The original state. |
ControlStates | newState | The new state. |
OnSurfaceChanged(ICellSurface, ICellSurface)
Called when the Surface property is set.
Declaration
protected virtual void OnSurfaceChanged(ICellSurface oldSurface, ICellSurface newSurface)
Parameters
Type | Name | Description |
---|---|---|
ICellSurface | oldSurface | The previous surface instance. |
ICellSurface | newSurface | The new surface instance. |
OnUnfocused()
Called when the control loses focus.
Declaration
protected virtual void OnUnfocused()
PlaceRelativeTo(ControlBase, Types, int)
Places this control relative to another, taking into account the bounds of the control.
Declaration
public void PlaceRelativeTo(ControlBase control, Direction.Types direction, int padding = 1)
Parameters
Type | Name | Description |
---|---|---|
ControlBase | control | The other control to place this one relative to. |
Direction.Types | direction | The direction this control should be placed. |
int | padding | Additional space between the controls after placement. |
Remarks
If this control hasn't been added to the parent of control
, it will be added.
ProcessKeyboard(Keyboard)
Called when the keyboard is used on this control.
Declaration
public virtual bool ProcessKeyboard(Keyboard state)
Parameters
Type | Name | Description |
---|---|---|
Keyboard | state | The state of the keyboard. |
Returns
Type | Description |
---|---|
bool |
ProcessMouse(MouseScreenObjectState)
Checks if the mouse is the control and calls the appropriate mouse methods.
Declaration
public virtual bool ProcessMouse(MouseScreenObjectState state)
Parameters
Type | Name | Description |
---|---|---|
MouseScreenObjectState | state | Mouse information. |
Returns
Type | Description |
---|---|
bool | True when the control is enabled, set to use the mouse and the mouse is over it, otherwise false. |
RefreshThemeStateColors(Colors)
Updates the ThemeState by calling RefreshTheme(Colors) with the provided colors. Override this method to adjust how colors are used by the ThemeState.
Declaration
protected virtual void RefreshThemeStateColors(Colors colors)
Parameters
Type | Name | Description |
---|---|---|
Colors | colors | The colors to apply to the theme state. |
Resize(int, int)
Declaration
public virtual void Resize(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
int | width | The desired width of the control. |
int | height | The desired height of the control. |
SetThemeColors(Colors?)
Sets the theme colors used by this control. When null, indicates this control should read the theme colors from the parent.
Declaration
public void SetThemeColors(Colors? value)
Parameters
Type | Name | Description |
---|---|---|
Colors | value | The colors to use with this control. |
UpdateAndRedraw(TimeSpan)
Redraws the control if applicable.
Declaration
public abstract void UpdateAndRedraw(TimeSpan time)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | time | The duration of thecurrent frame. |
Events
Focused
Declaration
public event EventHandler<EventArgs>? Focused
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
IsDirtyChanged
Raised when the IsDirty property changes.
Declaration
public event EventHandler<EventArgs>? IsDirtyChanged
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
MouseButtonClicked
Raised when a mouse button is clicked while the mouse is over this control.
Declaration
public event EventHandler<ControlBase.ControlMouseState>? MouseButtonClicked
Event Type
Type | Description |
---|---|
EventHandler<ControlBase.ControlMouseState> |
MouseEnter
Raised when the mouse enters this control.
Declaration
public event EventHandler<ControlBase.ControlMouseState>? MouseEnter
Event Type
Type | Description |
---|---|
EventHandler<ControlBase.ControlMouseState> |
MouseExit
Raised when the mouse exits this control.
Declaration
public event EventHandler<ControlBase.ControlMouseState>? MouseExit
Event Type
Type | Description |
---|---|
EventHandler<ControlBase.ControlMouseState> |
MouseMove
Raised when the mouse is moved over this control.
Declaration
public event EventHandler<ControlBase.ControlMouseState>? MouseMove
Event Type
Type | Description |
---|---|
EventHandler<ControlBase.ControlMouseState> |
PositionChanged
Raised when the Position property changes value.
Declaration
public event EventHandler<EventArgs>? PositionChanged
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |
Unfocused
Declaration
public event EventHandler<EventArgs>? Unfocused
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |