mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 21:15:52 +03:00
[GH-ISSUE #406] Relative and absolute positions do not work properly #104
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#104
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @imaai on GitHub (Dec 11, 2025).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/406
Seems like it's a little broken.
@kommander commented on GitHub (Dec 11, 2025):
Contrary to web browsers absolute elements are always global absolute, not relative to their parents. That is currently expected behaviour. I am open to changing that and make absolutely positioned elements relative to the closest explicitly relative positioned parent, then it would be browser like behavior.
@imaai commented on GitHub (Dec 11, 2025):
@kommander
When running first example I thought it behaves like "fixed" position, but notice that in second example I set
bottom: 0, green container is being positioned in the fourth line from the top. Just like the height of the relative container.I checked that it computes the position based on the height of closest parent height, which i find super confusing.
@kommander commented on GitHub (Dec 11, 2025):
That is either a yoga quirk, or the yoga nodes are not set up properly. Does it work with the yoga web examples https://www.yogalayout.dev/playground ?
@imaai commented on GitHub (Dec 11, 2025):
@kommander In yoga playground it works as expected. Also for the relatives.
@kommander commented on GitHub (Dec 11, 2025):
Then we need to check how opentui sets up the nodes differently.
@edlsh commented on GitHub (Dec 13, 2025):
Looked into this. Pretty sure the issue is in the
x/ygetters inRenderable.ts.Yoga's
getComputedLayout()always returns positions relative to the parent (confirmed here), but we only add the parent offset forrelativeelements and skip it forabsolute. That's backwards.So when you set
bottom: 0, Yoga does the right thing and computestop = parentHeight - childHeight, but then we don't add where the parent actually is on screen. That's why you get the weird behavior.Fix is just removing the position type check:
This matches what Yoga's docs describe for containing blocks.
@kommander commented on GitHub (Dec 13, 2025):
I am afraid it's not as simple as that, because x/y are considered screen coordinates that the renderables are rendered to. If you don't add the parent offset, all Renderables start at the top right 0/0 position of the screen.
Edit: re your PR, what is absolute positioning then when parent offset is always added?