Class Layout

java.lang.Object
me.agent.vgui.api.contents.Layout

public final class Layout extends Object
A character-mask layout for a view. Each string is one row; each character is one slot. Map characters to items with where(char, ViewItem), then apply the layout via ViewContents.applyLayout(Layout) or a ViewBuilder.

The characters '.' and ' ' always mean "leave the slot empty" and cannot be mapped. Unmapped characters are also left empty, which makes them useful as named regions for Pagination.slots(Layout, char).

Layout layout = Layout.of(
        "#########",
        "#ppppppp#",
        "#ppppppp#",
        "#<..c..>#")
    .where('#', ViewItem.of(filler))
    .where('<', ViewItem.pagePrevious(prevArrow))
    .where('>', ViewItem.pageNext(nextArrow))
    .where('c', ViewItem.closeButton(barrier));
  • Method Details

    • of

      public static Layout of(String... rows)
      Creates a layout from row strings. All rows must have the same length.
    • of

      public static Layout of(List<String> rows)
      Creates a layout from row strings. All rows must have the same length.
    • where

      public Layout where(char character, ViewItem item)
      Maps a character to an item. Passing null removes the mapping.
      Throws:
      IllegalArgumentException - for '.' or ' ' (always empty)
    • rows

      public int rows()
      Number of rows in this layout.
    • columns

      public int columns()
      Number of columns (length of each row string).
    • size

      public int size()
      Total number of slots covered by this layout.
    • charAt

      public char charAt(int slot)
      The character at a flat slot index.
    • slotsOf

      public int[] slotsOf(char character)
      All flat slot indexes whose layout character equals character, in reading order.
    • resolve

      public Map<Integer,ViewItem> resolve()
      Resolves the layout to a map of flat slot index to item, in reading order. Slots whose character is unmapped, '.' or ' ' are absent.