-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Seperate ui::Node
style fields into seperate required components
#20982
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
base: main
Are you sure you want to change the base?
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
As a proof of concept, I have only done it for |
Wouldn't you also want a bare |
I think under this scheme either the display field would become boolean on both the flex and grid components, with false removing the node and its descendants from the layout. Or it would use an optional marker component 'RemoveFromLayout' (or whatever) that denotes the same thing by its presence. |
So something like this(?): #[derive(Component, Clone, PartialEq, Debug, Reflect)]
pub struct Block {
pub display: bool,
pub justify_items: JustifyItems,
pub justify_self: JustifySelf,
}
#[derive(Component, Clone, PartialEq, Debug, Reflect)]
pub struct Flex {
pub display: bool,
pub flex_direction: FlexDirection,
pub flex_wrap: FlexWrap,
pub flex_grow: f32,
pub flex_shrink: f32,
pub flex_basis: Val,
}
#[derive(Component, Clone, PartialEq, Debug, Reflect)]
pub struct Grid {
pub display: bool,
pub justify_items: JustifyItems,
pub justify_self: JustifySelf,
pub grid_auto_flow: GridAutoFlow,
pub grid_template_rows: Vec<RepeatedGridTrack>,
pub grid_template_columns: Vec<RepeatedGridTrack>,
pub grid_auto_rows: Vec<GridTrack>,
pub grid_auto_columns: Vec<GridTrack>,
pub grid_row: GridPlacement,
pub grid_column: GridPlacement,
} And then keep the rest of the common fields in the Also, does mutually exclusive mean an enum or something bevy specific? |
IIRC @viridia or @ickshonpe or @nicoburns had a really nice idea to split this by FlexParent/FlexChild/GridParent/GridChild, to avoid wasted data while enforcing valid state. I'm still partial to that design. |
I was thinking:
As far as |
Performance-wise it's not going to be significant either way. But it occured to while looking at the FPS overlay PR, that since a lot of users are confused about whether they should use pub enum UiVisibility {
/// An entity with `UiVisibility::Inherited` will inherit the UiVisibility of its [`ChildOf`] target.
///
/// A root-level entity that is set to `Inherited` will be visible.
#[default]
Inherited,
/// An entity with `UiVisibility::Hidden` will be unconditionally hidden.
Hidden,
/// An entity with `UiVisibility::Visible` will be unconditionally visible.
///
/// Note that an entity with `UiVisibility::Visible` will be visible regardless of whether the
/// [`ChildOf`] target entity is hidden.
Visible,
/// The entity and it's decendents are removed from the UI layout and do not occupy any space.
Removed,
} It does mean even further divergence from the rendering APIs, though, which isn't great. |
I assume these would not be mutually exclusive, because it is possible to have a grid item also contain another grid or the like. |
547411d
to
27e4921
Compare
I just pushed the initial splitting of |
Checkout Taffy's *Style traits for a guide on what goes where https://docs.rs/taffy/latest/taffy/style/index.html#traits |
The only difference between what I have so far and what taffy does is that for blocks, I added more align/justify properties from the table in https://www.w3.org/TR/2025/WD-css-align-3-20250311/#overview. |
That makes sense, although Taffy doesn't implement those properties for Blocks yet (they were only very recently added to the standard - I don't think Firefox implements them all yet either). |
I have the conversion to taffy style done, the only annoyance was that for some of the properties (especially the justify/align ones), could be duplicated across different containers or items. One way to fix this would be to make the container mutually exclusive and the item mutually exclusive (each node can "have" only one container and one item), but I don't know the best way to do this. |
Objective
Fixes #16580
Solution
Extract out all style fields from the
ui::Node
struct to separate (required on Node) components.Possibly group similar style components (like
width
andheight
) into one component as opposed to individual components.The only place these fields are used are in the conversion to
taffy
styles, so I created a struct to represent a query (withQueryData
) of all the style components and pass that around.Testing
This PR doesn't add anything new, so I am relying on the current tests for
ui::Node
.I have tested it with
cargo run -p ci
.Unless
cargo run -p ci
runs it on different architecture/platforms, I have run it on Linux x86_64.Showcase
While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases:
Click to view showcase