Module settings_editor

Module settings_editor 

Source
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::handle is called when the user makes a selection. Implement handle on your struct to mutate context.settings and return the updated display string.
  • Text-input settings: Implement InputSettingKind and its apply_text method. The overlay and submission flow are handled by SettingValue.

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§

CategoryButton
A single category button that renders itself with background and text.
CategoryEditor
A view for editing category-specific settings.
CategoryNavigationBar
Horizontal navigation bar displaying category tabs.
SettingRow
A row in the settings UI that displays a setting label and its corresponding value.
SettingValue
Represents a single setting value display in the settings UI.
SettingsCategoryProvider
Navigation provider for settings categories.
SettingsEditor
Main settings editor view.
SettingsEditorBottomBar
Reusable bottom bar component for settings editor views

Enums§

BottomBarVariant
Defines the layout variant for the settings editor bottom bar
Category
Categories of settings available in the settings editor.
SettingsEvent