From e4115b3ffdf0201df64e338c1c72aecfe9cf8de5 Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 17 Jul 2026 16:03:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20add=20preset=5Fbar()=20=E2=80=94=20?= =?UTF-8?q?combobox=20+=20global=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Selecting a concrete preset applies its bundle and sets just_applied for one frame to suppress Custom-detection on that frame. Global '↺ all' reset (deviation from spec's per-section reset, flagged in plan for review). --- src/ui/mod.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 16e6174..d8e2d81 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -5,6 +5,7 @@ pub mod preset; use bevy::prelude::*; use bevy_egui::egui; +use crate::ui::preset::{Preset, apply, canonical_hash, params_hash}; use crate::ui::style::ACCENT_CYAN; /// One-shot egui styling. Registered in `EguiPrimaryContextPass` with a @@ -94,6 +95,44 @@ fn collapsing_with_toggle( }); } +/// The top preset bar. `current` is the UI-layer state (which preset is +/// shown as selected); `just_applied` is set for one frame after a preset +/// is chosen, to skip the Custom-detection hash compare on that frame +/// (applying a preset changes params; that change must not flip to Custom). +fn preset_bar( + ui: &mut egui::Ui, + params: &mut crate::params::BlackHoleParams, + current: &mut Preset, + just_applied: &mut bool, +) { + ui.horizontal(|ui| { + ui.label("Preset:"); + let prev = *current; + egui::ComboBox::from_id_salt("preset_combo") + .selected_text(format!("{:?}", prev)) + .show_ui(ui, |ui| { + ui.selectable_value(current, Preset::Cinematic, "Cinematic"); + ui.selectable_value(current, Preset::Performance, "Performance"); + ui.selectable_value(current, Preset::Web, "Web"); + ui.selectable_value(current, Preset::Custom, "Custom"); + }); + if *current != prev && *current != Preset::Custom { + // User picked a concrete preset → apply its bundle. + apply(*current, params); + *just_applied = true; + } + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + // Global reset-to-default for all params. + if ui.button("↺ all").clicked() { + *params = crate::params::BlackHoleParams::default(); + *current = Preset::Custom; + *just_applied = true; + } + }); + }); + ui.separator(); +} + pub fn ui_system( mut contexts: bevy_egui::EguiContexts, mut params: ResMut,