-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There should be a way to position bevy_ui children independently of parent Flex parameters #9167
Comments
This is the same behaviour as in CSS positioning, I'd leave it as is for consistency personally. |
What do you mean? If an element is set as |
Ok, maybe you meant the behavior with regard to the "containing block". Though I'm not sure I follow what the mdn dock is about here1. You seem to know quite well CSS, could you link to documentation in question? It's very easy to have a wrong idea of what's going on. I personally tried a few possible combination of properties in the mdn playground before opening this issue, and still have little idea of the correct behavior. In any case bevy already doesn't follow web standards with the I think, ideally, UI rendering should be fully decoupled from UI layouting, allowing for 3rd party layout algos to benefit from the UI rendering without having to deal with the very thing they try to replace. A potential alternative is to add a "do not compute" Your proposed solution is extremely cumbersome to implement for my usecase, check the linked issue for an explanation why it would be impractical. Lastly, I thought of a different workaround, which is to set the Footnotes
|
This is the intended behavior and works like in CSS: The same example in HTML/CSS<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
html,
body {
margin: 0;
}
div {
display: flex;
box-sizing: border-box;
position: relative;
}
</style>
</head>
<body>
<div
style="
background-color: yellow;
border: solid red 10px;
width: 300px;
height: 50px;
"
>
<div style="position: absolute; left: 0; right: 0; top: 0; bottom: 0">
Bad border!
</div>
</div>
</body>
</html> This is because, even with SolutionI know of two ways to solve this problem in HTML/CSS, from my testing it seems like they both work in Bevy as well: Negative Margin of ChildThe first option is to give the child element a negative margin equal to the border width. HTML/CSS code sample<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
html,
body {
margin: 0;
}
div {
display: flex;
box-sizing: border-box;
position: relative;
}
</style>
</head>
<body>
<div
style="
background-color: yellow;
border: solid red 10px;
width: 300px;
height: 50px;
"
>
<div
style="
position: absolute;
margin: -10px;
left: 0;
right: 0;
top: 0;
bottom: 0;
"
>
Bad border!
</div>
</div>
</body>
</html> Border of Child ElementThe second option is to add the border via another child element, instead of adding it directly to the parent. HTML/CSS code sample<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
html,
body {
margin: 0;
}
div {
display: flex;
box-sizing: border-box;
position: relative;
}
</style>
</head>
<body>
<div style="background-color: yellow; width: 300px; height: 50px">
<div
style="
position: absolute;
border: solid red 10px;
width: 100%;
height: 100%;
"
></div>
<div style="position: absolute; left: 0; right: 0; top: 0; bottom: 0">
Bad border!
</div>
</div>
</body>
</html> |
Any solution that requires propagating the offset to the children is a no-go for my use case. Ideally, I could just turn off layout computation. |
It seems the issue here is that the only two position types are I suppose either a PositionType::Static or a PositionType::Fixed might solve your issue? I'd be happy to give a go at implementing one of these, or at least see how far I could get, unless there's a reason they don't exist already? |
PositionType::Absolute
children
I'd love to see that! It would be great. It was probably overlooked because "why the hell would you need that?" Which is fair ahah. until someone (like me) has a usecase you don't expect. |
A couple of notes:
|
The lack of There are also complications for people wanting to embed Taffy in a widget system that is not "all in" on Taffy and that doesn't give the layout algorithm access to the entire tree at once (although we could likely just not support this feature for that use case while still supporting it in the case that you do have access to the entire tree) |
#9931 implements the |
Bevy version
main: ede5848
What you did
I set the border of a node with a
PositionType::Absolute
child.What went wrong
The child's position changed according to the border width, while it shouldn't, as
Absolute
implies.Additional information
Click to see Minimal reproducible example
The text was updated successfully, but these errors were encountered: