Skip to content

Game.UI.Editor.IItemPicker

Assembly: Game
Namespace: Game.UI.Editor

Type: interface

Base: (none)

Summary:
Defines a contract for "item picker" UI widgets used by the editor. The interface exposes the currently selected item index, the range of visible items, and a method to mark an item as a favorite. It also contains two nested helper types: - Item: a serializable data container that represents an individual entry in the picker (display name, tooltip, optional image/badge, directory/favorite flags). - Bindings: a binding factory that creates widget bindings to connect UI triggers to the IItemPicker implementation (e.g., setting visible range, selecting an item, toggling favorite).


Fields

  • public class Item
    Represents a single entry in the item picker. This nested class implements IJsonWritable and holds presentation data and flags for an item:
  • displayName: LocalizedString — primary label shown for the item.
  • tooltip: LocalizedString? — optional tooltip text.
  • image: string? — optional image identifier/path. Marked [CanBeNull].
  • badge: string? — optional badge identifier. Marked [CanBeNull].
  • directory: bool — true if the item represents a directory (non-leaf).
  • favorite: bool — true if the item is marked as a favorite.
  • Write(IJsonWriter writer): serializes the item via IJsonWriter (writes type name and the properties displayName, tooltip, image, directory, favorite, badge).

  • public class Bindings
    A nested binding factory implementing IWidgetBindingFactory. Its CreateBindings method yields bindings that map named triggers from the UI to actions on IItemPicker instances. The produced bindings allow the UI to:

  • setVisibleItemRange(startIndex, endIndex) — updates visibleStartIndex and visibleEndIndex on the picker.
  • setItemSelected(index) — sets selectedIndex on the picker and invokes the provided onValueChanged callback.
  • setItemFavorite(index, favorite) — calls SetFavorite(index, favorite) on the picker.

Properties

  • public int selectedIndex { get; set; }
    Index of the currently selected item in the picker. Bindings expose a "setItemSelected" trigger that sets this property and notifies the UI via the onValueChanged callback.

  • public int visibleStartIndex { get; set; }
    Start index (inclusive) of the currently visible range in the picker. The Bindings factory maps a "setVisibleItemRange" trigger to update this property.

  • public int visibleEndIndex { get; set; }
    End index (inclusive) of the currently visible range in the picker. Updated by the "setVisibleItemRange" binding.

Constructors

  • (interface) IItemPicker has no constructors.
  • public Item() (implicit) — the nested Item class has the default parameterless constructor.
  • public Bindings() (implicit) — the nested Bindings class has the default parameterless constructor.

Methods

  • void SetFavorite(int index, bool favorite)
    Request to mark/unmark the item at the given index as a favorite. Implementations should update their underlying model/state for the item at index and typically cause the UI to refresh that entry.

  • public void Write(IJsonWriter writer) (Item.Write)
    Serializes the Item instance to the provided IJsonWriter. The implementation writes the item's type name then the following properties: displayName, tooltip, image, directory, favorite, badge.

  • public IEnumerable<IBinding> CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged) (Bindings.CreateBindings)
    Creates binding objects that connect widget triggers (identified by group/name) to operations on an IItemPicker implementation. The bindings provided:

  • TriggerBinding "setVisibleItemRange" — sets visibleStartIndex / visibleEndIndex.
  • TriggerBinding "setItemSelected" — sets selectedIndex and invokes onValueChanged.
  • TriggerBinding "setItemFavorite" — calls SetFavorite(index, favorite).

Usage Example

// Minimal example implementing the IItemPicker interface.
public class SimpleItemPicker : IItemPicker
{
    private readonly List<IItemPicker.Item> m_items = new List<IItemPicker.Item>();

    public int selectedIndex { get; set; } = -1;
    public int visibleStartIndex { get; set; } = 0;
    public int visibleEndIndex { get; set; } = -1;

    public SimpleItemPicker(IEnumerable<string> names)
    {
        foreach (var name in names)
        {
            m_items.Add(new IItemPicker.Item
            {
                displayName = new LocalizedString(name),
                tooltip = null,
                image = null,
                badge = null,
                directory = false,
                favorite = false
            });
        }
    }

    public void SetFavorite(int index, bool favorite)
    {
        if (index < 0 || index >= m_items.Count) return;
        m_items[index].favorite = favorite;
        // Notify UI / refresh the item entry as needed by your framework.
    }
}

// Example of using the Bindings factory to attach bindings to a widget system:
// var bindings = new IItemPicker.Bindings();
// var createdBindings = bindings.CreateBindings("pickerGroup", widgetResolver, OnValueChanged);