Skip to content
GNamimates edited this page Oct 30, 2024 · 4 revisions

Class Name: GNUI.Box

A box is a Rectangle that represents the building block of GNUI

Note

It is recommened to use GNUI.newBox() instead of requiring the class script, save yourself some space.

Properties

Type Field Description
number AccumulatedScaleFactor Scales the displayed sprites and its children based on the factor.
Vector4 Anchor Determins where to attach to its parent, (0-1, left-right, up-down)
string[] BakedText The baked text to be displayed.
table cache Contains data to optimize the process.
boolean canCaptureCursor True when the box can capture the cursor. from its parent
GNUI.Canvas Canvas The canvas that the box is attached to.
integer ChildIndex the element's place order on its parent.
table<any,GNUI.any> Children A list of the element's children.
boolean ClipOnParent when true, the box will go invisible once touching outside the parent container.
Vector3 Color The tint applied to the sprite.
Vector4 ContainmentRect The final output dimensions with anchors applied. incredibly handy piece of data.
boolean CursorHovering True when the cursor is hovering over the container, compared with the parent container.
Vector2 CustomMinimumSize Minimum size that the box will use.
string DefaultTextColor The color to be used when the text color is not specified.
Vector4 Dimensions Determins the offset of each side from the final output
number FontScale The scale of the text.
Vector2 GrowDirection The direction in which the box grows into when is too small for the parent container.
integer id A unique integer for this element. (next-free based).
boolean isClipping true when the box is touching outside the parent's container.
boolean isCursorHovering true when the cursor is hovering over the container.
boolean isFreed true when the element is being freed.
ModelPart ModelPart The ModelPart used to handle where to display debug features and the sprite.
string name An optional property used to get the element by a name.
Nineslice Nineslice the sprite that will be used for displaying textures.
Vector2 offsetChildren Shifts the children.
GNUI.any Parent the element's parents.
table PARENT_CHANGED when the parent changes.
number ScaleFactor Scales the displayed sprites and its children based on the factor.
Vector2 Size The size of the container.
Vector2 SystemMinimumSize The minimum size that the box can use, set by the box itself.
table Text The text to be displayed.
Vector2 TextAlign The alignment of the text within the box.
GNUI.TextBehavior TextBehavior Tells the text what to do when out of bounds.
GNUI.TextEffect TextEffect The effect to be applied to the text.
integer[] TextLengths The length of each separated text
boolean TextLimitsHeight If true, the text will clamp to the height of the box
Vector2 TextOffset Specifies how much to offset the text from its final position.
ModelPart TextPart The ModelPart used to display text.
TextTask[] TextTasks A list of tasks to be executed when the text is changed.
boolean Visible true to see.
number Z Offsets the box forward(+) or backward(-) if Z fighting is occuring, also affects its children.
number ZSquish Multiplies how much the modelpart is positioned in the Z axis

Events

Event Description
ANCHOR_CHANGED Triggered when the anchors applied to the box is changed.
CANVAS_CHANGED Triggered when the canvas that the box is attached to has changed. first argument is the new, second is the old one.
CHILDREN_ADDED when a child is added. first parameter is the child added.
CHILDREN_CHANGED when the children list is changed.
CHILDREN_REMOVED when a child is removed. first parameter is the child removed.
DIMENSIONS_CHANGED Triggered when the final box dimensions has changed.
INPUT Serves as the handler for all inputs within the boundaries of the container.
MOUSE_ENTERED Triggered once the cursor is hovering over the container
MOUSE_EXITED Triggered once the cursor leaves the confinement of this container.
MOUSE_MOVED Triggered when the mouse position changes within this container. GNUI.InputEventMouseMotion being the first agument, containing data about the event.
MOUSE_PRESSENCE_CHANGED Triggered when the state of the mouse to box interaction changes, arguments include: (hovering: boolean, pressed: boolean)
ON_FREE when the element is wiped from history.
SIZE_CHANGED Triggered when the size of the final box dimensions is different from the last tick.
SPRITE_CHANGED Triggered when the sprite object set to this box has changed.
TEXT_CHANGED Triggered when the text is changed.
VISIBILITY_CHANGED on change of visibility.

Methods

