Skip to content

Commit 5e03b46

Browse files
committed
feat(workbench): add extensible settings panel with custom sections
1 parent 558dca5 commit 5e03b46

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ impl Plugin for WorkbenchPlugin {
185185
pub trait WorkbenchApp {
186186
/// Register a custom panel. The panel will be added to the dock layout.
187187
fn register_panel(&mut self, panel: impl dock::WorkbenchPanel) -> &mut Self;
188+
189+
/// Register a custom section in the built-in Settings panel.
190+
fn register_settings_section(&mut self, section: menu_bar::SettingsSection) -> &mut Self;
188191
}
189192

190193
impl WorkbenchApp for App {
@@ -196,6 +199,17 @@ impl WorkbenchApp for App {
196199
tile_state.add_panel(Box::new(panel));
197200
self
198201
}
202+
203+
fn register_settings_section(&mut self, section: menu_bar::SettingsSection) -> &mut Self {
204+
let mut tile_state = self
205+
.world_mut()
206+
.get_resource_mut::<dock::TileLayoutState>()
207+
.expect("WorkbenchPlugin must be added before registering settings sections");
208+
if let Some(panel) = tile_state.get_panel_mut::<menu_bar::SettingsPanel>("settings") {
209+
panel.custom_sections.push(section);
210+
}
211+
self
212+
}
199213
}
200214

201215
/// Assigns PrimaryEguiContext to the first active, window-targeting camera that

src/menu_bar.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ pub fn toolbar_system(
134134
}
135135

136136
/// Settings panel — displayed as a tab in the tile layout.
137+
/// A custom section to inject into the Settings panel.
138+
pub struct SettingsSection {
139+
/// Section heading.
140+
pub label: String,
141+
/// UI rendering callback.
142+
pub ui_fn: Box<dyn FnMut(&mut egui::Ui) + Send + Sync>,
143+
}
144+
137145
pub struct SettingsPanel {
138146
/// Edited scale value (not yet saved).
139147
pub edited_scale: f32,
@@ -151,6 +159,8 @@ pub struct SettingsPanel {
151159
pub edited_font_path: Option<String>,
152160
/// Set to true when user clicks Save.
153161
pub save_requested: bool,
162+
/// Custom settings sections injected by downstream applications.
163+
pub custom_sections: Vec<SettingsSection>,
154164
}
155165

156166
impl Default for SettingsPanel {
@@ -164,6 +174,7 @@ impl Default for SettingsPanel {
164174
edited_locale: crate::i18n::Locale::default(),
165175
edited_font_path: None,
166176
save_requested: false,
177+
custom_sections: Vec::new(),
167178
}
168179
}
169180
}
@@ -546,6 +557,13 @@ fn settings_panel_ui(panel: &mut SettingsPanel, ui: &mut egui::Ui) {
546557
if ui.button("Save").clicked() {
547558
panel.save_requested = true;
548559
}
560+
561+
// Custom settings sections
562+
for section in &mut panel.custom_sections {
563+
ui.separator();
564+
ui.heading(&section.label);
565+
(section.ui_fn)(ui);
566+
}
549567
}
550568

551569
/// Handles key recording for the keybindings panel, extracted to reduce nesting.

src/prelude.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ pub use crate::game_view::{
1515
pub use crate::i18n::{I18n, Locale};
1616
pub use crate::inspector::InspectorPanel;
1717
pub use crate::layout::{LayoutMode, LayoutState};
18-
pub use crate::menu_bar::{CustomMenu, MenuAction, MenuBarExtensions, MenuExtItem};
18+
pub use crate::menu_bar::{
19+
CustomMenu, MenuAction, MenuBarExtensions, MenuExtItem, SettingsSection,
20+
};
1921
pub use crate::mode::{EditorMode, GameClock, GameSchedule, ModeController, on_fresh_play};
2022
pub use crate::theme::{ThemeConfig, ThemePreset, ThemeState};
2123
pub use crate::undo::{UndoAction, UndoStack};

0 commit comments

Comments
 (0)