Class UIHelper
ENGINE - Static helper methods for UI Toolkit styling. Reduces boilerplate when creating UI elements programmatically.
public static class UIHelper
- Inheritance
-
objectUIHelper
Methods
AddHoverEffect(VisualElement, Color, Color)
Add hover color effect to an element.
public static void AddHoverEffect(VisualElement element, Color normalColor, Color hoverColor)
Parameters
elementVisualElementnormalColorColorhoverColorColor
CreateButton(string, Action, int, Color?)
Create a styled button.
public static Button CreateButton(string text, Action onClick, int fontSize = 14, Color? backgroundColor = null)
Parameters
textstringonClickActionfontSizeintbackgroundColorColor?
Returns
CreateColorIndicator(Color, float, float)
Create a color indicator box (for country colors, etc.).
public static VisualElement CreateColorIndicator(Color color, float size = 16, float borderRadius = 2)
Parameters
colorColorsizefloatborderRadiusfloat
Returns
CreateLabel(string, int, Color, FontStyle)
Create a styled label.
public static Label CreateLabel(string text, int fontSize, Color color, FontStyle fontStyle = FontStyle.Normal)
Parameters
Returns
CreatePanel(string, Color, float, float)
Create a styled panel container.
public static VisualElement CreatePanel(string name, Color backgroundColor, float padding = 10, float borderRadius = 6)
Parameters
namestringbackgroundColorColorpaddingfloatborderRadiusfloat
Returns
Hide(VisualElement)
Hide element.
public static void Hide(VisualElement element)
Parameters
elementVisualElement
RemoveBorders(VisualElement)
Remove all borders.
public static void RemoveBorders(VisualElement element)
Parameters
elementVisualElement
SetAbsolutePosition(VisualElement, float?, float?, float?, float?)
Position element absolutely at specified coordinates.
public static void SetAbsolutePosition(VisualElement element, float? top = null, float? right = null, float? bottom = null, float? left = null)
Parameters
elementVisualElementtopfloat?rightfloat?bottomfloat?leftfloat?
SetBorderColor(VisualElement, Color)
Set uniform border color on all sides.
public static void SetBorderColor(VisualElement element, Color color)
Parameters
elementVisualElementcolorColor
SetBorderRadius(VisualElement, float)
Set uniform border radius on all corners.
public static void SetBorderRadius(VisualElement element, float all)
Parameters
elementVisualElementallfloat
SetBorderRadius(VisualElement, float, float, float, float)
Set border radius with individual values.
public static void SetBorderRadius(VisualElement element, float topLeft, float topRight, float bottomRight, float bottomLeft)
Parameters
elementVisualElementtopLeftfloattopRightfloatbottomRightfloatbottomLeftfloat
SetBorderWidth(VisualElement, float)
Set uniform border width on all sides.
public static void SetBorderWidth(VisualElement element, float all)
Parameters
elementVisualElementallfloat
SetFlexColumn(VisualElement, Justify, Align)
Set flex direction to column with optional alignment.
public static void SetFlexColumn(VisualElement element, Justify justify = Justify.FlexStart, Align align = Align.Stretch)
Parameters
elementVisualElementjustifyJustifyalignAlign
SetFlexRow(VisualElement, Justify, Align)
Set flex direction to row with optional alignment.
public static void SetFlexRow(VisualElement element, Justify justify = Justify.FlexStart, Align align = Align.Stretch)
Parameters
elementVisualElementjustifyJustifyalignAlign
SetMargin(VisualElement, float)
Set uniform margin on all sides.
public static void SetMargin(VisualElement element, float all)
Parameters
elementVisualElementallfloat
SetMargin(VisualElement, float, float)
Set margin with vertical and horizontal values.
public static void SetMargin(VisualElement element, float vertical, float horizontal)
Parameters
elementVisualElementverticalfloathorizontalfloat
SetMargin(VisualElement, float, float, float, float)
Set margin with individual values.
public static void SetMargin(VisualElement element, float top, float right, float bottom, float left)
Parameters
elementVisualElementtopfloatrightfloatbottomfloatleftfloat
SetMaxHeight(VisualElement, float)
Set maximum height.
public static void SetMaxHeight(VisualElement element, float height)
Parameters
elementVisualElementheightfloat
SetMinWidth(VisualElement, float)
Set minimum width.
public static void SetMinWidth(VisualElement element, float width)
Parameters
elementVisualElementwidthfloat
SetPadding(VisualElement, float)
Set uniform padding on all sides.
public static void SetPadding(VisualElement element, float all)
Parameters
elementVisualElementallfloat
SetPadding(VisualElement, float, float)
Set padding with vertical and horizontal values.
public static void SetPadding(VisualElement element, float vertical, float horizontal)
Parameters
elementVisualElementverticalfloathorizontalfloat
SetPadding(VisualElement, float, float, float, float)
Set padding with individual values.
public static void SetPadding(VisualElement element, float top, float right, float bottom, float left)
Parameters
elementVisualElementtopfloatrightfloatbottomfloatleftfloat
SetSize(VisualElement, float, float)
Set fixed width and height.
public static void SetSize(VisualElement element, float width, float height)
Parameters
elementVisualElementwidthfloatheightfloat
SetTextAlign(VisualElement, TextAnchor)
Set text alignment.
public static void SetTextAlign(VisualElement element, TextAnchor anchor)
Parameters
elementVisualElementanchorTextAnchor
SetVisible(VisualElement, bool)
Set visibility based on condition.
public static void SetVisible(VisualElement element, bool visible)
Parameters
elementVisualElementvisiblebool
Show(VisualElement)
Show element.
public static void Show(VisualElement element)
Parameters
elementVisualElement
StyleLabel(Label, int, Color, FontStyle)
Style a label with common text properties.
public static void StyleLabel(Label label, int fontSize, Color color, FontStyle fontStyle = FontStyle.Normal)