Returns Methods
self Box.new(parent : GNUI.Box?)
self Box:setVisible(visible : boolean)
self Box:setColor(r : number|Vector3|string, g : number?, b : number?)
Box:_updateVisibility()
self Box:setName(name : string)
string Box:getName()
GNUI.any Box:getChild(name : string)
Box:getChildByIndex()
self Box:updateChildrenOrder(self : self)
self Box:addChild(child : GNUI.any, index : integer?)
self Box:removeChild(child : GNUI.Box)
table<integer, Box:getChildren()
self Box:updateChildrenIndex(self : self)
Box:setChildIndex(i : any)
Box:free()
Box:purgeAllChildren()
Box:purgeChildrenRange(ifrom : any, ito : any)
self Box:setCanvas(canvas : GNUI.Canvas)
self Box:setNineslice(self : self, nineslice : Nineslice?)
self Box:setClipOnParent(self : self, clip : any)
self Box:setDimensions(self : self, x : number|Vector4, y : number?, w : number?, t : number?)
self Box:setPos(self : self, x : number|Vector2, y : number?)
self Box:setEnd(self : self, x : number|Vector2, y : number?)
self Box:setSize(x : number|Vector2, y : number?)
Vector2 Box:getSize()
boolean Box:isPosInside(x : number|Vector2, y : number?)
self Box:setZMul(mul : number)
self Box:setCanCaptureCursor(capture : boolean)
self Box:setScaleFactor(factor : number?)
self Box:setAnchorTop(units : number?)
self Box:setAnchorLeft(units : number?)
self Box:setAnchorDown(units : number?)
self Box:setAnchorRight(units : number?)
self Box:setAnchor(left : number|Vector4|Vector2, top : number|Vector2?, right : number?, bottom : number?)
self Box:setIsCursorHovering(toggle : boolean)
self Box:setCustomMinimumSize(x : number|Vector2, y : number?)
self Box:setSystemMinimumSize(x : number|Vector2, y : number?)
self Box:setGrowDirection(x : number|Vector2, y : number?)
self Box:setChildrenOffset(x : number|Vector2, y : number?)
Box:getMinimumSize()
Vector2 Box:XYtoUV(x : number|Vector2, y : number?)
Vector2 Box:UVtoXY(x : number|Vector2, y : number?)
Vector2 Box:toGlobal(x : number|Vector2, y : number?)
Vector2 Box:toLocal(x : number|Vector2, y : number?)
self Box:update(self : self)
self Box:updateTheming(self : self)
Box:_update()
Box:updateSpriteTasks()
self Box:forceUpdate(self : self)
Box:_propagateUpdateToChildren()
self Box:rebuildTextTasks(self : self)
Box:repositionText()
self Box:setText(self : self, text : any)
self Box:setFontScale(scale : number)
self Box:setDefaultTextColor(color : Vector3|string)
Box:setTextAlign(h : number?, v : number?)
self Box:setTextBehavior(behavior : GNUI.TextBehavior)
self Box:setTextEffect(self : self, effect : GNUI.TextEffect)
self Box:setTextOffset(x : number|Vector2, y : number?)

Box.new(parent)

Creates a new container.

Arguments

  • GNUI.Box? parent

Returns self

Box:setVisible(visible)

Sets the visibility of the element and its children

Arguments

  • boolean visible

Returns self

Box:setColor(r, g, b)

Sets the color of the element.

Arguments

  • number|Vector3|string r

  • number? g

  • number? b

Returns self

Box:_updateVisibility()

Box:setName(name)

Sets the name of the element. this is used to make it easier to find elements with getChild

Arguments

  • string name

Returns self

Box:getName()

Returns string

Box:getChild(name)

Gets a child by username

Arguments

  • string name

Returns GNUI.any

Box:getChildByIndex()

Box:updateChildrenOrder(self)

Argument

Returns self

Box:addChild(child, index)

Adopts an element as its child.

Arguments

  • GNUI.any child

  • integer? index

Returns self

Box:removeChild(child)

Abandons the child into the street.

Arguments

  • GNUI.Box child

Returns self

Box:getChildren()

Returns table<integer,

Box:updateChildrenIndex(self)

Argument

Returns self

Box:setChildIndex(i)

Sets the Child Index of the element.

Arguments

  • any i

Box:free()

Frees all the data of the element. all thats left to do is to forget it ever existed.

Box:purgeAllChildren()

Kills all the children, go startwars mode.

Box:purgeChildrenRange(ifrom, ito)

Kills all the children in the given number range.

Arguments

  • any ifrom

  • any ito

Box:setCanvas(canvas)

Sets the canvas of this box and its hierarchy.

Arguments

  • GNUI.Canvas canvas

Returns self

Box:setNineslice(self, nineslice)

Sets the backdrop of the container.
Note: if the sprite given is already in use, it will overtake it.

Argument

  • Nineslice? nineslice

Returns self

Box:setClipOnParent(self, clip)

Sets the flag if this box should go invisible once touching outside of its parent.

Argument

  • any clip

Returns self

Box:setDimensions(self, x, y, w, t)

Sets the dimensions of this container.
x,y is top left
z,w is bottom right
if Z or W is missing, they will use X and Y instead

Argument

  • number|Vector4 x

  • number? y

  • number? w

  • number? t

Returns self

Box:setPos(self, x, y)

Sets the position of this container.
check out Box:setEnd() for setting the position from the other end.

Argument

  • number|Vector2 x

  • number? y

Returns self

Box:setEnd(self, x, y)

