Skip to content
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

many_buttons with bordered buttons #9004

Merged
merged 5 commits into from
Jul 5, 2023
Merged
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
31 changes: 27 additions & 4 deletions examples/stress_tests/many_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//! To start the demo without text run
//! `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
//! `cargo run --example many_buttons --release recompute-layout`
//!
Expand Down Expand Up @@ -87,22 +90,40 @@ fn setup(mut commands: Commands) {
})
.with_children(|commands| {
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 j in 0..count {
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(
commands: &mut ChildBuilder,
color: BackgroundColor,
background_color: BackgroundColor,
total: f32,
i: usize,
j: usize,
spawn_text: bool,
border: UiRect,
border_color: BorderColor,
) {
let width = 90.0 / total;
let mut builder = commands.spawn((
Expand All @@ -114,12 +135,14 @@ fn spawn_button(
left: Val::Percent(100.0 / total * j as f32),
align_items: AlignItems::Center,
position_type: PositionType::Absolute,
border,
..default()
},
background_color: color,
background_color,
border_color,
..default()
},
IdleColor(color),
IdleColor(background_color),
));

if spawn_text {
Expand Down