Package com.marcusslover.plus.lib.item
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.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classA helper class to calculate bounds.static class -
Method Summary
Modifier and TypeMethodDescriptioninthandle(@NotNull Canvas.BasicPopulator.ViewStrategy.ViewStrategyContext ctx) Allows you to modify the button depending on the given context.Deprecated.parseLayout(boolean groupLetters, String... rows) Parses an array of strings to create aCanvas.BasicPopulator.ViewStrategyfor rendering elements on a canvas.
-
Method Details
-
parseLayout
Parses an array of strings to create aCanvas.BasicPopulator.ViewStrategyfor 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 slotsrows- an array of strings representing the grid layout- Returns:
- a
Canvas.BasicPopulator.ViewStrategydefining the rendering behavior based on the parsed layout - Throws:
IllegalArgumentException- if any row does not have a length of exactly 9
- Use any letter (e.g.
-
parse
Deprecated.This method is deprecated and will be removed in future versions. UseparseLayout(boolean, String...)instead. Parses an array of strings to create aCanvas.BasicPopulator.ViewStrategyfor 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.ViewStrategythat defines the rendering behavior based on the parsed grid. - Throws:
IllegalArgumentException- If the length of any row is not equal to 9.
-
handle
Allows you to modify the button depending on the given context.- Parameters:
ctx- the context of the view strategy- Returns:
- elements per page
-