-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Node size computed incorrectly(?) on cross axis for AlignItems::Stretch #291
Comments
(no clue if it's a bug or working as expected, label can always be removed later 😅 ) |
I can try to get a repro of this using Stretch directly, and if the same issue happens with Stretch we can raise this with them. Maybe this is expected behaviour. |
Sounds like a plan to me. Thanks for the thoroughness here! |
Edit: I just checked and it is the same behaviour regardless of whether the parent node is the root node or nested under the root. |
I have not been able to reproduce this problem using Stretch directly: https://gist.github.com/stefee/b01f1f7097bcfc2de6727742231d4199 Stretch computes the child node height correctly:
So this does actually appear to be a Bevy UI issue. |
I also just confirmed that the Bevy UI behaviour is the same when the parent has |
@stefee It seems that if you set each of the Flex Items' |
@harrywincup This might be it... Bevy UI should default |
OK, so I just tried setting the child style to the following in my Stretch gist: Style {
size: Size{
width: Dimension::Undefined,
height: Dimension::Undefined,
},
flex_basis: Dimension::Percent(50.0),
..Default::default()
} And this resulted in the following test output:
I think we might have found the bug @harrywincup! |
@stefee Well i've got no idea what i'm doing because i'm a total Rust newbie, but it sounds like you're making progress! These lines in Stretch also seem relevant, as it appears to resolve any
https://github.com/vislyhq/stretch/blob/6879b9a1cf3c244430bbf8b88bf205c614d72562/src/algo.rs#L227 I don't know what the suggestion is to fix, but it definitely seems like Bevy should be doing something similar? |
@harrywincup |
@stefee Yeah I think so. I suppose the question then is what the correct input is? Are you thinking that the default here should be bevy/crates/bevy_ui/src/node.rs Line 95 in a3c0740
|
So I think ideally we should do something like this in impl Default for Size<Val> {
fn default() -> Self {
Self { width: Val::Auto, height: Val::Auto }
}
} This matches Stretch default: But this doesn't currently work because of these errors:
|
I updated the issue description with @harrywincup's solution. |
Here is a CodeSandbox showing how
flex-basis
andalign-items: stretch
works: https://codesandbox.io/s/stoic-turing-tdyz7?file=/index.htmlNote that by default
align-items
isstretch
in browsers and also in the Stretch library which Bevy UI is based on.I am trying to reproduce the above CodeSandbox using Bevy UI: https://github.com/stefee/bevy/commit/33bdca418f1944ed05daf9e8c1e96217106e32ff
The above code results in a purple square – the parent node is visible but not the child nodes, because the child nodes have a height of 0.
Height in this case corresponds to the "cross axis" in the flex model, and the child node should have cross axis size of 100% when
AlignItems::Stretch
is used. (See Guide to Flexbox).Workaround
The current workaround is to specify a
size
as well as (or instead of)flex_basis
.The problem with this is that width and height do not respect flex direction, so if you were to change flex direction (e.g. from row to column) you would need to also swap the width and height properties.
Also, if you were to change the parent to use something other than
AlignItems::Stretch
you would then need to update the child sizes as well to get the desired effect.Update 24/08/18
@harrywincup found a better workaround of using
Val::Auto
for the child node size.This has the same result as the above workaround, but with the advantage that flex direction is respected and
AlignItems
behaviour works as expected.I've opened a PR to make
Val::Auto
the default value forstyle.size
. 👉 #304The text was updated successfully, but these errors were encountered: