Table of Contents

Class ElementHelper

Namespace
MLEM.Ui.Elements
Assembly
MLEM.Ui.dll

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 Anchor

The button's anchor

size Vector2

The button's size

texture TextureRegion

The texture of the image to render on the button

text string

The text to display on the button

tooltipText string

The text of the button's tooltip

imagePadding float

The 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 Anchor

The button's anchor

size Vector2

The button's size

keybind Keybind

The keybind that this button should represent

inputHandler InputHandler

The input handler to query inputs with

activePlaceholder string

A placeholder text that is displayed while the keybind is being edited

unbindKey GenericInput
unboundPlaceholder string

A 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 int

The 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 Anchor

The button's anchor

size Vector2

The button's size

keybind Keybind

The keybind that this button should represent

inputHandler InputHandler

The input handler to query inputs with

activePlaceholder string

A placeholder text that is displayed while the keybind is being edited

unbind Keybind

An optional keybind to press that allows the keybind value to be unbound, clearing the combination

unboundPlaceholder string

A 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 int

The 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 Element

The element the groups should be added to, optional.

totalSize Vector2

The total width of all of the groups combined

amount int

The amount of groups to split the total size into

setHeightBasedOnChildren bool

Whether 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 Element

The element the groups should be added to, can be null.

totalSize Vector2

The total size that the grid should take up.

width int

The width of the grid, or the amount of columns it should have.

height int

The 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 Anchor

The text field's anchor

size Vector2

The size of the text field

defaultValue int

The default content of the text field

stepPerClick int

The value that is added or removed to the text field's value when clicking the + or - buttons

rule TextField.Rule

The rule for text input. OnlyNumbers by default.

onTextChange TextField.TextChanged

A 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 UiSystem

The ui system to add the panel to, optional.

anchor Anchor

The anchor of the panel

width float

The width of the panel

text string

The text to display on the panel

buttonHeight float

The height of the "close" button

okText string

The text on the "close" button

Returns

Panel

An info box panel