Download Now

    Reference TListBox

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

    TListBox shows a list of items, one of which can be selected by clicking it or with the Up, Down, Home, End, Prior, and Next keys. Dragging the mouse over the items selects the item under it. While the mouse is held above or below the items during a drag the list scrolls on a timer, whether or not the mouse moves. A vertical scroll bar is shown when the items do not fit, and the mouse wheel scrolls the list. OnChange fires when ItemIndex changes. The list box keeps the size it is given, 200 by 200 by default.
      TListBox = class(TWidget)
      protected
        function AutoSize: Boolean; override;
        function CanSelect: Boolean; override;
        procedure Paint(Stage: TPaintStage); override;
        procedure DoKeyDown(var Args: TSceneKeyArgs); override;
        procedure DoMouseDown(var Args: TSceneMouseArgs); override;
        procedure DoMouseMove(var Args: TSceneMouseArgs); override;
        procedure DoMouseUp(var Args: TSceneMouseArgs); override;
        procedure DoMouseWheel(var Args: TSceneWheelArgs); override;
      public
        constructor Create(Parent: TWidget; const Name: string = ''); override;
        { Scroll the list so the item at index can be seen }
        procedure ScrollToItem(Index: Integer);
        { The methods below are used by themes to draw the list box. Rectangles are
          relative to the top left of the list box. }
        function ItemHeight: Float;
        { The area holding the items, inside the frame and scroll bar }
        function ItemArea: TRectF;
        { The rectangle of an item, moved by the scroll position }
        function ItemRect(Index: Integer): TRectF;
        { The item at a point, or -1 if there is none }
        function ItemFromPoint(X, Y: Float): Integer;
        { True if the scroll bar is showing }
        function BarVisible: Boolean;
        { The rectangle of the scroll bar }
        function BarRect: TRectF;
        { The rectangle of the thumb of the scroll bar }
        function ThumbRect: TRectF;
        { The number of pixels the list is scrolled }
        property ScrollY: Float read FScrollY;
        { The item under the mouse, used while the list box is hot }
        property HotIndex: Integer read FHotIndex;
        { The number of items }
        property Count: Integer read GetCount;
        { The items in the list }
        property Items: StringArray read FItems write SetItems;
        { The index of the selected item, or -1 if none is selected }
        property ItemIndex: Integer read FItemIndex write SetItemIndex;
        property OnChange;
        property OnClick;
        property OnKeyDown;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
      end;

    See also

    Float in Codebot.System.pas
    TRectF in Codebot.Graphics.Types.pas
    TSceneKeyArgs in Codebot.Render.Scenes.pas
    TSceneMouseArgs in Codebot.Render.Scenes.pas
    TSceneWheelArgs in Codebot.Render.Scenes.pas