mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
many_buttons
with bordered buttons (#9004)
# Objective Adds a border to each button. The borders can be disabled with the "no-borders" command line argument.
This commit is contained in:
parent
ee82eec2b3
commit
a3ab507cd4
1 changed files with 27 additions and 4 deletions
|
@ -3,6 +3,9 @@
|
||||||
//! To start the demo without text run
|
//! To start the demo without text run
|
||||||
//! `cargo run --example many_buttons --release no-text`
|
//! `cargo run --example many_buttons --release no-text`
|
||||||
//!
|
//!
|
||||||
|
//! //! To start the demo without borders run
|
||||||
|
//! `cargo run --example many_buttons --release no-borders`
|
||||||
|
//!
|
||||||
//| To do a full layout update each frame run
|
//| To do a full layout update each frame run
|
||||||
//! `cargo run --example many_buttons --release recompute-layout`
|
//! `cargo run --example many_buttons --release recompute-layout`
|
||||||
//!
|
//!
|
||||||
|
@ -87,22 +90,40 @@ fn setup(mut commands: Commands) {
|
||||||
})
|
})
|
||||||
.with_children(|commands| {
|
.with_children(|commands| {
|
||||||
let spawn_text = std::env::args().all(|arg| arg != "no-text");
|
let spawn_text = std::env::args().all(|arg| arg != "no-text");
|
||||||
|
let border = if std::env::args().all(|arg| arg != "no-borders") {
|
||||||
|
UiRect::all(Val::Percent(10. / count_f))
|
||||||
|
} else {
|
||||||
|
UiRect::DEFAULT
|
||||||
|
};
|
||||||
for i in 0..count {
|
for i in 0..count {
|
||||||
for j in 0..count {
|
for j in 0..count {
|
||||||
let color = as_rainbow(j % i.max(1)).into();
|
let color = as_rainbow(j % i.max(1)).into();
|
||||||
spawn_button(commands, color, count_f, i, j, spawn_text);
|
let border_color = as_rainbow(i % j.max(1)).into();
|
||||||
|
spawn_button(
|
||||||
|
commands,
|
||||||
|
color,
|
||||||
|
count_f,
|
||||||
|
i,
|
||||||
|
j,
|
||||||
|
spawn_text,
|
||||||
|
border,
|
||||||
|
border_color,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn spawn_button(
|
fn spawn_button(
|
||||||
commands: &mut ChildBuilder,
|
commands: &mut ChildBuilder,
|
||||||
color: BackgroundColor,
|
background_color: BackgroundColor,
|
||||||
total: f32,
|
total: f32,
|
||||||
i: usize,
|
i: usize,
|
||||||
j: usize,
|
j: usize,
|
||||||
spawn_text: bool,
|
spawn_text: bool,
|
||||||
|
border: UiRect,
|
||||||
|
border_color: BorderColor,
|
||||||
) {
|
) {
|
||||||
let width = 90.0 / total;
|
let width = 90.0 / total;
|
||||||
let mut builder = commands.spawn((
|
let mut builder = commands.spawn((
|
||||||
|
@ -114,12 +135,14 @@ fn spawn_button(
|
||||||
left: Val::Percent(100.0 / total * j as f32),
|
left: Val::Percent(100.0 / total * j as f32),
|
||||||
align_items: AlignItems::Center,
|
align_items: AlignItems::Center,
|
||||||
position_type: PositionType::Absolute,
|
position_type: PositionType::Absolute,
|
||||||
|
border,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
background_color: color,
|
background_color,
|
||||||
|
border_color,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
IdleColor(color),
|
IdleColor(background_color),
|
||||||
));
|
));
|
||||||
|
|
||||||
if spawn_text {
|
if spawn_text {
|
||||||
|
|
Loading…
Reference in a new issue