Download Now

    Reference TWidget

    Declared in Codebot.Render.Widgets.pas on line 227

    TWidget is the base class for ui controls. A widget is created by giving it a parent and rectangle using the create constructor. A widget is destroyed by freeing its parent, freeing the widget, or deleteing it from its parent.
    Any children of a widget are destroyed when the widget is destroyed.
      TWidget = class
      public
        type
        TWidgetEnumerator = IEnumerator<TWidget>;
        { Enumerates the children of the widget }
        function GetEnumerator: TWidgetEnumerator;
      protected
        procedure Paint(Stage: TPaintStage); virtual;
        function AutoSize: Boolean; virtual;
        procedure Resize; virtual;
        procedure Repack; virtual;
        function GetBorders: TRectF; virtual;
        function CanSelect: Boolean; virtual;
        procedure AddState(Part: TWidgetStatePart);
        procedure RemoveState(Part: TWidgetStatePart);
        procedure Change; virtual;
        procedure DoModalResult; virtual;
        procedure DoClick; virtual;
        procedure DoKeyDown(var Args: TSceneKeyArgs); virtual;
        procedure DoKeyUp(var Args: TSceneKeyArgs); virtual;
        procedure DoMouseDown(var Args: TSceneMouseArgs); virtual;
        procedure DoMouseMove(var Args: TSceneMouseArgs); virtual;
        procedure DoMouseUp(var Args: TSceneMouseArgs); virtual;
        procedure DoTextInput(var Args: TSceneTextArgs); virtual;
        procedure DoMouseWheel(var Args: TSceneWheelArgs); virtual;
        { Events }
        property OnChange: TNotifyEvent read FOnChange write FOnChange;
        property OnClick: TNotifyEvent read FOnClick write FOnClick;
        property OnKeyDown: TSceneKeyEvent read FOnKeyDown write FOnKeyDown;
        property OnKeyUp: TSceneKeyEvent read FOnKeyUp write FOnKeyUp;
        property OnMouseDown: TSceneMouseEvent read FOnMouseDown write FOnMouseDown;
        property OnMouseMove: TSceneMouseEvent read FOnMouseMove write FOnMouseMove;
        property OnMouseUp: TSceneMouseEvent read FOnMouseUp write FOnMouseUp;
      public
        { Create a widget as a child of a parent, optionally giving it a name }
        constructor Create(Parent: TWidget; const Name: string = ''); virtual;
        destructor Destroy; override;
        { Alias for self }
        function This: TWidget;
        { Add a widget of type T as a child of this widget optinally giving it a
          name }
        function Add<T: TWidget>(const Name: string = ''): T; overload;
        { Add overload ot type T capturing the new child }
        function Add<T: TWidget>(out Child: T; const Name: string = ''): T; overload;
        { Add a widget of type T as the first child of this widget }
        function AddFirst<T: TWidget>(const Name: string = ''): T; overload;
        { AddFirst overload capturing the new child }
        function AddFirst<T: TWidget>(out Child: T; const Name: string = ''): T; overload;
        { Search for a widget at position x, y }
        function FindWidget(X, Y: Float): TWidget;
        { Search for a widget by name }
        function FindWidget<T: TWidget>(const Name: string): T;
        { Pack arranges child controls returning true if a pack was needed }
        function Pack: Boolean; virtual;
        { Invoke a click on the widget }
        procedure Click;
        { Deletes and destroys the child widget at index }
        procedure Delete(Index: Integer);
        { Returns true if the widget is in the child chain of a parent widget }
        function IsParent(Parent: TWidget): Boolean;
        { If the widget is top level activate it }
        procedure Activate;
        { If the widget is top level bring it to the top of the zorder }
        procedure BringToFront;
        { If the widget is top level send it to the bottom of the zorder }
        procedure SendToBack;
        { Move the widget up or down in zorder }
        procedure ZOrder(Delta: Integer);
        { Calculate a theme color for this widget }
        function Color(Color: TThemeColor): TColorF;
        { The computed properties of the widget }
        property Computed: TComputedWidget read FComputed;
        { Themes can be applied down to the widget level }
        property Theme: TTheme read FTheme write SetTheme;
        { Align is used when packing the widget inside a container }
        property Align: TWidgetAlign read FAlign write SetAlign;
        { If the parent is the main widget, then sector applies a fixed placement }
        property Sector: Integer read FSector write FSector;
        { If the parent is the main widget, then put the wiget above all others }
        property StayOnTop: Boolean read FStayOnTop write FStayOnTop;
        { If the parent is the main widget, then the widget and everything inside it
          is drawn transformed by this matrix, and the mouse is mapped back through
          it, so the widget works the same when it is scaled, rotated, or skewed. It
          is nil by default, which is no transform. }
        property Matrix: IMatrix read FMatrix write FMatrix;
        { A rectangle relative to the partent designating size and position of this
          widget }
        property Bounds: TRectF read FBounds write SetBounds;
        { If hint is set and the main widgets allows hints, then display a tooltip }
        property Hint: string read FHint write FHint;
        { The main widget to which this widget belongs }
        property Main: TMainWidget read GetMain;
        { The immediate parent of this widget }
        property Parent: TWidget read FParent;
        { The top level contaier of this widget }
        property Container: TContainerWidget read GetContainer;
        { The first child of this widget }
        property FirstChild: TWidget read GetFirstChild;
        { The last child of this widget }
        property LastChild: TWidget read GetLastChild;
        { The number of child widgets }
        property ChildCount: Integer read GetChildCount;
        { Access to child widgets }
        property Child[Index: Integer]: TWidget read GetChild;
        { Position and size properties }
        property X: Float index 0 read GetDim write SetDim;
        property Y: Float index 1 read GetDim write SetDim;
        property Width: Float index 2 read GetDim write SetDim;
        property Height: Float index 3 read GetDim write SetDim;
        { The space kept around the widget when it is packed }
        property Margin: Float read FMargin write SetMargin;
        { The number of indents the widget is moved across when it is packed. The
          theme sets the size of an indent. }
        property Indent: Integer read FIndent write SetIndent;
        { Name can be used to seearch for the widget }
        property Name: string read FName write FName;
        { Opacity of the widget in the range from 0 to 1 }
        property Opacity: Float read FOpacity write FOpacity;
        { The text or caption shown by the widget }
        property Text: string read FText write SetText;
        { When false the widget and its children are not shown }
        property Visible: Boolean read FVisible write SetVisible;
        { When false the widget and its children take no input and are drawn
          disabled }
        property Enabled: Boolean read FEnabled write FEnabled;
        { Singal the parent window with this value if the widget is clicked }
        property ModalResult: TModalResult read FModalResult write SetModalResult;
        { See TWidgetStatePart }
        property State: TWidgetState read FState;
        { When unpacked is true the widget ignores all packing rules }
        property Unpacked: Boolean read FUnpacked write SetUnpacked;
        { User data tag property }
        property Tag: PtrInt read FTag write FTag;
      end;

    See also

    Float in Codebot.System.pas
    IMatrix in Codebot.Render.Graphics.pas
    TColorF in Codebot.Graphics.Types.pas
    TRectF in Codebot.Graphics.Types.pas
    TSceneKeyArgs in Codebot.Render.Scenes.pas
    TSceneKeyEvent in Codebot.Render.Scenes.pas
    TSceneMouseArgs in Codebot.Render.Scenes.pas
    TSceneMouseEvent in Codebot.Render.Scenes.pas
    TSceneTextArgs in Codebot.Render.Scenes.pas
    TSceneWheelArgs in Codebot.Render.Scenes.pas