Skip to content

Game.UI.Widgets.Scrollable

Assembly: Game
Namespace: Game.UI.Widgets

Type: class

Base: LayoutContainer

Summary:
Scrollable is a UI layout container that exposes a configurable scrolling direction and is intended to be used wherever a scrollable layout is required. The control makes itself expand to fill available layout space by setting base.flex to FlexLayout.Fill in the constructor. The direction property is serialized (written) as an integer by the overridden WriteProperties method so it can be persisted or sent to the UI JSON pipeline.


Fields

  • This class declares no explicit (non-inherited) fields.
    {{ The Scrollable class only uses inherited fields (for example, children from LayoutContainer). All state added by this class is exposed via the public property 'direction'. }}

Properties

  • public Direction direction { get; set; }
    {{ Represents the scroll direction for this container (type Direction is an enum defined elsewhere). The value is written to the UI JSON output in WriteProperties as an integer. There is no explicit default set in the constructor, so it will have the enum default unless assigned. }}

Constructors

  • public Scrollable()
    {{ Creates a new Scrollable instance and configures its layout to fill available space by setting base.flex = FlexLayout.Fill. No other initialization is performed here. }}

Methods

  • public static Scrollable WithChildren(IList<IWidget> children)
    {{ Factory helper that returns a new Scrollable with the provided children list assigned to its inherited children collection. Useful for inline construction when you have child widgets ready. Example usage: Scrollable.WithChildren(myChildren). }}

  • protected override void WriteProperties(IJsonWriter writer)
    {{ Overrides the base implementation to add serialization of the "direction" property. It calls base.WriteProperties(writer) and then writes a property named "direction" with the integer value of the direction enum. This ensures the scrolling direction is included in any JSON representation produced by the UI writer. }}

Usage Example

// create a scrollable container with children and set its direction
var children = new List<IWidget> { headerWidget, contentWidget, footerWidget };
var scroll = Scrollable.WithChildren(children);
scroll.direction = Direction.Vertical;

// or construct and set manually
var scroll2 = new Scrollable();
scroll2.children = children;
scroll2.direction = Direction.Horizontal;

{{ NOTES: - The Scrollable class relies on the LayoutContainer base for child management and most layout behavior. - Direction is serialized as an integer; if you change the Direction enum values, ensure compatibility with any persisted JSON or UI definitions. - Because the constructor sets base.flex = FlexLayout.Fill, a Scrollable will try to occupy available space in its parent layout unless overridden. }}