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:

  • Property 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.
  • Property 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.
  • Property 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.
  • Property Name - a custom Name for the Control, in case you need to identify it later.
  • Property Appearance - the Appearance of the Control.
  • Property 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.
  • Property Status - the State of the Control
  • Property Visibility - the visibility state of the Control (Visible, Hidden, Collapsed). A Collapsed control takes no space.
  • Property Tag - a generic Object tag property, useful for keeping additional data.
  • Property 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

  • Property 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
  • Property 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.
  • Property 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:

  • Event OnGameUpdate(Control control, float msFrame) - called on every frame.
  • Event OnStatusChange(Control control, ControlStatus previousValue, ControlStatus newValue)
  • Event OnVisibilityChange(Control control, ControlVisibility previousValue, ControlVisibility newValue)

Finally, virtual methods that can be overridden if desierd:

  • Method OnMouseEnterEvent - when the mouse enters the Control's area.
  • Method OnMouseLeaveEvent - when the mouse leaves the Control's area.
  • Method OnUpdate - called on every frame.