feat(ui): add group()/collapsing() section helpers
group() = always-open framed card with cyan heading. collapsing() = CollapsingHeader wrapper with stable id_salt. These eliminate the 11x boilerplate in the upcoming section rewrite.
This commit is contained in:
parent
77b1817f58
commit
d542d527f2
@ -4,6 +4,8 @@ pub mod preset;
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
|
||||
use crate::ui::style::ACCENT_CYAN;
|
||||
|
||||
/// One-shot egui styling. Registered in `EguiPrimaryContextPass` with a
|
||||
/// `Local<bool>` guard so it retries until `ctx_mut()` first succeeds, then
|
||||
/// runs exactly once. Per-frame set_style/set_visuals would dirty layout
|
||||
@ -21,6 +23,47 @@ pub fn setup_egui_style(
|
||||
}
|
||||
}
|
||||
|
||||
/// An always-open framed card. Title in cyan `RichText::strong().small()`.
|
||||
/// Used for the 4 most-tuned groups (Camera / Black Hole / Disk / Quality).
|
||||
fn group(ui: &mut egui::Ui, title: &str, body: impl FnOnce(&mut egui::Ui)) {
|
||||
egui::Frame::group(ui.style())
|
||||
.inner_margin(8.0)
|
||||
.corner_radius(6.0)
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
ui.visuals().window_stroke.color,
|
||||
))
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.label(
|
||||
egui::RichText::new(title)
|
||||
.strong()
|
||||
.small()
|
||||
.color(ACCENT_CYAN),
|
||||
);
|
||||
ui.add_space(2.0);
|
||||
body(ui);
|
||||
});
|
||||
}
|
||||
|
||||
/// A collapsible section (`default_open` controls initial state).
|
||||
/// Used for the 6 secondary groups. The body closure is only invoked when open.
|
||||
fn collapsing(
|
||||
ui: &mut egui::Ui,
|
||||
id: &str,
|
||||
title: &str,
|
||||
default_open: bool,
|
||||
body: impl FnOnce(&mut egui::Ui),
|
||||
) {
|
||||
egui::CollapsingHeader::new(title)
|
||||
.default_open(default_open)
|
||||
.id_salt(id)
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
body(ui);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn ui_system(
|
||||
mut contexts: bevy_egui::EguiContexts,
|
||||
mut params: ResMut<crate::params::BlackHoleParams>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user