Sets the position of this container.
check out Box:setPos() for setting the position from the other end.

Argument

  • number|Vector2 x

  • number? y

Returns self

Box:setSize(x, y)

Sets the Size of this container.

Arguments

  • number|Vector2 x

  • number? y

Returns self

Box:getSize()

Gets the Size of this container.

Returns Vector2

Box:isPosInside(x, y)

Checks if the given position is inside the container, in local BBunits of this box with dimension offset considered.

Arguments

  • number|Vector2 x

  • number? y

Returns boolean

Box:setZMul(mul)

Multiplies the offset from its parent container, useful for making the future elements go behind the parent by setting this value to lower than 0.

Arguments

  • number mul

Returns self

Box:setCanCaptureCursor(capture)

If this box should be able to capture the cursor from its parent if obstructed.

Arguments

  • boolean capture

Returns self

Box:setScaleFactor(factor)

Sets the UI scale of its children, while still mentaining their original anchors and positions.

Arguments

  • number? factor

Returns self

Box:setAnchorTop(units)

Sets the top anchor.
0 = top part of the box is fully anchored to the top of its parent
1 = top part of the box is fully anchored to the bottom of its parent

Arguments

  • number? units

Returns self

Box:setAnchorLeft(units)

Sets the left anchor.
0 = left part of the box is fully anchored to the left of its parent
1 = left part of the box is fully anchored to the right of its parent

Arguments

  • number? units

Returns self

Box:setAnchorDown(units)

Sets the down anchor.
0 = bottom part of the box is fully anchored to the top of its parent
1 = bottom part of the box is fully anchored to the bottom of its parent

Arguments

  • number? units

Returns self

Box:setAnchorRight(units)

Sets the right anchor.
0 = right part of the box is fully anchored to the left of its parent
1 = right part of the box is fully anchored to the right of its parent

Arguments

  • number? units

Returns self

Box:setAnchor(left, top, right, bottom)

Sets the anchor for all sides.
x 0 <-> 1 = left <-> right
y 0 <-> 1 = top <-> bottom
if right and bottom are not given, they will use left and top instead.

Arguments

  • number|Vector4|Vector2 left

  • number|Vector2? top

  • number? right

  • number? bottom

Returns self

Box:setIsCursorHovering(toggle)

Arguments

  • boolean toggle

Returns self

Box:setCustomMinimumSize(x, y)

Arguments

  • number|Vector2 x

  • number? y

Returns self

Box:setSystemMinimumSize(x, y)

Arguments

  • number|Vector2 x

  • number? y

Returns self

Box:setGrowDirection(x, y)

Arguments

  • number|Vector2 x

  • number? y

Returns self

Box:setChildrenOffset(x, y)

Sets the shift of the children, useful for scrollbars.

Arguments

  • number|Vector2 x

  • number? y

Returns self

Box:getMinimumSize()

Gets the minimum size of the container.

Box:XYtoUV(x, y)

Converts a point from BBunits to UV units.

Arguments

  • number|Vector2 x

  • number? y

Returns Vector2

Box:UVtoXY(x, y)

Converts a point from UV units to BB units.

Arguments

  • number|Vector2 x

  • number? y

Returns Vector2

Box:toGlobal(x, y)

returns the global position of the given local position.

Arguments

  • number|Vector2 x

  • number? y

Returns Vector2

Box:toLocal(x, y)

returns the local position of the given global position.

Arguments

  • number|Vector2 x

  • number? y

Returns Vector2

Box:update(self)

Flags this Container to be updated.

Argument

Returns self

Box:updateTheming(self)

Calls the events that are most likely used by themes. ex. MOUSE_PRESSENCE_CHANGED

Argument

Returns self

Box:_update()

Box:updateSpriteTasks()

Box:forceUpdate(self)

Forces an update of the box.

Argument

Returns self

Box:_propagateUpdateToChildren()

Box:rebuildTextTasks(self)

Argument

Returns self

Box:repositionText()

Box:setText(self, text)

Sets the text to be displayed in the box. This supports raw json text

Argument

  • any text

Returns self

Box:setFontScale(scale)

Sets the scale of the text being displayed.

Arguments

  • number scale

Returns self

Box:setDefaultTextColor(color)

Sets the default text color

Arguments

  • Vector3|string color

Returns self

Box:setTextAlign(h, v)

Tells where to anchor the text at.
0 <-> 1, left <-> right
0 <-> 1, top <-> bottom

Arguments

  • number? h

  • number? v

Box:setTextBehavior(behavior)

Sets the flag if the text should wrap around when out of bounds.

Arguments

  • GNUI.TextBehavior behavior

Returns self

Box:setTextEffect(self, effect)

Argument

  • GNUI.TextEffect effect

Returns self

Box:setTextOffset(x, y)

Sets the offset of the text.

Arguments

  • number|Vector2 x

  • number? y

Returns self

Clone this wiki locally