Table of Contents

Class ScrollBox<TElementContainer, TElement>

Namespace
RichHudFramework.UI
Assembly
RichHudClient.dll

A scrollable container for HUD elements, based on HudChain<TElementContainer, TElement>. It clips content that exceeds its bounds and provides a scrollbar for navigation.

public class ScrollBox<TElementContainer, TElement> : HudChain<TElementContainer, TElement>, IReadOnlyHudElement, IReadOnlyHudNode, IReadOnlyHudParent, IHudCollection<TElementContainer, TElement>, IReadOnlyHudCollection<TElementContainer, TElement>, IReadOnlyList<TElementContainer>, IReadOnlyCollection<TElementContainer>, IEnumerable<TElementContainer>, IEnumerable where TElementContainer : IScrollBoxEntry<TElement>, new() where TElement : HudElementBase

Type Parameters

TElementContainer
TElement
Inheritance
HudCollection<TElementContainer, TElement>
HudChain<TElementContainer, TElement>
ScrollBox<TElementContainer, TElement>
Implements
IHudCollection<TElementContainer, TElement>
IReadOnlyHudCollection<TElementContainer, TElement>
IReadOnlyList<TElementContainer>
IReadOnlyCollection<TElementContainer>
IEnumerable<TElementContainer>
Derived
Inherited Members

Examples

The following example demonstrates how to create a fixed-size ScrollBox attached to HighDpiRoot. It configures the container to stack elements vertically and populates it with a variety of standard UI controls, including buttons, sliders, text fields, and a nested list box.

var sidebar = new ScrollBox(HudMain.HighDpiRoot)
{
    // Create a vertical scrolling list
    AlignVertical = true,
    // Match member width to ScrollBox width
    SizingMode = HudChainSizingModes.FitMembersOffAxis,
    // Align to right side of the screen
    ParentAlignment = ParentAlignments.Right,
    // Set fixed size
    Size = new Vector2(300, 400),
    Padding = new Vector2(40),
    Spacing = 10,
    // Nearly anything can go in here
    CollectionContainer = 
    {
        new NamedOnOffButton(),
        new BorderedButton()
        {
            MouseInput = 
            { 
                LeftClickedCallback = (obj, args) => 
                { 
                    MyAPIGateway.Utilities.ShowMessage("ScrollBox Example", "Button clicked"); 
                }
            }
        },
        new ColorPickerRGB() { Name = "RGBA Color" },
        new Label()
        { 
            Text = "Text Field Label", 
            AutoResize = false,
            Height = 20f
        },
        new TextField() 
        {
            UpdateValueCallback = (obj, args) => 
            { 
                var field = obj as TextField;
                MyAPIGateway.Utilities.ShowMessage("ScrollBox Example", $"TextField Updated: {field.Value}"); 
            }
        },
        new NamedCheckBox(),
        new ColorPickerHSV() { Name = "HSV Color" },
        new ListBox<string>()
        {
            { "Key 1", "Value 1" },
            { "Key 2", "Value 2" },
            { "Key 3", "Value 3" },
            { "Key 4", "Value 4" },
            { "Key 5", "Value 5" },
            { "Key 6", "Value 6" },
            { "Key 7", "Value 7" },
            { "Key 8", "Value 8" },
        }
    }
};

Remarks

ScrollBox is a scrollable variation of HudChain<TElementContainer, TElement>. It maintains the ability to organize child elements into a linear stack—either vertically or horizontally—while constraining them within a fixed viewport. Content that exceeds the defined bounds is clipped by default, and a scrollbar is automatically provided to facilitate navigation through the collection.

Unlike a standard chain, this container requires that elements be wrapped in IScrollBoxEntry<TElement> objects. This interface introduces an Enabled state to the container, allowing specific entries to be dynamically hidden or shown within the scrolling list without creating layout gaps or removing them from the underlying collection. This makes the control particularly suitable for filtered lists or large collections of data.

Layout and Sizing

