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
anchorAnchorThe button's anchor
sizeVector2The button's size
textureTextureRegionThe texture of the image to render on the button
textstringThe text to display on the button
tooltipTextstringThe text of the button's tooltip
imagePaddingfloatThe 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
anchorAnchorThe button's anchor
sizeVector2The button's size
keybindKeybindThe keybind that this button should represent
inputHandlerInputHandlerThe input handler to query inputs with
activePlaceholderstringA placeholder text that is displayed while the keybind is being edited
unbindKeyGenericInputunboundPlaceholderstringA placeholder text that is displayed if the keybind is unbound
inputNameFunc<GenericInput, string>An optional function to give each input a display name that is easier to read. If this is null, ToString() is used.
indexintThe index in the
keybindthat 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.isKeybindAllowedFunc<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
anchorAnchorThe button's anchor
sizeVector2The button's size
keybindKeybindThe keybind that this button should represent
inputHandlerInputHandlerThe input handler to query inputs with
activePlaceholderstringA placeholder text that is displayed while the keybind is being edited
unbindKeybindAn optional keybind to press that allows the keybind value to be unbound, clearing the combination
unboundPlaceholderstringA placeholder text that is displayed if the keybind is unbound
inputNameFunc<GenericInput, string>An optional function to give each input a display name that is easier to read. If this is null, ToString() is used.
indexintThe index in the
keybindthat 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.isKeybindAllowedFunc<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
parentElementThe element the groups should be added to, optional.
totalSizeVector2The total width of all of the groups combined
amountintThe amount of groups to split the total size into
setHeightBasedOnChildrenboolWhether 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
parentElementThe element the groups should be added to, can be null.
totalSizeVector2The total size that the grid should take up.
widthintThe width of the grid, or the amount of columns it should have.
heightintThe 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
anchorAnchorThe text field's anchor
sizeVector2The size of the text field
defaultValueintThe default content of the text field
stepPerClickintThe value that is added or removed to the text field's value when clicking the + or - buttons
ruleTextField.RuleThe rule for text input. OnlyNumbers by default.
onTextChangeTextField.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
systemUiSystemThe ui system to add the panel to, optional.
anchorAnchorThe anchor of the panel
widthfloatThe width of the panel
textstringThe text to display on the panel
buttonHeightfloatThe height of the "close" button
okTextstringThe text on the "close" button
Returns
- Panel
An info box panel