-
-
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
[Merged by Bors] - Document how padding
and margin
behave with percentage values
#7785
Conversation
padding
field of Style
.padding
's behaviour with percentage values
padding
's behaviour with percentage valuespadding
behaves with percentage values
padding
behaves with percentage valuespadding
behaves with percentage values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks good, but:
- I think it would be good to explicitly write out that this applies to even top/bottom padding
- It would be good to add the same note to margin and border
padding
behaves with percentage valuespadding
and margin
behave with percentage values
I thought borders were implemented in Bevy and occupied space around a node but just weren't rendered, but that doesn't seem to be right like in this example: fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
let root = commands.spawn(NodeBundle {
style: Style {
flex_direction: FlexDirection::Column,
flex_basis: Val::Percent(100.0),
margin: UiRect::all(Val::Px(25.0)),
flex_wrap: FlexWrap::Wrap,
justify_content: JustifyContent::FlexStart,
align_items: AlignItems::FlexStart,
align_content: AlignContent::FlexStart,
..Default::default()
},
background_color: BackgroundColor(Color::BLACK),
..Default::default()
}).id();
let borders = [
UiRect::all(Val::Auto),
UiRect::all(Val::Px(0.)),
UiRect::all(Val::Px(25.0)),
UiRect::all(Val::Px(250.0)),
UiRect::all(Val::Undefined),
UiRect::all(Val::Percent(25.0)),
UiRect::all(Val::Percent(100.0)),
UiRect::all(Val::Percent(1000.0)),
UiRect::left(Val::Px(25.0)),
UiRect::right(Val::Px(25.0)),
UiRect::top(Val::Px(25.0)),
UiRect::bottom(Val::Px(25.0)),
UiRect::left(Val::Percent(25.0)),
UiRect::right(Val::Percent(25.0)),
UiRect::top(Val::Percent(25.0)),
UiRect::bottom(Val::Percent(25.0)),
UiRect::left(Val::Percent(1000.0)),
UiRect::vertical(Val::Percent(200.0)),
UiRect::vertical(Val::Px(200.0)),
UiRect::horizontal(Val::Px(200.0)),
UiRect::vertical(Val::Percent(200.0)),
];
for border in borders.into_iter().cycle().take(400) {
let b = commands.spawn(NodeBundle {
style: Style {
size: Size::all(Val::Px(50.)),
border,
margin: UiRect::all(Val::Px(5.)),
..Default::default()
},
background_color: BackgroundColor(Color::BLUE),
..Default::default()
}).id();
commands.entity(root).add_child(b);
}
} Draws the squares in a regular grid pattern, even with all the different border values. Am I missing something? |
oh this one is fine though:
|
Improved the examples a bit but they aren't great without the option to test them against a generated layout. As for borders, I'm not sure I understand how borders work. I had thought borders followed mostly the same rules as margins, except for having no automatic determination and being drawn. As the rendering isn't implemented, they aren't useful anyway at the moment, so should we just have a comment saying "not implemented yet, don't use"? Or even remove the field until the implementation is ready. |
IMO it ought to be removed entirely if borders aren't actually drawn. Looks like there's already an issue for actual border support #5924 |
I could implement basic solid coloured border support myself just quickly, but I'm not quite sure where to get the border geometry. edit: oh. that wouldn't work with percentages though. |
You go inwards from each edge by the border value (in CSS varies depending on the Percentage borders are not a thing on web (they are a taffy/bevy proprietary extension). They are resolved against the computed width of the parent node by analogy with padding/margin. |
Ah, I think I understand borders after hacking out this implementation. What I was missing is that the size of the node only needs to be expanded by the size of the border if there are constraints that prevent the layout algorithm from placing the border within the existing node boundary. |
EDIT: Nope. I tested this and it seems that nodes are always expanded to accommodate borders if necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very helpful.
bors r+
padding
and margin
behave with percentage valuespadding
and margin
behave with percentage values
…vyengine#7785) # Objective Add a comment explaining that percentage padding is calculated based on the width of the parent node.
# Objective Implement borders for UI nodes. Relevant discussion: #7785 Related: #5924, #3991 <img width="283" alt="borders" src="https://user-images.githubusercontent.com/27962798/220968899-7661d5ec-6f5b-4b0f-af29-bf9af02259b5.PNG"> ## Solution Add an extraction function to draw the borders. --- Can only do one colour rectangular borders due to the limitations of the Bevy UI renderer. Maybe it can be combined with #3991 eventually to add curved border support. ## Changelog * Added a component `BorderColor`. * Added the `extract_uinode_borders` system to the UI Render App. * Added the UI example `borders` --------- Co-authored-by: Nico Burns <nico@nicoburns.com>
Objective
Add a comment explaining that percentage padding is calculated based on the width of the parent node.