GuiBase2d

Show Deprecated
Not Creatable
Not Browsable

GuiBase2d is an abstract class inherited by 2D GUI Objects.

Summary

Properties

Describes the actual screen position of a UI element, in pixels.

READ ONLY
NOT REPLICATED

Describes the actual screen rotation of a UI element, in degrees.

READ ONLY
NOT REPLICATED

Describes the actual screen size of a UI element, in pixels.

READ ONLY
NOT REPLICATED

When set to true, localization will be applied to this GuiBase2d and its descendants based on the GuiBase2d.RootLocalizationTable specified for this GuiBase2d.

A reference to a LocalizationTable to be used to apply automated localization to this GuiBase2d and its descendants.

Customizes gamepad selection behavior in the down direction.

NOT BROWSABLE

Customizes gamepad selection behavior in the left direction.

NOT BROWSABLE

Customizes gamepad selection behavior in the right direction.

NOT BROWSABLE

Customizes gamepad selection behavior in the up direction.

NOT BROWSABLE

Allows customization of gamepad selection movement.

NOT BROWSABLE

Events

SelectionChanged(amISelected: boolean, previousSelection: GuiObject, newSelection: GuiObject): RBXScriptSignal  

Fires when the gamepad selection moves to, leaves, or changes within the connected GuiBase2d or any descendent GuiObjects.

Methods

Properties

AbsolutePosition

Read Only
Not Replicated

AbsolutePosition is a read-only property that provides the screen position of a UI element in pixels. This represents the actual pixel position at which an element renders as a result of its ancestors' sizes and positions. The GuiObject.AnchorPoint also influences the AbsolutePosition. This property, GuiBase2d.AbsoluteSize and GuiBase2d.AbsoluteRotation are a group of properties that all describe the final rendered orientation of a UI element.

For example, on a 1920 by 1080 screen, a Frame with position {0.5, 0}, {0.5, 0} would have an AbsolutePosition of (960, 540). If you were to place another Frame with position {0, 50}, {0, 50} inside that one, its AbsolutePosition would be (1010, 590). This example assumes each Frame has the defualt GuiObject.AnchorPoint of (0, 0), the top left corner.

AbsoluteRotation

Read Only
Not Replicated

AbsoluteRotation is a read-only property that describes the actual screen rotation of a UI element, in degrees. This property, GuiBase2d.AbsoluteSize and GuiBase2d.AbsolutePosition are a group of properties that all describe the final rendered orientation of a UI element. It composes (sums) each of the UI element's ancestors' GuiObject.Rotation into one value. It does not perform bounds checking, so its value may not be in the range 0 ≤ x < 360 degrees.

For example, if FrameA has a rotation of 40 degrees, and FrameB within it has a GuiObject.Rotation of 50 degrees, then FrameB's AbsoluteRotation would be 90 degrees.

AbsoluteSize

Read Only
Not Replicated

AbsoluteSize is a read-only property that provides the screen size of a UI element in pixels. This represents the actual pixel size at which an element renders as a result of its ancestors' sizes. This property, GuiBase2d.AbsolutePosition and GuiBase2d.AbsoluteRotation are a group of properties that all describe the final rendered orientation of a UI element.

For example, on a 1920 by 1080 screen, if FrameA exists within FrameB, and they both have a Size of {.5, 0}, {.5, 0}, then the AbsoluteSize of FrameA (the inner frame) would be (480, 270) as the GuiObject.Size property determines the size of a child UI element relative to its parent. Both of the frames are set to 50% of the parent size. Since 50% of 50% is 25%, and 25% of our screen size, 1920 by 1080, is (480, 270), this would be the resultant AbsoluteSize of the inner frame.

AutoLocalize

When set to true, localization will be applied to this GuiBase2d and its descendants based on the GuiBase2d.RootLocalizationTable specified for this GuiBase2d.

RootLocalizationTable

A reference to a LocalizationTable to be used to apply automated localization to this GuiBase2d and its descendants.

The GuiBase2d.AutoLocalize property must be set to true on this object and its ancestors for automated localization to be applied. You can set this to reference a LocalizationTable anywhere in the DataModel. It is not required to be a child of LocalizationService. When RootLocalizationTable is set on a GUI object then that object and all of its children will use that specific LocalizationTable and its parents for automatic text replacement, instead of using the tables under LocalizationService in an undefined order.

If there is no translation available in the referenced table it will look for a translation in the parent of that table, if it is also a LocalizationTable, and so on.

SelectionBehaviorDown

Not Browsable

Customizes gamepad selection behavior in the down direction.

SelectionBehaviorLeft

Not Browsable

Customizes gamepad selection behavior in the left direction.

SelectionBehaviorRight

Not Browsable

Customizes gamepad selection behavior in the right direction.

SelectionBehaviorUp

Not Browsable

Customizes gamepad selection behavior in the up direction.

SelectionGroup

Not Browsable

Toggling SelectionGroup on for a GUI allows customization of how gamepad selection can move between buttons, which are descendants of the SelectionGroup, leaves the group, and selects other buttons. Setting SelectionGroup to true exposes the SelectionBehaviorUp/Down/Left/ Right properties, which can be set to SelectionBehavior.Escape or SelectionBehavior.Stop. Escape is the default behavior. When set to Escape, the gamepad selection tries to first find a selection within the SelectionGroup and only moves outside if it does not find a suitable button. When set to Stop, gamepad selection only looks within the SelectionGroup and does not move outside of the group from the SelectionBehavior direction.

Events

SelectionChanged

This event fires when the selection changes within any descendants of the connected GuiBase2d. When the selection highlight moves to a GuiObject, the event bubbles from that GuiObject to all of its ancestors, informing them that the selection has changed/entered/exited to a GuiObject in their descendant tree.

Parameters

amISelected: boolean

True if the new selection matches the attached GuiBase2d.

previousSelection: GuiObject
newSelection: GuiObject

Code Samples

SelectionChanged Background Color

1backgroundWindow.SelectionChanged:Connect(function(amI, old, new)
2 if new:IsDescendantOf(backgroundWindow) then
3 backgroundWindow.BackgroundColor3 = Color3.new(0, 1, 0) -- green when focused
4 else
5 backgroundWindow.BackgroundColor3 = Color3.new(1, 0, 0) -- red when not focused
6 end
7end)

Methods