Skip to content

Game.UI.Widgets.PagedList

Assembly: Assembly-CSharp (inferred)
Namespace: Game.UI.Widgets

Type: public class

Base: NamedWidgetWithTooltip, implements IExpandable, IPaged, IListWidget, IWidget, IJsonWritable, IContainerWidget, IDisableCallback

Summary:
PagedList is a UI widget that presents a paginated list of child widgets built by an IListAdapter. It maintains paging state (current page, page size, page count), supports expanding/collapsing (controlling visibleChildren), delegates element management to an adapter (add/insert/duplicate/move/delete/clear) and serializes its important properties to JSON. The widget updates its children from the adapter when the adapter reports changes in the active range, and it can propagate a disabled state to nested children that implement IDisableCallback.


Fields

  • private int m_Length
    Holds the current total number of elements reported by the adapter. Updated in Update() when adapter.length changes. Used to compute pageCount and visible child indices.

  • private int m_CurrentPageIndex
    The currently selected page index (internal storage). The public setter clamps this value and recalculates child range.

  • private int m_ChildStartIndex
    Zero-based index of the first element on the current page (inclusive). Used when asking the adapter to update and build only the required elements for the current page.

  • private int m_ChildEndIndex
    Index of the end of the current page (exclusive). Together with m_ChildStartIndex describes the half-open range [start, end) of elements that should be present in m_Children.

  • private List<IWidget> m_Children = new List<IWidget>()
    The list of child widgets currently built for the active page. Populated by adapter.BuildElementsInRange() when adapter reports an updated range.

  • private bool m_Expanded
    Backer for the public expanded property. When set, the widget marks properties and children as changed so the UI can update (calls SetPropertiesChanged and SetChildrenChanged).

Properties

  • public bool expanded { get; set; }
    Controls whether the list is expanded (visible). Getter returns m_Expanded. Setter updates m_Expanded and calls SetPropertiesChanged() and SetChildrenChanged() so UI refreshes. When false, visibleChildren is empty and the list behaves as collapsed.

  • public IListAdapter adapter { get; set; }
    Adapter responsible for managing underlying data and building IWidget instances for elements. adapter must provide length, resizable, sortable, UpdateRange(start,end), BuildElementsInRange(), and modification methods (AddElement, InsertElement, etc.). PagedList delegates most element operations to this adapter.

  • public int level { get; set; }
    A level value (likely used for hierarchical display or indentation). The class stores it but does not otherwise use it internally—consumer code or adapter may use it.

  • public int pageSize { get; set; } = 10
    Number of elements per page. Default is 10. Changing this affects pageCount and how child ranges are computed.

  • public int pageCount => (m_Length + pageSize - 1) / pageSize
    Computed read-only property returning the number of pages required to hold m_Length elements (ceiling division). If m_Length is 0, pageCount is 0.

  • public IList<IWidget> children => m_Children
    Exposes the current list of built child widgets (for the active page). Note this contains only widgets for the currently built range; it is not a representation of all elements across all pages.

  • public int currentPageIndex { get; set; }
    Getter returns m_CurrentPageIndex. Setter clamps the incoming value to [0, pageCount-1] and updates m_CurrentPageIndex. It also recalculates m_ChildStartIndex and m_ChildEndIndex for the new page and calls SetPropertiesChanged().

  • public override IList<IWidget> visibleChildren { get; }
    If expanded is false, returns an empty array (no visible children). If expanded is true, returns m_Children. This override controls what the UI framework considers visible child widgets.

Constructors

  • public PagedList()
    (No explicit constructor in source; the default parameterless constructor is used.) Initialize defaults: pageSize defaults to 10, m_Children initialized to an empty List. The adapter must be set by the consumer after construction.

