Interface Canvas.BasicPopulator.ViewStrategy

Enclosing class:
Canvas.BasicPopulator<T>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public static interface Canvas.BasicPopulator.ViewStrategy
Holds the strategy on how to populate the elements on the canvas. If a menu requires multiple pages, this is the strategy to use. The strategy allows the modification of the area in which the elements are populated.
  • Method Details

    • parseLayout

      static Canvas.BasicPopulator.ViewStrategy parseLayout(boolean groupLetters, String... rows)
      Parses an array of strings to create a Canvas.BasicPopulator.ViewStrategy for rendering elements on a canvas.

      The provided array of strings represents a grid layout, where each character indicates the presence or absence of an element at a specific position.

      • Use any letter (e.g. 'x') to indicate the presence of an element.
      • Use '-' to indicate the absence of an element.
      • Grouping is supported: multiple identical letters may represent a single element. This is useful for creating components larger than one slot (e.g., a button occupying 4 cells).

      Examples:

      Example 1: A simple layout with 10 individual slots (no grouping).

      
       String[] rows = {
           "---------",
           "--xxxxx--",
           "--xxxxx--",
           "---------",
           "---------",
           "---------"
       };
      
       ViewStrategy viewStrategy = ViewStrategy.parseLayout(false, rows);
       canvas.viewStrategy(viewStrategy);
       

      Example 2: A grouped layout with two buttons, each occupying four slots.

      
       String[] rows = {
           "---------",
           "--aa-bb--",
           "--aa-bb--",
           "---------",
           "---------",
           "---------"
       };
      
       ViewStrategy viewStrategy = ViewStrategy.parseLayout(true, rows);
       canvas.viewStrategy(viewStrategy);
       
      Parameters:
      groupLetters - whether identical letters should be treated as grouped elements or as individual slots
      rows - an array of strings representing the grid layout
      Returns:
      a Canvas.BasicPopulator.ViewStrategy defining the rendering behavior based on the parsed layout
      Throws:
      IllegalArgumentException - if any row does not have a length of exactly 9
    • parse

      Deprecated.
      This method is deprecated and will be removed in future versions. Use parseLayout(boolean, String...) instead. Parses an array of strings to create a Canvas.BasicPopulator.ViewStrategy for rendering elements on a canvas.

      The provided array of strings represents a grid, where each character in the strings indicates the presence or absence of an element at a specific grid position. Use 'x' to indicate the presence of an element and 'o' to indicate the absence of an element.

      Example:

               
               String[] rows = new String[] {
                    "ooooooooo",
                    "ooooxoooo",
                    "ooooxoooo",
                    "ooooxoooo",
                    "ooooxoooo",
                    "ooooxoooo"
               };
               
               ViewStrategy viewStrategy = ViewStrategy.parse(rows);
               canvas.viewStrategy(viewStrategy);
       
      Parameters:
      rows - An array of strings representing the grid.
      Returns:
      A Canvas.BasicPopulator.ViewStrategy that defines the rendering behavior based on the parsed grid.
      Throws:
      IllegalArgumentException - If the length of any row is not equal to 9.
    • handle

      int handle(@NotNull @NotNull Canvas.BasicPopulator.ViewStrategy.ViewStrategyContext ctx)
      Allows you to modify the button depending on the given context.
      Parameters:
      ctx - the context of the view strategy
      Returns:
      elements per page