tModLoader v2024.11
A mod to make and play Terraria mods
UIElement Class Reference

A UI element, the building blocks of a user interface. Commonly used elements include UIPanel, UIImage, UIList, UIScrollbar, UITextPanel<T>, and UIText. UIElements are nested within each other using Append(Terraria.UI.UIElement) to build a layout. More...

Inherits IComparable.

Inherited by ConfigElement< bool >, ConfigElement< object >, ConfigElement< string >, ConfigElement< T >, DefinitionOptionElement< T >, EmoteButton, EmotesGroupListItem, GroupOptionButton< T >, HeaderElement, PowerStripUIElement, UIAnimatedImage, UIBestiaryBar, UIBestiaryEntryButton, UIBestiaryEntryGrid, UIBestiaryEntryIcon, UIBestiaryInfoLine< T >, UIBestiaryNPCEntryPortrait, UICharacter, UICharacterNameButton, UIClothStyleButton, UIColoredImageButton, UIColoredSliderSimple, UICreativeInfiniteItemsDisplay, UICreativeItemsInfiniteFilteringOptions, UICreativePowerButton, UICycleImage, UIDifficultyButton, UIDynamicItemCollection, UIFocusInputTextField, UIGenProgressBar, UIGrid, UIHeader, UIHorizontalSeparator, UIIconTextButton, UIImage, UIImageButton, UIImageFramed, UIInputTextField, UIItemIcon, UIItemSlot, UIKeybindingListItem, UIKeybindingSimpleListItem, UIKeybindingSliderItem, UIKeybindingToggleListItem, UIList, UIList, UILoaderAnimatedImage, UIMemoryBar, UIModStateText, UIPanel, UIParticleLayer, UIProgressBar, UIScrollbar, UIScrollbar, UISearchBar, UISlicedImage, UISliderBase, UISortableElement, UIState, UIText, UIToggleImage, UIVerticalSeparator, and UIWorldCreationPreview.

Public Member Functions

void Activate ()
 
void Append (UIElement element)
 Adds the element as a child of this element. The UI system expects children elements to be positioned within the bounds of the parent element and will not work correctly if this restriction is not followed.
 
virtual int CompareTo (object obj)
 
virtual bool ContainsPoint (Vector2 point)
 
void CopyStyle (UIElement element)
 
void Deactivate ()
 
virtual void Draw (SpriteBatch spriteBatch)
 
void DrawDebugHitbox (BasicDebugDrawer drawer, float colorIntensity=0f)
 
delegate void ElementEvent (UIElement affectedElement)
 
virtual void ExecuteRecursively (UIElementAction action)
 
Rectangle GetClippingRectangle (SpriteBatch spriteBatch)
 
CalculatedStyle GetDimensions ()
 The dimensions of the area covered by this element. This is the area of this element interactible by the mouse. The width and height are derived from the Width and Height values of this element and will be limited by MinWidth/MaxWidth/MinHeight/MaxHeight as well as the GetInnerDimensions of the parent element. The position is derived from the Top, Left, HAlign, VAlign, and MarginLeft/Right/Top/Bottom values of this element as well as the GetInnerDimensions of the parent element.
 
UIElement GetElementAt (Vector2 point)
 
CalculatedStyle GetInnerDimensions ()
 The dimensions of the area within this element suitable for placing children elements. Takes into account PaddingLeft/Right/Top/Bottom.
 
CalculatedStyle GetOuterDimensions ()
 The dimensions of the area covered by this element plus the additional MarginLeft/Right/Top/Bottom.
 
bool GetSnapPoint (out SnapPoint point)
 
virtual List< SnapPointGetSnapPoints ()
 
virtual Rectangle GetViewCullingArea ()
 
bool HasChild (UIElement child)
 
void Initialize ()
 
virtual void LeftClick (UIMouseEvent evt)
 
virtual void LeftDoubleClick (UIMouseEvent evt)
 
virtual void LeftMouseDown (UIMouseEvent evt)
 Called when the UIElement under the mouse is left clicked. The default code calls the OnLeftMouseDown event and then calls LeftMouseDown on the Parent element. Since the method is called on all parent elements in the hierarchy, check if (evt.Target == this) for code only interested in direct clicks to this element. Children elements overlaying this element can be ignored by setting IgnoresMouseInteraction to true on them. More...
 
virtual void LeftMouseUp (UIMouseEvent evt)
 
virtual void MiddleClick (UIMouseEvent evt)
 
virtual void MiddleDoubleClick (UIMouseEvent evt)
 
virtual void MiddleMouseDown (UIMouseEvent evt)
 
virtual void MiddleMouseUp (UIMouseEvent evt)
 
delegate void MouseEvent (UIMouseEvent evt, UIElement listeningElement)
 
virtual void MouseOut (UIMouseEvent evt)
 Called once when this UIElement is no longer moused over. Default implementation sets IsMouseHovering to false, calls OnMouseOut event, then calls this same method on the Parent element. Useful for changing visuals to indicate the element is no longer interactable, as is the OnMouseOut event. MouseOver(UIMouseEvent) will be called when it is hovered once again. More...
 
