API ListviewItem - shmellyorc/Box GitHub Wiki

ListviewItem

Namespace: Box.Entities.Container

Description

Represents a base class for items displayed in a Listview. Manages selection state, displays a colored bar (ColorRect) when selected, and provides access back to its parent list view.

Constructor

public ListviewItem();

Sets KeepAlive to true so the item persists within the list view.

Properties

Property Description
Listview Listview Reference to the parent Listview control.
bool Selected Whether this item is currently selected; toggles the visibility of the selection bar.
Color Color Color of the selection bar; updating this changes the bar’s color when visible.

Methods

Method Signature Description Returns
protected override void OnEnter() Called when the item is added to the screen: creates a ColorRect child sized to Size, sets its Color and initial Visible state based on Selected, then invokes base.OnEnter(). void

Examples

// Create a custom list view item
public class PlayerItem : ListviewItem
{
    public string Name;
    public PlayerItem(string name)
    {
        Name = name;
        Size = new Vect2(200, 30);
    }

    protected override void OnEnter()
    {
        // Add a label entity as child, positioned beside the selection bar
        AddChild(new Label(Name) { Position = new Vect2(10, 5) });

        base.OnEnter();
    }
}

// Use with Listview
var list = new Listview(3,
    new PlayerItem("Alice"),
    new PlayerItem("Bob"),
    new PlayerItem("Carol")
);

mainScreen.AddEntity(list);