Control - SirePi/duality-ui GitHub Wiki
A Control is the smalles unit of interaction with the UI; it currently comes in three distinct flavors:
It exposes a number of properties, the most useful ones being the following:
- Size - the desired size, in pixels, that the control should keep. It can change, depending on the configuration, and the kind of ControlContainer it is placed into and, in some cases, it can even be left to its default value.
- Position - the position of the control relative to its parent (either the game window, or another Control); usually this can be ignored, unless you are placing your control inside a CanvasPanel, or it's the root ControlContainer in the UI, and it's not a Fullscreen UI.
- ActualSize and ActualPosition are to be considered as read-only properties, although they are not. They are automatically recalculated each frame and represent the actual size and global position on screen of the Control.
- Name - a custom Name for the Control, in case you need to identify it later.
- Appearance - the Appearance of the Control.
- TemplateName - it's used in combination with a Skin, and determines its Appearance and configuration. If not set, the Control will look for a template with the same name as its Type's Name.
- Status - the State of the Control
- Visibility - the visibility state of the Control (Visible, Hidden, Collapsed). A Collapsed control takes no space.
- Tag - a generic Object tag property, useful for keeping additional data.
- Uniforms - a <string, float[]> dictionary which lets you set uniforms to be used when rendering the Control with shaders.
Then, there are the layout properties
- Cell - it's used in combination with a GridPanel parent. It lets you set the Control's size and position inside a grid. Supports Row, Column, RowSpan and ColumnSpan
- Docking - it's used in combination with a DockPanel parent. It lets you set the Control's docking side, and affects its size and position.
- StretchToFill - if set to true (default value), lets the Control take all the available space in its assigned layout slot.
In addition to properties, there are a number of events that can be subscribed to:
- OnGameUpdate(Control control, float msFrame) - called on every frame.
- OnStatusChange(Control control, ControlStatus previousValue, ControlStatus newValue)
- OnVisibilityChange(Control control, ControlVisibility previousValue, ControlVisibility newValue)
Finally, virtual methods that can be overridden if desierd:
- OnMouseEnterEvent - when the mouse enters the Control's area.
- OnMouseLeaveEvent - when the mouse leaves the Control's area.
- OnUpdate - called on every frame.