Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(ui): UINode absolute positioning via position + inset (REARCH_GUI F3 / U2)

esengined9133973fc81
diff --git a/desktop/public/scenes/ui-node-absolute.esscene b/desktop/public/scenes/ui-node-absolute.esscene
new file mode 100644
index 000000000..7fe19c24f
--- /dev/null
+++ b/desktop/public/scenes/ui-node-absolute.esscene
@@ -0,0 +1,77 @@
+{
+ "version": "1.0",
+ "name": "UINode absolute positioning / inset (REARCH_GUI F3 unification)",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 10 } } },
+ { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 300, "isActive": true, "priority": 0 } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 1,
+ "name": "Canvas",
+ "parent": null,
+ "children": [2],
+ "components": [
+ { "type": "Transform", "data": {} },
+ { "type": "Canvas", "data": { "designResolution": { "x": 800, "y": 600 }, "scaleMode": 2 } },
+ { "type": "UIRect", "data": { "anchorMin": { "x": 0.5, "y": 0.5 }, "anchorMax": { "x": 0.5, "y": 0.5 }, "size": { "x": 800, "y": 600 }, "pivot": { "x": 0.5, "y": 0.5 } } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 2,
+ "name": "Panel",
+ "parent": 1,
+ "children": [3, 4, 5],
+ "components": [
+ { "type": "Transform", "data": {} },
+ { "type": "UINode", "data": { "width": { "value": 100, "unit": 1 }, "height": { "value": 100, "unit": 1 } } },
+ { "type": "UIRenderer", "data": { "visualType": 1, "color": { "r": 0.12, "g": 0.12, "b": 0.15, "a": 1 }, "enabled": true } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 3,
+ "name": "TopLeft",
+ "parent": 2,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": {} },
+ { "type": "UINode", "data": { "position": 1, "insetTop": { "value": 20, "unit": 0 }, "insetLeft": { "value": 20, "unit": 0 }, "width": { "value": 160, "unit": 0 }, "height": { "value": 100, "unit": 0 } } },
+ { "type": "UIRenderer", "data": { "visualType": 1, "color": { "r": 0.85, "g": 0.25, "b": 0.25, "a": 1 }, "enabled": true } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 4,
+ "name": "TopRight",
+ "parent": 2,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": {} },
+ { "type": "UINode", "data": { "position": 1, "insetTop": { "value": 20, "unit": 0 }, "insetRight": { "value": 20, "unit": 0 }, "width": { "value": 160, "unit": 0 }, "height": { "value": 100, "unit": 0 } } },
+ { "type": "UIRenderer", "data": { "visualType": 1, "color": { "r": 0.25, "g": 0.8, "b": 0.35, "a": 1 }, "enabled": true } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 5,
+ "name": "BottomBar",
+ "parent": 2,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": {} },
+ { "type": "UINode", "data": { "position": 1, "insetLeft": { "value": 0, "unit": 0 }, "insetRight": { "value": 0, "unit": 0 }, "insetBottom": { "value": 0, "unit": 0 }, "height": { "value": 80, "unit": 0 } } },
+ { "type": "UIRenderer", "data": { "visualType": 1, "color": { "r": 0.3, "g": 0.45, "b": 0.9, "a": 1 }, "enabled": true } }
+ ],
+ "visible": true
+ }
+ ]
+}
diff --git a/desktop/public/scenes/ui-node-absolute.textures.json b/desktop/public/scenes/ui-node-absolute.textures.json
new file mode 100644
index 000000000..9e26dfeeb
--- /dev/null
+++ b/desktop/public/scenes/ui-node-absolute.textures.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/sdk/src/component.generated.ts b/sdk/src/component.generated.ts
index ace8c5489..8461511db 100644
--- a/sdk/src/component.generated.ts
+++ b/sdk/src/component.generated.ts
@@ -12,7 +12,7 @@ import type { AssetFieldType } from './scene';
* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to
* run on mismatch, because mismatched offsets read the wrong heap bytes.
*/
-export const ABI_LAYOUT_HASH = '25bb0ec77b88b51a';
+export const ABI_LAYOUT_HASH = 'dba3504ff7b44cfd';
export interface AssetFieldMeta {
field: string;
@@ -457,6 +457,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {
},
UINode: {
defaults: {
+ position: 0,
width: { value: 0, unit: 2 },
height: { value: 0, unit: 2 },
minWidth: { value: 0, unit: 2 },
@@ -471,6 +472,10 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {
marginTop: { value: 0, unit: 0 },
marginRight: { value: 0, unit: 0 },
marginBottom: { value: 0, unit: 0 },
+ insetLeft: { value: 0, unit: 2 },
+ insetTop: { value: 0, unit: 2 },
+ insetRight: { value: 0, unit: 2 },
+ insetBottom: { value: 0, unit: 2 },
},
assetFields: [],
entityFields: [],
diff --git a/sdk/src/ecs/ptrAccessors.generated.ts b/sdk/src/ecs/ptrAccessors.generated.ts
index 5b397cb43..ebaa3f699 100644
--- a/sdk/src/ecs/ptrAccessors.generated.ts
+++ b/sdk/src/ecs/ptrAccessors.generated.ts
@@ -1138,6 +1138,7 @@ export function createUIMaskData(): UIMaskPtrData {
}
export interface UINodePtrData {
+ position: number;
flexGrow: number;
flexShrink: number;
alignSelf: number;
@@ -1147,22 +1148,25 @@ export function fillUINode(
f32: Float32Array, u32: Uint32Array, u8: Uint8Array,
ptr: number, out: UINodePtrData,
): void {
- out.flexGrow = f32[(ptr + 48) >> 2];
- out.flexShrink = f32[(ptr + 52) >> 2];
- out.alignSelf = u8[ptr + 64];
+ out.position = u8[ptr];
+ out.flexGrow = f32[(ptr + 52) >> 2];
+ out.flexShrink = f32[(ptr + 56) >> 2];
+ out.alignSelf = u8[ptr + 68];
}
export function writeUINode(
f32: Float32Array, u32: Uint32Array, u8: Uint8Array,
ptr: number, data: UINodePtrData,
): void {
- f32[(ptr + 48) >> 2] = data.flexGrow;
- f32[(ptr + 52) >> 2] = data.flexShrink;
- u8[ptr + 64] = data.alignSelf;
+ u8[ptr] = data.position;
+ f32[(ptr + 52) >> 2] = data.flexGrow;
+ f32[(ptr + 56) >> 2] = data.flexShrink;
+ u8[ptr + 68] = data.alignSelf;
}
export function createUINodeData(): UINodePtrData {
return {
+ position: 0,
flexGrow: 0,
flexShrink: 0,
alignSelf: 0,
diff --git a/sdk/src/ptrLayouts.generated.ts b/sdk/src/ptrLayouts.generated.ts
index 3adc42c15..c449b405e 100644
--- a/sdk/src/ptrLayouts.generated.ts
+++ b/sdk/src/ptrLayouts.generated.ts
@@ -303,9 +303,10 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
UINode: {
ptrFn: 'getUINodePtr',
fields: [
- { name: 'flexGrow', type: 'f32', offset: 48 },
- { name: 'flexShrink', type: 'f32', offset: 52 },
- { name: 'alignSelf', type: 'u8', offset: 64 },
+ { name: 'position', type: 'u8', offset: 0 },
+ { name: 'flexGrow', type: 'f32', offset: 52 },
+ { name: 'flexShrink', type: 'f32', offset: 56 },
+ { name: 'alignSelf', type: 'u8', offset: 68 },
],
},
UIRect: {
diff --git a/sdk/src/ui/core/ui-node.ts b/sdk/src/ui/core/ui-node.ts
index a298a8978..34607447b 100644
--- a/sdk/src/ui/core/ui-node.ts
+++ b/sdk/src/ui/core/ui-node.ts
@@ -14,7 +14,19 @@
import { defineBuiltin } from '../../component';
import { auto, px, type Dimension } from './dimension';
+/** Positioning scheme (mirrors the C++ UIPositionType enum). */
+export const UIPositionType = {
+ /** In flex flow (default). */
+ Relative: 0,
+ /** Out of flow; placed by `inset` against the parent box — covers
+ * anchor/stretch (the old RectTransform cases). */
+ Absolute: 1,
+} as const;
+export type UIPositionType = (typeof UIPositionType)[keyof typeof UIPositionType];
+
export interface UINodeData {
+ /** Relative (flex flow) or Absolute (placed by inset). */
+ position: number;
/** Box size; `auto()` = content-/flex-driven. */
width: Dimension;
height: Dimension;
@@ -34,9 +46,16 @@ export interface UINodeData {
marginTop: Dimension;
marginRight: Dimension;
marginBottom: Dimension;
+ /** Offset from the parent's edges when `position` is Absolute; `auto()` =
+ * that edge is unconstrained. Mirrors CSS left/top/right/bottom. */
+ insetLeft: Dimension;
+ insetTop: Dimension;
+ insetRight: Dimension;
+ insetBottom: Dimension;
}
export const UINode = defineBuiltin<UINodeData>('UINode', {
+ position: 0,
width: auto(),
height: auto(),
minWidth: auto(),
@@ -51,4 +70,8 @@ export const UINode = defineBuiltin<UINodeData>('UINode', {
marginTop: px(0),
marginRight: px(0),
marginBottom: px(0),
+ insetLeft: auto(),
+ insetTop: auto(),
+ insetRight: auto(),
+ insetBottom: auto(),
});
diff --git a/sdk/src/ui/index.ts b/sdk/src/ui/index.ts
index 4fdf04225..35c8b8083 100644
--- a/sdk/src/ui/index.ts
+++ b/sdk/src/ui/index.ts
@@ -67,7 +67,7 @@ export {
// ─── Layer 1: Primitives ────────────────────────────────────────────────────
export { DimensionUnit, type Dimension, px, percent, auto, isAuto } from './core/dimension';
-export { UINode, type UINodeData } from './core/ui-node';
+export { UINode, UIPositionType, type UINodeData } from './core/ui-node';
export { UIRect, type UIRectData } from './core/ui-rect';
export {
diff --git a/sdk/src/wasm.generated.ts b/sdk/src/wasm.generated.ts
index cce156b01..31e9082bd 100644
--- a/sdk/src/wasm.generated.ts
+++ b/sdk/src/wasm.generated.ts
@@ -122,6 +122,11 @@ export enum TextAlign {
Right = 2,
}
+export enum UIPositionType {
+ Relative = 0,
+ Absolute = 1,
+}
+
export enum UIVisualType {
None = 0,
SolidColor = 1,
@@ -432,6 +437,7 @@ export interface UIMask {
}
export interface UINode {
+ position: number;
width: Dimension;
height: Dimension;
minWidth: Dimension;
@@ -446,6 +452,10 @@ export interface UINode {
marginTop: Dimension;
marginRight: Dimension;
marginBottom: Dimension;
+ insetLeft: Dimension;
+ insetTop: Dimension;
+ insetRight: Dimension;
+ insetBottom: Dimension;
}
export interface UIRect {
diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cpp
index 815b492b5..c430ff21f 100644
--- a/src/esengine/bindings/EditorAPI.generated.cpp
+++ b/src/esengine/bindings/EditorAPI.generated.cpp
@@ -2,10 +2,10 @@
* @file EditorAPI.generated.cpp
* @brief Auto-generated editor API with string-dispatched component access
* @details Generated by EHT - DO NOT EDIT
- * @schema_hash 9ffcadb10a7a752e
+ * @schema_hash 7084ff0da3e21818
*/
-#define ES_EDITOR_API_SCHEMA_HASH "9ffcadb10a7a752e"
+#define ES_EDITOR_API_SCHEMA_HASH "7084ff0da3e21818"
#include <emscripten/bind.h>
#include <string>
@@ -472,6 +472,7 @@ std::string editor_getComponentSchema(const std::string& name) {
])JSON";
} else if (name == "UINode") {
return R"JSON([
+ {"key":"position","type":"enum","group":"UINode","values":["Relative","Absolute"]},
{"key":"width.value","type":"float","group":"UINode"},
{"key":"width.unit","type":"float","group":"UINode"},
{"key":"height.value","type":"float","group":"UINode"},
@@ -496,7 +497,15 @@ std::string editor_getComponentSchema(const std::string& name) {
{"key":"marginRight.value","type":"float","group":"UINode"},
{"key":"marginRight.unit","type":"float","group":"UINode"},
{"key":"marginBottom.value","type":"float","group":"UINode"},
- {"key":"marginBottom.unit","type":"float","group":"UINode"}
+ {"key":"marginBottom.unit","type":"float","group":"UINode"},
+ {"key":"insetLeft.value","type":"float","group":"UINode"},
+ {"key":"insetLeft.unit","type":"float","group":"UINode"},
+ {"key":"insetTop.value","type":"float","group":"UINode"},
+ {"key":"insetTop.unit","type":"float","group":"UINode"},
+ {"key":"insetRight.value","type":"float","group":"UINode"},
+ {"key":"insetRight.unit","type":"float","group":"UINode"},
+ {"key":"insetBottom.value","type":"float","group":"UINode"},
+ {"key":"insetBottom.unit","type":"float","group":"UINode"}
])JSON";
} else if (name == "UIRect") {
return R"JSON([
@@ -1103,6 +1112,14 @@ bool editor_setFloat(Registry& reg, u32 e, const std::string& comp, const std::s
else if (field == "marginRight.unit") { c.marginRight.unit = value; }
else if (field == "marginBottom.value") { c.marginBottom.value = value; }
else if (field == "marginBottom.unit") { c.marginBottom.unit = value; }
+ else if (field == "insetLeft.value") { c.insetLeft.value = value; }
+ else if (field == "insetLeft.unit") { c.insetLeft.unit = value; }
+ else if (field == "insetTop.value") { c.insetTop.value = value; }
+ else if (field == "insetTop.unit") { c.insetTop.unit = value; }
+ else if (field == "insetRight.value") { c.insetRight.value = value; }
+ else if (field == "insetRight.unit") { c.insetRight.unit = value; }
+ else if (field == "insetBottom.value") { c.insetBottom.value = value; }
+ else if (field == "insetBottom.unit") { c.insetBottom.unit = value; }
else { return false; }
return true;
} else if (comp == "UIRect") {
@@ -1437,6 +1454,14 @@ f32 editor_getFloat(Registry& reg, u32 e, const std::string& comp, const std::st
else if (field == "marginRight.unit") { return c.marginRight.unit; }
else if (field == "marginBottom.value") { return c.marginBottom.value; }
else if (field == "marginBottom.unit") { return c.marginBottom.unit; }
+ else if (field == "insetLeft.value") { return c.insetLeft.value; }
+ else if (field == "insetLeft.unit") { return c.insetLeft.unit; }
+ else if (field == "insetTop.value") { return c.insetTop.value; }
+ else if (field == "insetTop.unit") { return c.insetTop.unit; }
+ else if (field == "insetRight.value") { return c.insetRight.value; }
+ else if (field == "insetRight.unit") { return c.insetRight.unit; }
+ else if (field == "insetBottom.value") { return c.insetBottom.value; }
+ else if (field == "insetBottom.unit") { return c.insetBottom.unit; }
} else if (comp == "UIRect") {
if (!reg.has<esengine::ecs::UIRect>(entity)) return 0.0f;
const auto& c = reg.get<esengine::ecs::UIRect>(entity);
@@ -1643,7 +1668,8 @@ bool editor_setInt(Registry& reg, u32 e, const std::string& comp, const std::str
} else if (comp == "UINode") {
if (!reg.has<esengine::ecs::UINode>(entity)) return false;
auto& c = reg.get<esengine::ecs::UINode>(entity);
- if (field == "alignSelf") { c.alignSelf = static_cast<AlignSelf>(value); }
+ if (field == "position") { c.position = static_cast<UIPositionType>(value); }
+ else if (field == "alignSelf") { c.alignSelf = static_cast<AlignSelf>(value); }
else { return false; }
return true;
} else if (comp == "UIRenderer") {
@@ -1783,7 +1809,8 @@ i32 editor_getInt(Registry& reg, u32 e, const std::string& comp, const std::stri
} else if (comp == "UINode") {
if (!reg.has<esengine::ecs::UINode>(entity)) return 0;
const auto& c = reg.get<esengine::ecs::UINode>(entity);
- if (field == "alignSelf") { return static_cast<i32>(c.alignSelf); }
+ if (field == "position") { return static_cast<i32>(c.position); }
+ else if (field == "alignSelf") { return static_cast<i32>(c.alignSelf); }
} else if (comp == "UIRenderer") {
if (!reg.has<esengine::ecs::UIRenderer>(entity)) return 0;
const auto& c = reg.get<esengine::ecs::UIRenderer>(entity);
diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cpp
index a2017a153..ac98b3c39 100644
--- a/src/esengine/bindings/WebBindings.generated.cpp
+++ b/src/esengine/bindings/WebBindings.generated.cpp
@@ -170,6 +170,10 @@ EMSCRIPTEN_BINDINGS(esengine_enums) {
.value("Center", esengine::ecs::TextAlign::Center)
.value("Right", esengine::ecs::TextAlign::Right);
+ enum_<esengine::ecs::UIPositionType>("UIPositionType")
+ .value("Relative", esengine::ecs::UIPositionType::Relative)
+ .value("Absolute", esengine::ecs::UIPositionType::Absolute);
+
enum_<esengine::ecs::UIVisualType>("UIVisualType")
.value("None", esengine::ecs::UIVisualType::None)
.value("SolidColor", esengine::ecs::UIVisualType::SolidColor)
@@ -835,6 +839,7 @@ UIMaskJS uimaskToJS(const esengine::ecs::UIMask& c) {
}
struct UINodeJS {
+ i32 position;
Dimension width;
Dimension height;
Dimension minWidth;
@@ -849,10 +854,15 @@ struct UINodeJS {
Dimension marginTop;
Dimension marginRight;
Dimension marginBottom;
+ Dimension insetLeft;
+ Dimension insetTop;
+ Dimension insetRight;
+ Dimension insetBottom;
};
esengine::ecs::UINode uinodeFromJS(const UINodeJS& js) {
esengine::ecs::UINode c;
+ c.position = static_cast<UIPositionType>(js.position);
c.width = js.width;
c.height = js.height;
c.minWidth = js.minWidth;
@@ -867,11 +877,16 @@ esengine::ecs::UINode uinodeFromJS(const UINodeJS& js) {
c.marginTop = js.marginTop;
c.marginRight = js.marginRight;
c.marginBottom = js.marginBottom;
+ c.insetLeft = js.insetLeft;
+ c.insetTop = js.insetTop;
+ c.insetRight = js.insetRight;
+ c.insetBottom = js.insetBottom;
return c;
}
UINodeJS uinodeToJS(const esengine::ecs::UINode& c) {
UINodeJS js;
+ js.position = static_cast<i32>(c.position);
js.width = c.width;
js.height = c.height;
js.minWidth = c.minWidth;
@@ -886,6 +901,10 @@ UINodeJS uinodeToJS(const esengine::ecs::UINode& c) {
js.marginTop = c.marginTop;
js.marginRight = c.marginRight;
js.marginBottom = c.marginBottom;
+ js.insetLeft = c.insetLeft;
+ js.insetTop = c.insetTop;
+ js.insetRight = c.insetRight;
+ js.insetBottom = c.insetBottom;
return js;
}
@@ -1206,6 +1225,7 @@ EMSCRIPTEN_BINDINGS(esengine_components) {
.field("mode", &UIMaskJS::mode);
value_object<UINodeJS>("UINode")
+ .field("position", &UINodeJS::position)
.field("width", &UINodeJS::width)
.field("height", &UINodeJS::height)
.field("minWidth", &UINodeJS::minWidth)
@@ -1219,7 +1239,11 @@ EMSCRIPTEN_BINDINGS(esengine_components) {
.field("marginLeft", &UINodeJS::marginLeft)
.field("marginTop", &UINodeJS::marginTop)
.field("marginRight", &UINodeJS::marginRight)
- .field("marginBottom", &UINodeJS::marginBottom);
+ .field("marginBottom", &UINodeJS::marginBottom)
+ .field("insetLeft", &UINodeJS::insetLeft)
+ .field("insetTop", &UINodeJS::insetTop)
+ .field("insetRight", &UINodeJS::insetRight)
+ .field("insetBottom", &UINodeJS::insetBottom);
value_object<esengine::ecs::UIRect>("UIRect")
.field("anchorMin", &esengine::ecs::UIRect::anchorMin)
@@ -2077,9 +2101,10 @@ static_assert(offsetof(esengine::ecs::UIInteraction, justPressed) == 2, "ABI off
static_assert(offsetof(esengine::ecs::UIInteraction, justReleased) == 3, "ABI offset drift: esengine::ecs::UIInteraction.justReleased (EHT expected 3)");
static_assert(offsetof(esengine::ecs::UIMask, enabled) == 0, "ABI offset drift: esengine::ecs::UIMask.enabled (EHT expected 0)");
static_assert(offsetof(esengine::ecs::UIMask, mode) == 1, "ABI offset drift: esengine::ecs::UIMask.mode (EHT expected 1)");
-static_assert(offsetof(esengine::ecs::UINode, flexGrow) == 48, "ABI offset drift: esengine::ecs::UINode.flexGrow (EHT expected 48)");
-static_assert(offsetof(esengine::ecs::UINode, flexShrink) == 52, "ABI offset drift: esengine::ecs::UINode.flexShrink (EHT expected 52)");
-static_assert(offsetof(esengine::ecs::UINode, alignSelf) == 64, "ABI offset drift: esengine::ecs::UINode.alignSelf (EHT expected 64)");
+static_assert(offsetof(esengine::ecs::UINode, position) == 0, "ABI offset drift: esengine::ecs::UINode.position (EHT expected 0)");
+static_assert(offsetof(esengine::ecs::UINode, flexGrow) == 52, "ABI offset drift: esengine::ecs::UINode.flexGrow (EHT expected 52)");
+static_assert(offsetof(esengine::ecs::UINode, flexShrink) == 56, "ABI offset drift: esengine::ecs::UINode.flexShrink (EHT expected 56)");
+static_assert(offsetof(esengine::ecs::UINode, alignSelf) == 68, "ABI offset drift: esengine::ecs::UINode.alignSelf (EHT expected 68)");
static_assert(offsetof(esengine::ecs::UIRect, anchorMin) == 0, "ABI offset drift: esengine::ecs::UIRect.anchorMin (EHT expected 0)");
static_assert(offsetof(esengine::ecs::UIRect, anchorMax) == 8, "ABI offset drift: esengine::ecs::UIRect.anchorMax (EHT expected 8)");
static_assert(offsetof(esengine::ecs::UIRect, offsetMin) == 16, "ABI offset drift: esengine::ecs::UIRect.offsetMin (EHT expected 16)");
@@ -2102,7 +2127,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif
// ABI Hash -- runtime handshake against the SDK bundle
// =============================================================================
-static const char* kEsAbiLayoutHash = "25bb0ec77b88b51a";
+static const char* kEsAbiLayoutHash = "dba3504ff7b44cfd";
std::string esengineGetAbiLayoutHash() {
return std::string(kEsAbiLayoutHash);
diff --git a/src/esengine/ecs/UILayoutSystem.cpp b/src/esengine/ecs/UILayoutSystem.cpp
index d7dbaf1bc..b07d12832 100644
--- a/src/esengine/ecs/UILayoutSystem.cpp
+++ b/src/esengine/ecs/UILayoutSystem.cpp
@@ -431,9 +431,20 @@ void applyMargin(YGNodeRef n, YGEdge edge, const Dimension& d) {
else if (d.unit == DIM_AUTO) YGNodeStyleSetMarginAuto(n, edge);
else YGNodeStyleSetMargin(n, edge, d.value);
}
+void applyInset(YGNodeRef n, YGEdge edge, const Dimension& d) {
+ // Auto = that edge is unconstrained; leave it unset so size/flow decides.
+ if (d.unit == DIM_PERCENT) YGNodeStyleSetPositionPercent(n, edge, d.value);
+ else if (d.unit == DIM_PX) YGNodeStyleSetPosition(n, edge, d.value);
+}
void applyUINodeStyle(Registry& registry, Entity entity, YGNodeRef yg) {
auto& n = registry.get<UINode>(entity);
+ YGNodeStyleSetPositionType(yg, n.position == UIPositionType::Absolute
+ ? YGPositionTypeAbsolute : YGPositionTypeRelative);
+ applyInset(yg, YGEdgeLeft, n.insetLeft);
+ applyInset(yg, YGEdgeTop, n.insetTop);
+ applyInset(yg, YGEdgeRight, n.insetRight);
+ applyInset(yg, YGEdgeBottom, n.insetBottom);
applyWidth(yg, n.width);
applyHeight(yg, n.height);
applyMinWidth(yg, n.minWidth);
diff --git a/src/esengine/ecs/components/UINode.hpp b/src/esengine/ecs/components/UINode.hpp
index 01c555769..8e5de1a63 100644
--- a/src/esengine/ecs/components/UINode.hpp
+++ b/src/esengine/ecs/components/UINode.hpp
@@ -10,6 +10,19 @@
namespace esengine::ecs {
+/**
+ * @brief Box positioning scheme. Absolute takes the node out of flex flow and
+ * places it by `inset` against the parent's box — this is how anchor /
+ * stretch (the old RectTransform use cases) are expressed in the CSS
+ * model (REARCH_GUI F3 unification): e.g. inset 0 on all edges = stretch
+ * to fill; top+right set = anchor to the top-right corner.
+ */
+ES_ENUM()
+enum class UIPositionType : u8 {
+ Relative,
+ Absolute
+};
+
/**
* @brief UINode — the CSS box-model layout input (REARCH_GUI F3, the CSS/Flex
* primary layout model; see docs/REARCH_GUI.md).
@@ -26,6 +39,10 @@ namespace esengine::ecs {
*/
ES_COMPONENT()
struct UINode {
+ // Positioning: Relative = in flex flow; Absolute = placed by `inset`.
+ ES_PROPERTY()
+ UIPositionType position{UIPositionType::Relative};
+
// Box size; auto = content-/flex-driven.
ES_PROPERTY()
Dimension width{0.0f, 2};
@@ -60,6 +77,18 @@ struct UINode {
ES_PROPERTY()
Dimension marginBottom{0.0f, 0};
+ // Inset (offset from the parent's edges) for Absolute positioning;
+ // auto = that edge is unconstrained (size/flow decides). Mirrors CSS
+ // left/top/right/bottom.
+ ES_PROPERTY()
+ Dimension insetLeft{0.0f, 2};
+ ES_PROPERTY()
+ Dimension insetTop{0.0f, 2};
+ ES_PROPERTY()
+ Dimension insetRight{0.0f, 2};
+ ES_PROPERTY()
+ Dimension insetBottom{0.0f, 2};
+
// Layout output (not serialized): resolved px size written by the Yoga pass.
glm::vec2 computed_size_{0.0f};