Methods

  • public int AddElement()
    Calls adapter.AddElement() to add a new element to the underlying data source, then calls ShowElement(newIndex) to ensure the page containing the new element becomes current. Returns the index of the added element returned by the adapter (commonly the newly added element index, or -1 on failure depending on adapter implementation).

  • public void InsertElement(int index)
    Delegates to adapter.InsertElement(index) to insert a new element at the given index in the underlying data.

  • public int DuplicateElement(int index)
    Delegates to adapter.DuplicateElement(index) to duplicate an element. After duplication, calls ShowElement(duplicatedIndex) to make the duplicated element visible. Returns the index of the duplicated element.

  • public void MoveElement(int fromIndex, int toIndex)
    Delegates to adapter.MoveElement(fromIndex, toIndex) to reorder elements.

  • public void DeleteElement(int index)
    Delegates to adapter.DeleteElement(index) to remove an element from the underlying data.

  • public void Clear()
    Delegates to adapter.Clear() to clear all elements.

  • protected override WidgetChanges Update()
    Performs the widget's update cycle:

  • Calls base.Update() and accumulates WidgetChanges.
  • Reads adapter.length and, if changed from m_Length, updates m_Length and marks properties changed.
  • Calls CalculateIndices to determine which page and child range should be active based on current stored child indices and length; if the computed page/index range differs from stored m_CurrentPageIndex/m_ChildStartIndex/m_ChildEndIndex, updates them and marks properties changed.
  • Calls adapter.UpdateRange(m_ChildStartIndex, m_ChildEndIndex) — if adapter reports the range needs rebuilding, the widget:
    • Marks children changed if expanded.
    • Clears and rebuilds m_Children from adapter.BuildElementsInRange().
    • Asserts (UnityEngine.Assertions.Assert.AreEqual) that the number of built widgets equals (m_ChildEndIndex - m_ChildStartIndex).
    • If this widget is disabled (m_Disabled true), recursively applies DisableChildren to each newly created child.
  • Returns the accumulated WidgetChanges. Notes: relies on adapter to correctly implement UpdateRange and BuildElementsInRange; uses Unity assertions to catch mismatches in expected counts.

  • private void DisableChildren(IWidget child)
    Recursively applies a disabled callback to the provided child and its nested children (if it is a container). If the child implements IDisableCallback, sets its disabled callback to a lambda that returns true (effectively forcing it disabled). If the child is an IContainerWidget, iterates its children and calls DisableChildren on each. This is used to propagate this PagedList's disabled state to all nested widgets.

  • private void ShowElement(int elementIndex)
    If elementIndex != -1, calculates page and child range for that element (via CalculateIndices) and updates m_CurrentPageIndex, m_ChildStartIndex, and m_ChildEndIndex so the element's page will be shown on next update.

  • private void CalculateIndices(int elementIndex, int length, out int pageIndex, out int childStartIndex, out int childEndIndex)
    Computes the pageIndex that contains the given elementIndex, clamping to valid pages given length and pageSize. Then calls CalculateChildIndices for the computed pageIndex to compute the child range [childStartIndex, childEndIndex).

  • private void CalculateChildIndices(int pageIndex, int length, out int childStartIndex, out int childEndIndex)
    Calculates the inclusive start index and exclusive end index of elements for the specified pageIndex:

  • childStartIndex = pageIndex * pageSize
  • childEndIndex = Min((pageIndex + 1) * pageSize, length)

  • protected override void WriteProperties(IJsonWriter writer)
    Serializes PagedList properties to JSON using the provided writer. Writes:

  • "expanded" : expanded
  • "resizable" : adapter.resizable
  • "sortable" : adapter.sortable
  • "length" : m_Length
  • "currentPageIndex" : currentPageIndex
  • "pageCount" : pageCount
  • "childStartIndex" : m_ChildStartIndex
  • "childEndIndex" : m_ChildEndIndex This is used for saving state or for UI inspection tools.

Usage Example

// Example Setup in a widget OnCreate or initializer:
var pagedList = new PagedList();
pagedList.adapter = new MyListAdapter(); // implement IListAdapter to provide elements/widgets
pagedList.pageSize = 20;                 // show 20 items per page
pagedList.expanded = true;               // ensure children are visible
pagedList.currentPageIndex = 0;          // show the first page

// To add an element and ensure it's visible:
int newIndex = pagedList.AddElement();   // adapter adds element and PagedList will switch to its page

// In an update loop the framework calls pagedList.Update(), which will:
// - read adapter.length
// - compute page indices
// - call adapter.UpdateRange(start,end)
// - rebuild m_Children via adapter.BuildElementsInRange() when needed

Notes and implementation tips: - Provide a correct IListAdapter implementation: UpdateRange(start,end) should return true when the adapter's built widgets for that range need to be (re)created so PagedList will call BuildElementsInRange(). BuildElementsInRange() should return exactly (childEndIndex - childStartIndex) widgets. - If you set adapter.resizable or adapter.sortable, those values are serialized by WriteProperties and may be used by host UI. - The widget relies on UnityEngine.Mathf and Unity assertions for sanity checks; ensure assertions are acceptable in your mod environment or replace with appropriate error handling for release builds if necessary.