Skip to content

ControlBase Class

Base class for all controls.

C#
[DataContract]
public abstract class ControlBase

Inheritance object

Creates a control.

C#
protected ControlBase(int width, int height)

width int

height int

A cached value determined by OnMouseEnter(ControlMouseState). true when the mouse is over the bounds defined by MouseArea .

C#
protected bool MouseState_IsMouseOver

A cached value determined by OnMouseEnter(ControlMouseState). true when the mouse entered the control’s bounds with the mouse button down.

C#
protected bool MouseState_EnteredWithButtonDown

A cached value determined by OnMouseIn(ControlMouseState). true when the left mouse button is down.

C#
protected bool MouseState_IsMouseLeftDown

A cached value determined by OnMouseIn(ControlMouseState). true when the right mouse button is down.

C#
protected bool MouseState_IsMouseRightDown

The theme of the control based on its state.

C#
public ThemeStates ThemeState { get; set; }

true to allow this control to respond to keyboard interactions when focused.

C#
[DataMember]
public bool UseKeyboard { get; set; }

true to allow this control to respond to mouse interactions.

C#
[DataMember]
public bool UseMouse { get; set; }

true to indicate this control can be focused, generally by clicking on the control or tabbing with the keyboard. Otherwise false.

C#
[DataMember]
public bool CanFocus { get; set; }

When true, indicates that this control can be resized with the Resize(int, int) method; otherwise false.

C#
[DataMember]
public bool CanResize { get; protected set; }

An alternate font used to render this control.

C#
[DataMember]
public IFont? AlternateFont { get; set; }

The cell data to render the control. Controlled by a theme.

C#
public ICellSurface Surface { get; set; }

The relative region the of the control used for mouse input.

C#
[DataMember]
public Rectangle MouseArea { get; set; }

When true, indicates the mouse button state has only been set with this control and not another; otherwise false.

C#
public bool IsMouseButtonStateClean { get; }

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.

The relative position of this control.

C#
[DataMember]
public Point Position { get; set; }

Gets the position of this control based on the control’s Position and the position of the Parent.

C#
public Point AbsolutePosition { get; }

Indicates whether or not this control is visible.

C#
[DataMember]
public bool IsVisible { get; set; }

A user-definable data object.

C#
public object? Tag { get; set; }

Indicates whether or not this control can be tabbed to.

C#
[DataMember]
public bool TabStop { get; set; }

Sets the tab index of this control.

C#
[DataMember]
public int TabIndex { get; set; }

Indicates whether or not this control is dirty and should be redrawn.

C#
public bool IsDirty { get; set; }

Represents a name to identify a control by.

C#
[DataMember]
public string? Name { get; init; }

Gets or sets whether or not this control will become focused when the mouse is clicked.

C#
[DataMember]
public bool FocusOnMouseClick { get; set; }

The width of the control.

C#
public int Width { get; protected set; }

The height of the control.

C#
public int Height { get; protected set; }

Gets or sets whether or not this control is focused.

C#
public bool IsFocused { get; set; }

Gets or sets whether or not this control is enabled.

C#
[DataMember]
public bool IsEnabled { get; set; }

The area of the host this control covers.

C#
public Rectangle Bounds { get; }

Gets or sets the parent container of this control.

C#
public IContainer? Parent { get; set; }

The state of the control.

C#
public ControlStates State { get; protected set; }

Called when the control loses focus.

C#
protected virtual void OnUnfocused()

Called when the control is focused.

C#
protected virtual void OnFocused()

Called when the IsDirty property changes value.

C#
protected virtual void OnIsDirtyChanged()

Called when the keyboard is used on this control.

C#
public virtual bool ProcessKeyboard(Keyboard state)

state Keyboard
The state of the keyboard.

bool

Checks if the mouse is the control and calls the appropriate mouse methods.

C#
public virtual bool ProcessMouse(MouseScreenObjectState state)

state MouseScreenObjectState
Mouse information.

bool
True when the control is enabled, set to use the mouse and the mouse is over it, otherwise false.

Called to trigger the state of losing mouse focus.

C#
public void LostMouse(MouseScreenObjectState state)

state MouseScreenObjectState
The mouse state.

Called when the parent property is changed.

C#
protected virtual void OnParentChanged()

Called when the control changes position.

C#
protected virtual void OnPositionChanged()

Places this control relative to another, taking into account the bounds of the control.

C#
public void PlaceRelativeTo(ControlBase control, Direction.Types direction, int padding = 1)

control ControlBase
The other control to place this one relative to.

direction SadRogue.Primitives.Direction.Types
The direction this control should be placed.

padding int
Additional space between the controls after placement.

