Expand description
Settings editor module for managing application configuration.
This module provides a hierarchical settings interface with the following structure:
SettingsEditor (Main view)
├── TopBar (Back button, "Settings" title)
├── StackNavigationBar (Category tabs: General | Libraries | Intermissions)
└── CategoryEditor (Embedded, shows settings for selected category)
├── SettingRow (One for each setting in the category)
│ ├── Label (Setting name)
│ └── SettingValue (Current value, can be tapped to edit)
└── BottomBar (Add Library button for Libraries category)§Components
- SettingsEditor: Top-level view with navigation bar and category editor
- CategoryNavigationBar: Horizontal bar with category tabs
- CategoryEditor: Embedded editor for a specific category’s settings
- SettingRow: Individual setting with label and value
- SettingValue: Interactive value display that opens editors/menus
- LibraryEditor: Specialized editor for library settings
§Event Flow
When a setting is modified, the CategoryEditor directly updates context.settings,
providing immediate feedback. Settings are persisted to disk when the settings editor
is closed.
§Adding a new setting
Each setting is a small self-contained struct that implements SettingKind.
The trait carries everything the UI needs.
§1. Add a variant to SettingIdentity
Open kinds/identity.rs and add a variant for the new setting:
pub enum SettingIdentity {
// ... existing variants
MyNewSetting,
}§2. Implement SettingKind
Add a struct in the appropriate kinds/*.rs file and implement the trait:
// This example uses hypothetical types (MyNewSetting, EntryId::EditMyNewSetting)
// that do not exist in the codebase — it illustrates the pattern to follow.
pub struct MyNewSetting;
impl SettingKind for MyNewSetting {
fn identity(&self) -> SettingIdentity {
SettingIdentity::MyNewSetting
}
fn label(&self, _settings: &Settings) -> String {
"My New Setting".to_string()
}
fn fetch(&self, settings: &Settings) -> SettingData {
SettingData {
value: settings.my_new_setting.to_string(),
widget: WidgetKind::ActionLabel(Event::Select(EntryId::EditMyNewSetting)),
}
}
}For a toggle widget, use WidgetKind::Toggle { ..., tap_event } where
tap_event is Event::Toggle(ToggleEvent::Setting(ToggleSettings::MyNewSetting))
(adding the corresponding ToggleSettings variant in kinds/mod.rs).
For a sub-menu (radio buttons), use WidgetKind::SubMenu(entries) where
entries is a Vec<EntryKind> — the sub-menu
event is built automatically from the entries when the row is tapped.
§3. Register the setting in Category::settings()
Open category.rs and add the new kind to the relevant category arm:
// This example shows a match arm inside Category::settings() — it is a
// partial snippet and cannot compile standalone.
Category::General => vec![
// ... existing kinds
Box::new(MyNewSetting),
],§4. Handle mutations (usually automatic)
Most settings do not require any changes to CategoryEditor. The framework
handles mutations automatically:
- Sub-menu / toggle / file-chooser settings:
SettingKind::handleis called when the user makes a selection. Implementhandleon your struct to mutatecontext.settingsand return the updated display string. - Text-input settings: Implement
InputSettingKindand itsapply_textmethod. The overlay and submission flow are handled bySettingValue.
A CategoryEditor handler is only needed for settings with custom event flows
not covered by the traits above — for example, library management actions that
must coordinate multiple views or emit side-effect events. In that case, add a
handler method in category_editor.rs and dispatch it from handle_event. After
mutating context.settings, send SettingsEvent::UpdateValue so the corresponding
SettingValue view refreshes its displayed text:
// This example shows a method inside a CategoryEditor impl block — it is a
// partial snippet and cannot compile standalone.
fn handle_my_new_setting(&mut self, value: f32, hub: &Hub, context: &mut Context) -> bool {
context.settings.my_new_setting = value;
hub.send(Event::Settings(SettingsEvent::UpdateValue {
kind: SettingIdentity::MyNewSetting,
value: value.to_string(),
}))
.ok();
true
}Re-exports§
pub use setting_value::ToggleSettings;pub use self::kinds::InputSettingKind;pub use self::kinds::SettingIdentity;pub use self::kinds::SettingKind;
Modules§
- bottom_
bar 🔒 - category 🔒
- category_
button 🔒 - category_
editor 🔒 - category_
navigation_ 🔒bar - category_
provider 🔒 - kinds
- Trait and supporting types for defining individual settings.
- library_
editor 🔒 - setting_
row 🔒 - setting_
value 🔒
Structs§
- Category
Button - A single category button that renders itself with background and text.
- Category
Editor - A view for editing category-specific settings.
- Category
Navigation Bar - Horizontal navigation bar displaying category tabs.
- Setting
Row - A row in the settings UI that displays a setting label and its corresponding value.
- Setting
Value - Represents a single setting value display in the settings UI.
- Settings
Category Provider - Navigation provider for settings categories.
- Settings
Editor - Main settings editor view.
- Settings
Editor Bottom Bar - Reusable bottom bar component for settings editor views
Enums§
- Bottom
BarVariant - Defines the layout variant for the settings editor bottom bar
- Category
- Categories of settings available in the settings editor.
- Settings
Event