The control fully supports per-element proportional scaling using AlignAxisScale and automatic sizing behaviors via SizingMode. To determine the visible area of the list, developers should utilize MinLength or MinVisibleCount, or manually assign a fixed size to the element.

Usages

This class serves as the foundational layout and storage mechanism for higher-level selection controls, including ListBox<TContainer, TElement, TValue> and Dropdown<TContainer, TElement, TValue>.

Constructors

ScrollBox()

public ScrollBox()

ScrollBox(HudParentBase)

public ScrollBox(HudParentBase parent)

Parameters

parent HudParentBase

ScrollBox(bool, HudParentBase)

public ScrollBox(bool alignVertical, HudParentBase parent = null)

Parameters

alignVertical bool
parent HudParentBase

Properties

AlignVertical

If true, ScrollBox members are arranged vertically (top to bottom). If false, members are arranged horizontally (left to right).

Also reconfigures the ScrollBar and Divider orientation.

public override bool AlignVertical { set; }

Property Value

bool

Background

Textured, tintable background behind the scrollbox content.

public TexturedBox Background { get; protected set; }

Property Value

TexturedBox

BarColor

Color of the scrollbar track.

public Color BarColor { get; set; }

Property Value

Color

BarHighlight

Color of the scrollbar track when moused over.

public Color BarHighlight { get; set; }

Property Value

Color

ClipRange

Range of element indices representing the visible area, plus padding to allow for smooth clipping. Used for scissor rect masking.

public Vector2I ClipRange { get; }

Property Value

Vector2I

Color

Background color of the scroll box.

public Color Color { get; set; }

Property Value

Color

Divider

Visual divider line between the content area and the scrollbar.

public TexturedBox Divider { get; protected set; }

Property Value

TexturedBox

EnableScrolling

If true, scrolling via mouse wheel or scrollbar interaction is enabled.

public bool EnableScrolling { get; set; }

Property Value

bool

EnabledCount

Total number of enabled elements in the list.

public int EnabledCount { get; }

Property Value

int

End

The index of the last element within the visible range of the chain. Setting this updates the scrollbar position.

public int End { get; set; }

Property Value

int

MinLength

Minimum total length (on the align axis) of visible members allowed in the scrollbox.

If non-zero, the ScrollBox will expand to meet this length if the content supports it.

public float MinLength { get; set; }

Property Value

float

MinVisibleCount

Minimum number of visible elements allowed in the viewport.

If non-zero, the ScrollBox will expand to fit at least this many elements if possible.

public int MinVisibleCount { get; set; }

Property Value

int

ScrollBar

The slider UI element controlling the scroll position.

public ScrollBar ScrollBar { get; protected set; }

Property Value

ScrollBar

SliderColor

Color of the slider (thumb) when not moused over.

public Color SliderColor { get; set; }

Property Value

Color

SliderHighlight

Color of the slider (thumb) when moused over.

public Color SliderHighlight { get; set; }

Property Value

Color

Start

The index of the first element within the visible range of the chain. Setting this updates the scrollbar position.

public int Start { get; set; }

Property Value

int

UseSmoothScrolling

Enables pixel-perfect scrolling and range masking.

If false, scrolling snaps to element indices.

public bool UseSmoothScrolling { get; set; }

Property Value

bool

VisCount

Number of elements currently visible (or partially visible) in the viewport.

public int VisCount { get; }

Property Value

int

VisStart

The index relative to the visible elements, not the absolute collection index.

public int VisStart { get; }

Property Value

int

Methods

GetRangeEnd(int, int)

Returns the index of the last enabled element that fits within the count limit, starting from the given index.

public int GetRangeEnd(int count, int start = 0)

Parameters

count int
start int

Returns

int

GetRangeSize(int, int)

Returns the total size of the ScrollBox's contents, including the scrollbar area.

public override Vector2 GetRangeSize(int start = 0, int end = -1)

Parameters

start int
end int

Returns

Vector2