If this control hasn’t been added to the parent of control, it will be added.

Sets the appropriate theme for the control based on the current state of the control.

C#
public virtual void DetermineState()

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.

OnStateChanged(ControlStates, ControlStates)

Section titled “OnStateChanged(ControlStates, ControlStates)”

Called when the State changes. Sets the IsDirty to true.

C#
protected virtual void OnStateChanged(ControlStates oldState, ControlStates newState)

oldState ControlStates
The original state.

newState ControlStates
The new state.

OnSurfaceChanged(ICellSurface, ICellSurface)

Section titled “OnSurfaceChanged(ICellSurface, ICellSurface)”

Called when the Surface property is set.

C#
protected virtual void OnSurfaceChanged(ICellSurface oldSurface, ICellSurface newSurface)

oldSurface ICellSurface
The previous surface instance.

newSurface ICellSurface
The new surface instance.

Returns the AlternateFont. If null, returns the host’s console font or the default engine font.

C#
public IFont FindThemeFont()

IFont

Returns the colors assigned to this control, the parent, or the library default.

C#
public Colors FindThemeColors()

Colors
The found colors.

Sets the theme colors used by this control. When null, indicates this control should read the theme colors from the parent.

C#
public void SetThemeColors(Colors? value)

value Colors
The colors to use with this control.

When true, indicates the control has custom theme colors assigned to it; othwerise false.

C#
public bool HasThemeColors()

bool

Resizes the control if the CanResize property is true.

C#
public virtual void Resize(int width, int height)

width int
The desired width of the control.

height int
The desired height of the control.

Called when Resize(int, int) was called.

C#
protected virtual void OnResized()

Generates the surface to be used by this control. This method is called internally to assign the Surface property a value.

C#
protected virtual ICellSurface CreateControlSurface()

ICellSurface
A surface that should be assigned to the Surface property.

Updates the ThemeState by calling RefreshTheme(Colors) with the provided colors. Override this method to adjust how colors are used by the ThemeState.

C#
protected virtual void RefreshThemeStateColors(Colors colors)

colors Colors
The colors to apply to the theme state.

Called when the mouse first enters the control. Raises the MouseEnter event and calls the DetermineState() method.

C#
protected virtual void OnMouseEnter(ControlBase.ControlMouseState state)

state ControlBase.ControlMouseState
The current mouse data

Called when the mouse exits the area of the control. Raises the MouseExit event and calls the DetermineState() method.

C#
protected virtual void OnMouseExit(ControlBase.ControlMouseState state)

state ControlBase.ControlMouseState
The current mouse data

Called as the mouse moves around the control area. Raises the MouseMove event and calls the DetermineState() method.

C#
protected virtual void OnMouseIn(ControlBase.ControlMouseState state)

state ControlBase.ControlMouseState
The current mouse data

Called when the left mouse button is clicked. Raises the MouseButtonClicked event and calls the DetermineState() method.

C#
protected virtual void OnLeftMouseClicked(ControlBase.ControlMouseState state)

state ControlBase.ControlMouseState
The current mouse data

Called when the right mouse button is clicked. Raises the MouseButtonClicked event and calls the DetermineState() method.

C#
protected virtual void OnRightMouseClicked(ControlBase.ControlMouseState state)

state ControlBase.ControlMouseState
The current mouse data.

Redraws the control if applicable.

C#
public abstract void UpdateAndRedraw(TimeSpan time)

time TimeSpan
The duration of thecurrent frame.

Raised when the IsDirty property changes.

C#
public event EventHandler<EventArgs>? IsDirtyChanged

EventHandler<EventArgs>

Raised when the IsFocused is set to true.

C#
public event EventHandler<EventArgs>? Focused

EventHandler<EventArgs>

Raised when the IsFocused is set to false.

C#
public event EventHandler<EventArgs>? Unfocused

EventHandler<EventArgs>

Raised when the Position property changes value.

C#
public event EventHandler<EventArgs>? PositionChanged

EventHandler<EventArgs>

Raised when the mouse enters this control.

C#
public event EventHandler<ControlBase.ControlMouseState>? MouseEnter

EventHandler<ControlBase.ControlMouseState>

Raised when the mouse exits this control.

C#
public event EventHandler<ControlBase.ControlMouseState>? MouseExit

EventHandler<ControlBase.ControlMouseState>

Raised when the mouse is moved over this control.

C#
public event EventHandler<ControlBase.ControlMouseState>? MouseMove

EventHandler<ControlBase.ControlMouseState>

Raised when a mouse button is clicked while the mouse is over this control.

C#
public event EventHandler<ControlBase.ControlMouseState>? MouseButtonClicked

EventHandler<ControlBase.ControlMouseState>