From dfa8c77ab10c529312677c27b0df2aa27e8e099c Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 17 Jul 2026 15:44:59 +0800 Subject: [PATCH] feat(ui): add collapsing_with_toggle() for header-row enables Doppler/Jets/Grid/Planets get their enable checkbox in the collapsing header (not a body row). Uses CollapsingState::show_header. Body closure receives the enabled flag so it can add_enabled() its rows. --- src/ui/mod.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/ui/mod.rs b/src/ui/mod.rs index d0e0733..3cfd6b6 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -64,6 +64,35 @@ fn collapsing( }); } +/// Collapsible section whose header hosts an enable toggle on the right. +/// Used by Doppler / Jets / Grid / Planets (design ยง4.1). The body closure +/// receives the current `enabled` state so it can `add_enabled` its rows. +/// +/// State persistence is handled by `HeaderResponse::body`, which calls +/// `CollapsingState::store` internally via `show_body_indented` (see egui +/// 0.35 `containers/collapsing_header.rs`). `show_header` consumes the +/// state, so there is no separate `store` call here. +fn collapsing_with_toggle( + ui: &mut egui::Ui, + id: &str, + title: &str, + default_open: bool, + enabled: &mut bool, + body: impl FnOnce(&mut egui::Ui, bool), +) { + let id = ui.make_persistent_id(id); + let state = + egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, default_open); + state + .show_header(ui, |ui| { + ui.checkbox(enabled, title); + }) + .body(|ui| { + ui.set_width(ui.available_width()); + body(ui, *enabled); + }); +} + pub fn ui_system( mut contexts: bevy_egui::EguiContexts, mut params: ResMut,