Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/picking/dragdrop_picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn setup(
commands
.spawn((
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Start,
..default()
Expand Down
12 changes: 3 additions & 9 deletions examples/ui/flex_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
height: percent(100),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
padding: UiRect::all(MARGIN),
padding: MARGIN.all(),
row_gap: MARGIN,
..Default::default()
},
Expand All @@ -47,7 +47,7 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
builder,
font.clone(),
ALIGN_ITEMS_COLOR,
UiRect::right(MARGIN),
MARGIN.right(),
"AlignItems",
);
spawn_nested_text_bundle(
Expand Down Expand Up @@ -133,13 +133,7 @@ fn spawn_child_node(
];
for (text, color, top_margin) in labels {
// We nest the text within a parent node because margins and padding can't be directly applied to text nodes currently.
spawn_nested_text_bundle(
builder,
font.clone(),
color,
UiRect::top(px(top_margin)),
&text,
);
spawn_nested_text_bundle(builder, font.clone(), color, px(top_margin).top(), &text);
}
});
}
Expand Down
36 changes: 16 additions & 20 deletions examples/ui/image_node_resizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
TextColor::BLACK,
Node {
grid_row: GridPlacement::span(1),
padding: UiRect::all(px(6)),
padding: px(6).all(),
..default()
},
UiDebugOptions {
Expand All @@ -110,7 +110,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
grid_row: GridPlacement::span(1),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::SpaceAround,
padding: UiRect::all(Val::Px(10.)),
padding: px(10.).all(),
..default()
},
BackgroundColor(Color::BLACK),
Expand All @@ -124,8 +124,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Node {
display: Display::Flex,
justify_content: JustifyContent::Start,
width: Val::Percent(IMAGE_GROUP_BOX_INIT_WIDTH),
height: Val::Percent(IMAGE_GROUP_BOX_INIT_HEIGHT),
width: percent(IMAGE_GROUP_BOX_INIT_WIDTH),
height: percent(IMAGE_GROUP_BOX_INIT_HEIGHT),
..default()
},
BackgroundColor(Color::from(tailwind::BLUE_100)),
Expand All @@ -150,8 +150,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Node {
display: Display::Flex,
justify_content: JustifyContent::Start,
width: Val::Percent(IMAGE_GROUP_BOX_INIT_WIDTH),
height: Val::Percent(IMAGE_GROUP_BOX_INIT_HEIGHT),
width: percent(IMAGE_GROUP_BOX_INIT_WIDTH),
height: percent(IMAGE_GROUP_BOX_INIT_HEIGHT),
..default()
},
BackgroundColor(Color::from(tailwind::BLUE_100)),
Expand All @@ -160,8 +160,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
for width in [10., 20., 30., 40.] {
parent.spawn((
Node {
height: Val::Percent(100.),
width: Val::Percent(width),
height: percent(100),
width: percent(width),
..default()
},
ImageNode {
Expand Down Expand Up @@ -247,27 +247,23 @@ fn on_trigger_image_group(event: On<ImageGroupResize>, query: Query<&mut Node, W
for mut node in query {
match event.event() {
ImageGroupResize::HeightGrow => {
if let Val::Percent(val) = node.height {
let new_val = (val + MIN_RESIZE_VAL).min(IMAGE_GROUP_BOX_MAX_HEIGHT);
node.height = Val::Percent(new_val);
if let Val::Percent(val) = &mut node.height {
*val = (*val + MIN_RESIZE_VAL).min(IMAGE_GROUP_BOX_MAX_HEIGHT);
}
}
ImageGroupResize::HeightShrink => {
if let Val::Percent(val) = node.height {
let new_val = (val - MIN_RESIZE_VAL).max(IMAGE_GROUP_BOX_MIN_HEIGHT);
node.height = Val::Percent(new_val);
if let Val::Percent(val) = &mut node.height {
*val = (*val - MIN_RESIZE_VAL).max(IMAGE_GROUP_BOX_MIN_HEIGHT);
}
}
ImageGroupResize::WidthGrow => {
if let Val::Percent(val) = node.width {
let new_val = (val + MIN_RESIZE_VAL).min(IMAGE_GROUP_BOX_MAX_WIDTH);
node.width = Val::Percent(new_val);
if let Val::Percent(val) = &mut node.width {
*val = (*val + MIN_RESIZE_VAL).min(IMAGE_GROUP_BOX_MAX_WIDTH);
}
}
ImageGroupResize::WidthShrink => {
if let Val::Percent(val) = node.width {
let new_val = (val - MIN_RESIZE_VAL).max(IMAGE_GROUP_BOX_MIN_WIDTH);
node.width = Val::Percent(new_val);
if let Val::Percent(val) = &mut node.width {
*val = (*val - MIN_RESIZE_VAL).max(IMAGE_GROUP_BOX_MIN_WIDTH);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/standard_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ fn spawn_menu(anchor: Entity, assets: Res<AssetServer>, mut commands: Commands)
display: Display::Flex,
flex_direction: FlexDirection::Column,
min_height: px(10.),
min_width: Val::Percent(100.),
min_width: percent(100),
border: UiRect::all(px(1)),
position_type: PositionType::Absolute,
..default()
Expand Down
4 changes: 2 additions & 2 deletions examples/ui/strikethrough_and_underline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((
Node {
flex_direction: FlexDirection::Column,
width: Val::Percent(100.),
height: Val::Percent(100.),
width: percent(100),
height: percent(100),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..Default::default()
Expand Down
8 changes: 4 additions & 4 deletions examples/ui/ui_drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ fn setup(mut commands: Commands) {
parent
.spawn((
Node {
width: Val::Px(TILE_SIZE),
height: Val::Px(TILE_SIZE),
border: UiRect::all(Val::Px(4.)),
width: px(TILE_SIZE),
height: px(TILE_SIZE),
border: px(4.).all(),
grid_row: GridPlacement::start(row + 1),
grid_column: GridPlacement::start(column + 1),
align_items: AlignItems::Center,
Expand All @@ -47,7 +47,7 @@ fn setup(mut commands: Commands) {
BorderColor::all(tile_border_color),
BackgroundColor(tile_color),
Outline {
width: Val::Px(2.),
width: px(2.),
offset: Val::ZERO,
color: Color::NONE,
},
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/ui_texture_atlas_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn setup(
justify_content: JustifyContent::Center,
// vertically center child text
align_items: AlignItems::Center,
margin: UiRect::all(px(20)),
margin: px(20).all(),
..default()
},
))
Expand Down