Skip to content

BaseElement ​

Путь подключения: require "ProjectMotionUI/Core/BaseElement"


Класс PMUI.BaseElement ​

Наследуется от: ISUIElement

Методы и функции ​

PMUI.BaseElement:new() ​

Creates a base PMUI element with hierarchy, layout, animation, and interaction support.

Returns: PMUI.BaseElement

PMUI.BaseElement:GetHierarchyParent() ​

Returns the element's parent in the PMUI hierarchy.

Returns: PMUI.BaseElement\|nil

PMUI.BaseElement:GetHierarchyRoot() ​

Returns the top-level element in the current hierarchy.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetPersistState(enabled, key) ​

Enables or disables persistent state for this element. The state key is used to identify the element when saving and restoring its data.

ПараметрТипОписание
enabledbooleanWhether state persistence is enabled.
keystring|nilOptional unique state key. Defaults to the element type.

Returns: PMUI.BaseElement

PMUI.BaseElement:SaveState(data) ​

Saves the element's position, scale, and gravity state into the provided table.

ПараметрТипОписание
datatableState table to populate.

PMUI.BaseElement:LoadState(data) ​

Restores the element's position, scale, and gravity state. Position offsets are reset if the restored coordinates place the element outside the screen.

ПараметрТипОписание
datatablePreviously saved element state.

PMUI.BaseElement:ApplyStyle(styleNameOrList, params) ​

Applies one or more registered styles to the element. A table can be supplied to apply multiple styles in sequence.

ПараметрТипОписание
styleNameOrListstring|string[]Style name or an ordered list of style names.
paramstable|nilOptional parameters passed to each style function.

Returns: PMUI.BaseElement

PMUI.BaseElement:instantiate() ​

Initializes the element and all children registered in its PMUI hierarchy. Each child is initialized, instantiated, attached to the native UI hierarchy, and laid out.

PMUI.BaseElement:AddChild(child) ​

Adds a child element to the PMUI hierarchy. If the parent is already instantiated, the child is also initialized and attached immediately.

ПараметрТипОписание
childPMUI.BaseElementChild element to add.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetHoverSound(soundName) ​

Sets the sound played when the mouse enters the element.

ПараметрТипОписание
soundNamestring|nilUI sound name.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetClickSound(soundName) ​

Sets the sound played when the element is clicked.

ПараметрТипОписание
soundNamestring|nilUI sound name.

Returns: PMUI.BaseElement

PMUI.BaseElement:OnRender(fn) ​

Registers a callback executed during the element's render phase. The callback receives the element instance.

ПараметрТипОписание
fnfunctionRender callback.

Returns: PMUI.BaseElement

PMUI.BaseElement:OnPreRender(fn) ​

Registers a callback executed during the element's pre-render phase. The callback receives the element instance and frame delta time in seconds.

ПараметрТипОписание
fnfunctionPre-render callback.

Returns: PMUI.BaseElement

PMUI.BaseElement:OnHover(fn) ​

Registers a callback invoked when the element's hover state changes. The callback receives the element instance and the new hover state.

ПараметрТипОписание
fnfunctionHover callback.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetDraggable(enabled, targetElement) ​

Enables or disables dragging for this element. An optional target element can be specified to move a parent or another element instead.

ПараметрТипОписание
enabledbooleanWhether dragging is enabled.
targetElementPMUI.BaseElement|nilElement to move. Defaults to this element.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetGravity(enabled) ​

Enables or disables the falling physics effect. Enabling gravity starts a fall animation; disabling it restores the element's position.

ПараметрТипОписание
enabledbooleanWhether gravity is enabled.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetTooltip(titleOrText, text) ​

Sets the tooltip content displayed for this element. When only one argument is provided, it is treated as the tooltip text without a title.

ПараметрТипОписание
titleOrTextstringTooltip title or body text.
textstring|nilOptional tooltip body text.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetSize(offsetW, offsetH) ​

Sets the element's fixed width and height offsets. The final dimensions also include any parent-relative scale values.

ПараметрТипОписание
offsetWnumber|nilWidth offset in pixels.
offsetHnumber|nilHeight offset in pixels.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetSizePercent(scaleW, scaleH) ​

Sets the element's width and height as proportions of its parent.

ПараметрТипОписание
scaleWnumber|nilWidth scale relative to the parent.
scaleHnumber|nilHeight scale relative to the parent.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetPosition(offsetX, offsetY) ​

Sets the element's position using pixel offsets relative to its parent.

ПараметрТипОписание
offsetXnumber|nilHorizontal position offset.
offsetYnumber|nilVertical position offset.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetPositionPercent(scaleX, scaleY) ​

Sets the element's position using proportions of its parent dimensions.

ПараметрТипОписание
scaleXnumber|nilHorizontal position scale.
scaleYnumber|nilVertical position scale.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetAnchor(anchorX, anchorY) ​

Sets the element's anchor point. Anchor values are normalized: 0.0 represents the leading edge, 0.5 the center, and 1.0 the trailing edge.

ПараметрТипОписание
anchorXnumber|nilHorizontal anchor value.
anchorYnumber|nilVertical anchor value.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetPassThroughClicks(pass) ​

Controls whether mouse clicks pass through this element to elements behind it.

ПараметрТипОписание
passbooleanWhether mouse clicks should pass through.

Returns: PMUI.BaseElement

PMUI.BaseElement:SetAlpha(alpha) ​

Sets the element's opacity.

ПараметрТипОписание
alphanumberOpacity value, typically between 0.0 and 1.0.

Returns: PMUI.BaseElement

PMUI.BaseElement:ApplyPositionOnly() ​

Recalculates and applies the element's position without changing its dimensions. Position is calculated from parent-relative scale, pixel offsets, anchor, and animation offsets.

PMUI.BaseElement:RecalculateLayout() ​

Recalculates the element's dimensions and position. Also updates the layout of all child elements in the PMUI hierarchy.

PMUI.BaseElement:prerender() ​

Performs per-frame element updates before rendering. Updates animations, hover state, registered pre-render callbacks, and tooltip positioning.

PMUI.BaseElement:render() ​

Executes registered render callbacks and draws the debug overlay when enabled.

PMUI.BaseElement:onMouseDown(x, y) ​

Handles mouse button presses. Starts dragging when the element is draggable; otherwise respects click pass-through settings.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

Returns: boolean\|nil Whether the mouse event was handled.

PMUI.BaseElement:onMouseMove(dx, dy) ​

Updates the dragged element's position while the mouse moves. Keeps a short history of mouse positions for calculating the release velocity.

ПараметрТипОписание
dxnumberHorizontal mouse movement delta.
dynumberVertical mouse movement delta.

Returns: boolean\|nil True when the element is being dragged.

PMUI.BaseElement:onMouseMoveOutside(dx, dy) ​

Continues drag handling when the mouse moves outside the element's bounds.

ПараметрТипОписание
dxnumberHorizontal mouse movement delta.
dynumberVertical mouse movement delta.

PMUI.BaseElement:onMouseUp(x, y) ​

Handles mouse button release. Stops dragging and, if the element was falling before the drag, applies the release velocity to its fall animation.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

Returns: boolean\|nil Whether the mouse event was handled.

PMUI.BaseElement:onMouseUpOutside(x, y) ​

Handles mouse button release outside the element's bounds.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

PMUI.BaseElement:onRightMouseDown(x, y) ​

Handles right mouse button presses according to the click pass-through setting.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

Returns: boolean Whether the mouse event was handled.