feat(ui): add preset_bar() — combobox + global reset

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).
This commit is contained in:
xfy 2026-07-17 16:03:20 +08:00
parent 1f90c790d3
commit e4115b3ffd

View File

@ -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<crate::params::BlackHoleParams>,