virtual void MouseOver (UIMouseEvent evt)
 Called once when this UIElement becomes moused over (hovered). Default implementation sets IsMouseHovering to true, calls OnMouseOver event, then calls this same method on the Parent element. Useful for changing visuals to indicate the element is interactable, as is the OnMouseOver event. Any code that needs to run as long as the element is hovered should use check IsMouseHovering in Update(GameTime). MouseOut(UIMouseEvent) will be called when it no longer hovered. More...
 
virtual void OnActivate ()
 Called each time this element is activated, which is usually when a UIState is activated via UserInterface.SetState(UIState). Use this to run code to update elements whenever the UI is toggled on. More...
 
virtual void OnDeactivate ()
 
virtual void OnInitialize ()
 Called before the first time this element is activated (see OnActivate). Use this method to create and append other UIElement to this to build a UI. More...
 
virtual void Recalculate ()
 
virtual void RecalculateChildren ()
 
void Remove ()
 
void RemoveAllChildren ()
 
void RemoveChild (UIElement child)
 
virtual void RightClick (UIMouseEvent evt)
 
virtual void RightDoubleClick (UIMouseEvent evt)
 
virtual void RightMouseDown (UIMouseEvent evt)
 
virtual void RightMouseUp (UIMouseEvent evt)
 
virtual void ScrollWheel (UIScrollWheelEvent evt)
 
delegate void ScrollWheelEvent (UIScrollWheelEvent evt, UIElement listeningElement)
 
void SetPadding (float pixels)
 
void SetSnapPoint (string name, int id, Vector2? anchor=null, Vector2? offset=null)
 
delegate void UIElementAction (UIElement element)
 
virtual void Update (GameTime gameTime)
 
virtual void XButton1Click (UIMouseEvent evt)
 
virtual void XButton1DoubleClick (UIMouseEvent evt)
 
virtual void XButton1MouseDown (UIMouseEvent evt)
 
virtual void XButton1MouseUp (UIMouseEvent evt)
 
virtual void XButton2Click (UIMouseEvent evt)
 
virtual void XButton2DoubleClick (UIMouseEvent evt)
 
virtual void XButton2MouseDown (UIMouseEvent evt)
 
virtual void XButton2MouseUp (UIMouseEvent evt)
 

Public Attributes

float HAlign
 Aligns the element horizontally within the available space. A value of 1 will place the element at the right side. A value of 0.5 will place the element centered horizontally.
 
StyleDimension Height
 How tall this element intends to be. The calculated height will be clamped between MinHeight and MaxHeight according to the GetInnerDimensions of the parent element.
 
bool IgnoresMouseInteraction
 If true, this element will be ignored for mouse interactions. This can be used to allow UIElement placed over other UIElement to not be the target of mouse clicks. Defaults to false.
 
StyleDimension Left
 How far right from the left edge of the Parent element's GetInnerDimensions that this element will be positioned. See also VAlign for another positioning option.
 
float MarginBottom
 
float MarginLeft
 
float MarginRight
 
float MarginTop
 Additional spacing between this element and the GetInnerDimensions of its parent element.
 
StyleDimension MaxHeight = StyleDimension.Fill
 The maximum height of this element. Defaults to the full height.
 
StyleDimension MaxWidth = StyleDimension.Fill
 The maximum width of this element. Defaults to the full width.
 
StyleDimension MinHeight = StyleDimension.Empty
 The maximum width of this element. Defaults to no height.
 
StyleDimension MinWidth = StyleDimension.Empty
 The minimum width of this element. Defaults to no width.
 
bool OverflowHidden
 
SamplerState OverrideSamplerState
 
float PaddingBottom
 
float PaddingLeft
 
float PaddingRight
 
float PaddingTop
 Additional spacing between this element's GetDimensions and the position of its children placed within.
 
StyleDimension Top
 How far down from the top edge of the Parent element's GetInnerDimensions that this element will be positioned. See also HAlign for another positioning option.
 
bool UseImmediateMode
 
float VAlign
 Aligns the element vertically within the available space. A value of 1 will place the element at the bottom. A value of 0.5 will place the element centered vertically.
 
StyleDimension Width
 How wide this element intends to be. The calculated width will be clamped between MinWidth and MaxWidth according to the GetInnerDimensions of the parent element.
 

Protected Member Functions

virtual void DrawChildren (SpriteBatch spriteBatch)
 
virtual void DrawSelf (SpriteBatch spriteBatch)
 

Protected Attributes

readonly List< UIElementElements = new List<UIElement>()
 

Properties

IEnumerable< UIElementChildren [get]
 
bool IsMouseHovering [get]
 True when the mouse is hovering over this UIElement. Useful for setting hover tooltips in DrawSelf or drawing hover visual indicators. Note that this is true for all elements in the hierarchy that are hovered, not just the topmost element. For example, hovering over a button that is appended to a panel will mean that IsMouseHovering is true for the button and the panel. Use this or ContainsPoint(Main.MouseScreen) for behaviors that use this logic, such as setting Player.mouseInterface to true.
 
