-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Split UI Overflow
by axis
#8095
Changes from 7 commits
c3c44b7
2fa9401
8ef59f3
c72213f
2b1c527
8653609
8284671
2a3e129
131650d
8c65e33
648ac48
44c170f
cf840ce
4938380
cafed54
48ef027
e8d8fec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//! Simple example demonstrating overflow behavior. | ||
|
||
use bevy::{prelude::*, winit::WinitSettings}; | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
// Only run the app when there is user input. This will significantly reduce CPU/GPU use. | ||
.insert_resource(WinitSettings::desktop_app()) | ||
.add_startup_system(setup) | ||
.run(); | ||
} | ||
|
||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | ||
commands.spawn(Camera2dBundle::default()); | ||
|
||
let text_style = TextStyle { | ||
font: asset_server.load("fonts/FiraMono-Medium.ttf"), | ||
font_size: 20.0, | ||
color: Color::WHITE, | ||
}; | ||
|
||
commands | ||
.spawn(NodeBundle { | ||
style: Style { | ||
align_items: AlignItems::Center, | ||
justify_content: JustifyContent::Center, | ||
size: Size::width(Val::Percent(100.)), | ||
..Default::default() | ||
}, | ||
background_color: Color::BLACK.into(), | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
for overflow in [ | ||
Overflow::visible(), | ||
Overflow::x_hidden(), | ||
Overflow::y_hidden(), | ||
Overflow::hidden(), | ||
] { | ||
parent | ||
.spawn(NodeBundle { | ||
style: Style { | ||
flex_direction: FlexDirection::Column, | ||
align_items: AlignItems::Center, | ||
margin: UiRect::horizontal(Val::Px(25.)), | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
let label = format!("{overflow:#?}"); | ||
parent | ||
.spawn(NodeBundle { | ||
style: Style { | ||
padding: UiRect::all(Val::Px(10.)), | ||
margin: UiRect::bottom(Val::Px(25.)), | ||
..Default::default() | ||
}, | ||
background_color: Color::DARK_GRAY.into(), | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
parent.spawn(TextBundle { | ||
text: Text::from_section(label, text_style.clone()), | ||
..Default::default() | ||
}); | ||
}); | ||
parent | ||
.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::all(Val::Px(100.)), | ||
padding: UiRect { | ||
left: Val::Px(25.), | ||
top: Val::Px(25.), | ||
..Default::default() | ||
}, | ||
overflow, | ||
..Default::default() | ||
}, | ||
background_color: Color::GRAY.into(), | ||
..Default::default() | ||
}) | ||
.with_children(|parent| { | ||
parent.spawn(NodeBundle { | ||
style: Style { | ||
min_size: Size::all(Val::Px(100.)), | ||
..Default::default() | ||
}, | ||
background_color: Color::WHITE.into(), | ||
..Default::default() | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
flex_direction: FlexDirection::Column, | ||
align_self: AlignSelf::Stretch, | ||
size: Size::height(Val::Percent(50.)), | ||
overflow: Overflow::Hidden, | ||
overflow: Overflow::y_hidden(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I would maybe just use Ignore me (resolve this) as you wish. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking |
||
..default() | ||
}, | ||
background_color: Color::rgb(0.10, 0.10, 0.10).into(), | ||
|
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.
Nit: what do you think about switching the position to
(before, after)
as in #8147? For me at least it's a tiny bit easier to understand:(None, None)
=> noop(Some, None)
=> remove(None, Some)
=> add(Some, Some)
=> updateThere 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.
I was going to switch them because it's a good idea, I like semantic ordering etc, but then I realised that it's probably better to use nested
if let
statements as you avoid that which option is which ambiguity completely.