Package tripleplay.ui

Class HistoryGroup<T,W extends Element<?>>

Type Parameters:
T - The type of item backing this history
W - The type of element or widget stored in this history
All Implemented Interfaces:
Iterable<Element<?>>
Direct Known Subclasses:
HistoryGroup.Labels

public abstract class HistoryGroup<T,W extends Element<?>> extends Composite<HistoryGroup<T,W>>
A scrolling vertical display, optimized for showing potentially very long lists such as a chat log. Supports:
  • addition of new elements on the end
  • pruning old elements from the beginning
  • progressive rendering of newly visible items in the list
  • automatically keeping the last item visible
  • purging of old rendered elements that are no longer visible
Items are stored in a backing array. Each entry in the array may or may not have a corresponding Element visible (presuming that the rendering and storage of elements is expensive). When the user scrolls, entries are rendered on demand using render(tripleplay.ui.HistoryGroup.Entry). Entries that are not visible use an estimated size for layout purposes. This of course may produce some artifacts during scrolling, which is the penalty of not computing the exact size.

NOTE: The elements in the UI (type W) must not be mutated after rendering and must have a constant size given a particular item and width. See render(tripleplay.ui.HistoryGroup.Entry).

  • Method Details

    • atBottom

      public boolean atBottom()
      Tests if the history is currently at the bottom. If the history is at the bottom, then subsequent additions will cause automatic scrolling. By default, new groups are at the bottom. Subsequent upward scrolling will clear this and scrolling to the bottom will set it again.
    • scrollToBottom

      public void scrollToBottom()
      Issues a request to scroll to the bottom of the list of history elements.
    • pruneOld

      public void pruneOld(int adjustment)
      Prunes the given number of entries from the beginning of the history.
    • addItem

      public void addItem(T item)
      Adds a new item to the end of the history. If the history is at the bottom, the item will be rendered immediately, otherwise the message group is invalidated so that the scroll bounds will be updated.
    • setVerticalGap

      public void setVerticalGap(int vgap)
      Sets the vertical gap between history elements. By default, the gap is set to 1.