Skip to content

Control

mdavisprog edited this page Apr 5, 2023 · 2 revisions

Control

Controls are the base objects that make up a GUI element. All controls must be a part of a Container in order to be positioned, updated, and painted.

This class contains a number of virtual functions that are invoked whenever the state of the GUI changes. All classes that inherit from Control can override the desired functions to implement the desired behavior.

Functions

Name Description
SetPosition All control's positioning is relative to it's parent. When the position is set, the control's layout is invalidated, notifying the owning container to update it's layout with this new position for this control.

PositionRelative position of this control. This Control reference.
GetPosition Vector2 relative position.
GetAbsolutePosition Vector2 absolute position.
SetSize If the size is different, a layout invalidate request is sent and the owning container will re-layout its contents with this new size for this control. The OnResized function will be called on this control before the layout occurs.

SizeVector2 of the new size for this control. This Control Reference.
GetSize Vector2 of this control's size.
SetParent The parent is usually a Container by in some cases may be another control.

ParentThe parent control for this control. Can be NULL. This Control reference.
GetParent Pointer to the parent control. May be NULL.
SetExpand The Expand type tells the owning Container how this control should be sized during any layouts. Control's by default do not expand in any direction. This value can either be None, Width, Height, or Both. If the control is set to be a fixed size, then no change is made when this function is called.

InExpandThe Expand type to set for this control. This Control reference.
GetExpand Expand type.
SetForwardKeyEvents Containers may want to handle key events but due to the architecture only allowing Controls to have focus, Containers will not be able to directly receive these events. Setting this flag will allow for this to occur.

ForwardBoolean to set whether key events should be forwarded. This Control reference.
ShouldForwardKeyEvents Boolean value.
SetForwardMouseEvents Containers may want to handle mouse events but due to the architecture only allowing Controls to have focus, Containers will not be able to directly receive these events. Setting this flag will allow for this to occur.

ForwardBoolean to set whether mouse events should be forwarded. This Control reference.
ShouldForwardMouseEvents Boolean value.
SetID Giving a control an ID uniquely identifies this control. The full ID path to this control takes into account the parent ID. For example, if the parent control has an ID of 'Parent' and this control has an ID of 'Child', the full ID would be 'Parent.Child'.

The main usage for giving control's an ID is to retrieve a reference to this control whenever an API that accepts a ControlList object is called. This object will retrieve all controls that have a specified ID and add them for retrieval by the caller. This allows for altering any additional settings and registering callbacks.

IDString defining the unique identifier for this control. This Control reference.
GetID String pointer to the control's ID.
GetFullID String object with the full ID.
HasID True if the control has an ID. False otherwise.
Contains PositionThe point to query if it is within the bounds. True if the point is in bounds. False otherwise.
GetBounds The Rect that defines the local bounds for this control.
GetAbsoluteBounds The Rect that defines the absolute bounds for this control.
SetWindow This function is defined to be virtual as some controls may need to perform additional logic when the owning window has changed.

InWindowThe new owning Window object for this control.
GetWindow Pointer to the Window object for this control.
RenderScale The Vector2 scale for rendering.
GetMousePosition The Vector2 mouse position.
GetTheme Shared pointer to the Theme object.
IsKeyPressed KeyThe key to check if it is pressed. True if the given key is pressed. False otherwise.
SetOnInvalidate The callback is invoked whenever a request for invalidation of this control occurs. The callback accepts the control and the type of invalidation requested.

FnThe callback to invoke. This Control reference.
Invalidate TypeCan either be a Paint or Layout request. This Control reference.
SetProperty Theme properties the control uses are read from the current Theme object if no property of the given type exists within this control.

PropertyThe theme property to override. ValueThe value to override the property with. This Control reference.
GetProperty PropertyThe property to retrieve. The Variant that contains the value for the property.
ClearProperty PropertyThe property to clear from this control. This Control reference.
Share A newly created shared_ptr object.
Share A newly created const shared_ptr object.
TShare TThe Control type to cast to. A newly created casted shared_ptr object.
TShare TThe Control type to cast to. A newly created casted const shared_ptr object.
Load This function provides a quick method of altering control properties after the control has been created. This is useful for adding additional controls to containers without using the API.

StreamJSON string.
OnPaint This is called for all controls of a given Window when a repaint request is issued. This can come from another control or from outside the library such as an event fired from the frontend.

BrushThe object to add painting commands to.
Update Notifies the control that it's layout is complete within a given container.
OnFocused A control may receive focus within a Window if its OnMousePressed function returns true. This tells the frontend that a focus request has occurred. A specific control can also be requested through the Window::SetFocus function.
OnUnfocused Notifies the control that is losing focus.
OnLoad A Window may have its controls defined within a JSON stream. The Window will parse the stream into a hierarchy of JSON objects and is passed to each control to give them an opportunity to load any properties that define the control. The stream can come from a list of places such as a disk, memory, or network stream.

RootThe Json object containing the properties to load for this control.
OnSave This may be called from any number of places which may wish to get information about controls. This JSON object can then be used to serialize the information to disk or be displayed in some other output device.

RootThe Json object to write properties of this control into.

Clone this wiki locally