Skip to content

Commit ff5de44

Browse files
ui: document anchor property and demo top-left anchor
- reference.md: document UIObject.anchor in the UI System section - examples/uiSystem/game.js: add a 'Menu' toggle button anchored to the top-left corner of the canvas with a 20px inset; showcases the anchor + self-pivot combination Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4a1e21a commit ff5de44

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

examples/uiSystem/game.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ function createUI()
8888
()=> setMenuVisible(false));
8989
button2.navigationIndex = ++navigationIndex;
9090
button2.navigationAutoSelect = true;
91+
92+
// menu toggle button anchored to top-left corner of the canvas with a 20px inset
93+
const buttonToggle = new LJS.UIButton(vec2(20, 20), vec2(150, 60), 'Menu');
94+
buttonToggle.anchor = vec2(-1, -1);
95+
buttonToggle.onClick = ()=> setMenuVisible(!getMenuVisible());
9196
}
9297

9398
///////////////////////////////////////////////////////////////////////////////

reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ uiSystem.drawLine(posA, posB, lineWidth, lineColor)
523523

524524
// Base widget
525525
new UIObject(pos=vec2(), size=vec2())
526+
UIObject.anchor // vec2 in [-1,1]; anchors to parent (or canvas if root) + self-pivot; default vec2()=center
526527
UIObject.addChild(child) // Returns child, parents it
527528
UIObject.removeChild(child)
528529
UIObject.destroy()

0 commit comments

Comments
 (0)