UIElement Parent [get]
 The element this element is appended to.
 
int UniqueId [get]
 

Events

MouseEvent OnLeftClick
 
MouseEvent OnLeftDoubleClick
 
MouseEvent OnLeftMouseDown
 
MouseEvent OnLeftMouseUp
 
MouseEvent OnMiddleClick
 
MouseEvent OnMiddleDoubleClick
 
MouseEvent OnMiddleMouseDown
 
MouseEvent OnMiddleMouseUp
 
MouseEvent OnMouseOut
 Called by MouseOut(UIMouseEvent). Use this event instead of inheritance if suitable.
 
MouseEvent OnMouseOver
 Called by MouseOver(UIMouseEvent). Use this event instead of inheritance if suitable.
 
MouseEvent OnRightClick
 
MouseEvent OnRightDoubleClick
 
MouseEvent OnRightMouseDown
 
MouseEvent OnRightMouseUp
 
ScrollWheelEvent OnScrollWheel
 
ElementEvent OnUpdate
 
MouseEvent OnXButton1Click
 
MouseEvent OnXButton1DoubleClick
 
MouseEvent OnXButton1MouseDown
 
MouseEvent OnXButton1MouseUp
 
MouseEvent OnXButton2Click
 
MouseEvent OnXButton2DoubleClick
 
MouseEvent OnXButton2MouseDown
 
MouseEvent OnXButton2MouseUp
 

Detailed Description

A UI element, the building blocks of a user interface. Commonly used elements include UIPanel, UIImage, UIList, UIScrollbar, UITextPanel<T>, and UIText.

UIElements are nested within each other using Append(Terraria.UI.UIElement) to build a layout.

Member Function Documentation

◆ LeftMouseDown()

virtual void UIElement.LeftMouseDown ( UIMouseEvent  evt)
virtual

Called when the UIElement under the mouse is left clicked. The default code calls the OnLeftMouseDown event and then calls LeftMouseDown on the Parent element. Since the method is called on all parent elements in the hierarchy, check if (evt.Target == this) for code only interested in direct clicks to this element. Children elements overlaying this element can be ignored by setting IgnoresMouseInteraction to true on them.

Parameters
evt

Reimplemented in GroupOptionButton< T >, UICharacterNameButton, UIClothStyleButton, UIDifficultyButton, UIHairStyleButton, UIIconTextButton, UIScrollbar, FixedUIScrollbar, UISearchBar, and FixedUIScrollbar.

◆ MouseOut()

virtual void UIElement.MouseOut ( UIMouseEvent  evt)
virtual

Called once when this UIElement is no longer moused over. Default implementation sets IsMouseHovering to false, calls OnMouseOut event, then calls this same method on the Parent element. Useful for changing visuals to indicate the element is no longer interactable, as is the OnMouseOut event. MouseOver(UIMouseEvent) will be called when it is hovered once again.

Reimplemented in EmoteButton, GroupOptionButton< T >, UIAchievementListItem, UICharacterListItem, UICharacterNameButton, UIClothStyleButton, UIColoredImageButton, UIDifficultyButton, UIHairStyleButton, UIIconTextButton, UIImageButton, UIResourcePack, UIWorkshopImportWorldListItem, UIWorkshopPublishResourcePackListItem, UIWorkshopPublishWorldListItem, and UIWorldListItem.

◆ MouseOver()

virtual void UIElement.MouseOver ( UIMouseEvent  evt)
virtual

Called once when this UIElement becomes moused over (hovered). Default implementation sets IsMouseHovering to true, calls OnMouseOver event, then calls this same method on the Parent element. Useful for changing visuals to indicate the element is interactable, as is the OnMouseOver event. Any code that needs to run as long as the element is hovered should use check IsMouseHovering in Update(GameTime). MouseOut(UIMouseEvent) will be called when it no longer hovered.

Reimplemented in EmoteButton, GroupOptionButton< T >, UIAchievementListItem, UICharacterListItem, UICharacterNameButton, UIClothStyleButton, UIColoredImageButton, UIDifficultyButton, UIHairStyleButton, UIIconTextButton, UIImageButton, UIResourcePack, UISearchBar, UIWorkshopImportWorldListItem, UIWorkshopPublishResourcePackListItem, UIWorkshopPublishWorldListItem, UIWorldListItem, ConfigElement< T >, ConfigElement< bool >, ConfigElement< object >, ConfigElement< string >, and UIButton< T >.

◆ OnActivate()

virtual void UIElement.OnActivate ( )
virtual

Called each time this element is activated, which is usually when a UIState is activated via UserInterface.SetState(UIState). Use this to run code to update elements whenever the UI is toggled on.

Reimplemented in UIAchievementsMenu, UICharacterSelect, UICreativePowersMenu, UIEmotesMenu, UIManageControls, UIVirtualKeyboard, UIWorkshopSelectResourcePackToPublish, UIWorkshopSelectWorldToPublish, UIWorkshopWorldImport, UIWorldLoad, UIWorldSelect, UIButton< T >, and UICreateMod.

◆ OnInitialize()

virtual void UIElement.OnInitialize ( )
virtual