Class ElementHelper
This class contains a set of helper methods that aid in creating special kinds of compound Element types for use inside of a UiSystem.
public static class ElementHelper
- Inheritance
-
ElementHelper
- Inherited Members
Methods
ImageButton(Anchor, Vector2, TextureRegion, string, string, float)
Creates a button with an image on the left side of its text.
public static Button ImageButton(Anchor anchor, Vector2 size, TextureRegion texture, string text = null, string tooltipText = null, float imagePadding = 2)
Parameters
anchor
AnchorThe button's anchor
size
Vector2The button's size
texture
TextureRegionThe texture of the image to render on the button
text
stringThe text to display on the button
tooltipText
stringThe text of the button's tooltip
imagePadding
floatThe Padding of the button's image
Returns
- Button
An image button
KeybindButton(Anchor, Vector2, Keybind, InputHandler, string, GenericInput, string, Func<GenericInput, string>, int, Func<GenericInput, IEnumerable<GenericInput>, bool>)
Creates a Button that acts as a way to input a custom value for a Keybind.
Note that only the Keybind.Combination at index index
of the given keybind is displayed and edited, all others are ignored.
Inputting custom keybinds using this element supports ModifierKey-based modifiers and any GenericInput-based keys.
The keybind button's current state can be retrieved using the "Active" GetData<T>(string) key, which stores a bool that indicates whether the button is currently waiting for a new value to be assigned.
public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, GenericInput unbindKey = default, string unboundPlaceholder = "", Func<GenericInput, string> inputName = null, int index = 0, Func<GenericInput, IEnumerable<GenericInput>, bool> isKeybindAllowed = null)
Parameters
anchor
AnchorThe button's anchor
size
Vector2The button's size
keybind
KeybindThe keybind that this button should represent
inputHandler
InputHandlerThe input handler to query inputs with
activePlaceholder
stringA placeholder text that is displayed while the keybind is being edited
unbindKey
GenericInputunboundPlaceholder
stringA placeholder text that is displayed if the keybind is unbound
inputName
Func<GenericInput, string>An optional function to give each input a display name that is easier to read. If this is null, ToString() is used.
index
intThe index in the
keybind
that the button should display. Note that, if the index is greater than the amount of combinations, combinations entered using this button will be stored at an earlier index.isKeybindAllowed
Func<GenericInput, IEnumerable<GenericInput>, bool>A function that can optionally determine whether a given input and modifier combination is allowed. If this is null, all combinations are allowed.
Returns
- Button
A keybind button with the given settings
KeybindButton(Anchor, Vector2, Keybind, InputHandler, string, Keybind, string, Func<GenericInput, string>, int, Func<GenericInput, IEnumerable<GenericInput>, bool>)
Creates a Button that acts as a way to input a custom value for a Keybind.
Note that only the Keybind.Combination at index index
of the given keybind is displayed and edited, all others are ignored.
Inputting custom keybinds using this element supports ModifierKey-based modifiers and any GenericInput-based keys.
The keybind button's current state can be retrieved using the "Active" GetData<T>(string) key, which stores a bool that indicates whether the button is currently waiting for a new value to be assigned.
public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, Keybind unbind = null, string unboundPlaceholder = "", Func<GenericInput, string> inputName = null, int index = 0, Func<GenericInput, IEnumerable<GenericInput>, bool> isKeybindAllowed = null)
Parameters
anchor
AnchorThe button's anchor
size
Vector2The button's size
keybind
KeybindThe keybind that this button should represent
inputHandler
InputHandlerThe input handler to query inputs with
activePlaceholder
stringA placeholder text that is displayed while the keybind is being edited
unbind
KeybindAn optional keybind to press that allows the keybind value to be unbound, clearing the combination
unboundPlaceholder
stringA placeholder text that is displayed if the keybind is unbound
inputName
Func<GenericInput, string>An optional function to give each input a display name that is easier to read. If this is null, ToString() is used.
index
intThe index in the
keybind
that the button should display. Note that, if the index is greater than the amount of combinations, combinations entered using this button will be stored at an earlier index.isKeybindAllowed
Func<GenericInput, IEnumerable<GenericInput>, bool>A function that can optionally determine whether a given input and modifier combination is allowed. If this is null, all combinations are allowed.
Returns
- Button
A keybind button with the given settings
MakeColumns(Element, Vector2, int, bool)
Creates an array of groups with a fixed width that can be used to create a column structure
public static Group[] MakeColumns(Element parent, Vector2 totalSize, int amount, bool setHeightBasedOnChildren = true)
Parameters
parent
ElementThe element the groups should be added to, optional.
totalSize
Vector2The total width of all of the groups combined
amount
intThe amount of groups to split the total size into
setHeightBasedOnChildren
boolWhether the groups should set their heights based on their children's heights
Returns
- Group[]
An array of columns
MakeGrid(Element, Vector2, int, int)
Creates an array of groups with a fixed width and height that can be used to create a grid with equally sized boxes.
public static Group[,] MakeGrid(Element parent, Vector2 totalSize, int width, int height)
Parameters
parent
ElementThe element the groups should be added to, can be null.
totalSize
Vector2The total size that the grid should take up.
width
intThe width of the grid, or the amount of columns it should have.
height
intThe height of the grid, or the amount of rows it should have.
Returns
- Group[,]
The created grid.
NumberField(Anchor, Vector2, int, int, Rule, TextChanged)
Creates a TextField with a + and a - button next to it, to allow for easy number input.
public static Group NumberField(Anchor anchor, Vector2 size, int defaultValue = 0, int stepPerClick = 1, TextField.Rule rule = null, TextField.TextChanged onTextChange = null)
Parameters
anchor
AnchorThe text field's anchor
size
Vector2The size of the text field
defaultValue
intThe default content of the text field
stepPerClick
intThe value that is added or removed to the text field's value when clicking the + or - buttons
rule
TextField.RuleThe rule for text input. OnlyNumbers by default.
onTextChange
TextField.TextChangedA callback that is invoked when the text field's text changes
Returns
- Group
A group that contains the number field
ShowInfoBox(UiSystem, Anchor, float, string, float, string)
Creates a panel that contains a paragraph of text and a button to close the panel. The panel is part of a group, which causes elements in the background (behind and around the panel) to not be clickable, leaving only the "close" button.
public static Panel ShowInfoBox(UiSystem system, Anchor anchor, float width, string text, float buttonHeight = 10, string okText = "Okay")
Parameters
system
UiSystemThe ui system to add the panel to, optional.
anchor
AnchorThe anchor of the panel
width
floatThe width of the panel
text
stringThe text to display on the panel
buttonHeight
floatThe height of the "close" button
okText
stringThe text on the "close" button
Returns
- Panel
An info box panel