From 57394753e67c0f0ecd87c33c01d8b393cf3d39f5 Mon Sep 17 00:00:00 2001 From: devmobasa <4170275+devmobasa@users.noreply.github.com> Date: Mon, 29 Dec 2025 14:31:55 +0100 Subject: [PATCH] Split keybindings into tabs --- configurator/src/app.rs | 36 ++++++++-- configurator/src/messages.rs | 3 +- configurator/src/models/keybindings.rs | 97 ++++++++++++++++++++++++++ configurator/src/models/mod.rs | 2 +- configurator/src/models/tab.rs | 38 ++++++++++ 5 files changed, 170 insertions(+), 6 deletions(-) diff --git a/configurator/src/app.rs b/configurator/src/app.rs index 4d5aad29..fdfdfbea 100644 --- a/configurator/src/app.rs +++ b/configurator/src/app.rs @@ -15,8 +15,8 @@ use wayscriber::config::{Config, PRESET_SLOTS_MAX, PRESET_SLOTS_MIN}; use crate::messages::Message; use crate::models::{ BoardModeOption, ColorMode, ColorQuadInput, ColorTripletInput, ConfigDraft, EraserModeOption, - FontStyleOption, FontWeightOption, NamedColorOption, OverrideOption, PresetEraserKindOption, - PresetEraserModeOption, PresetTextField, PresetToggleField, QuadField, + FontStyleOption, FontWeightOption, KeybindingsTabId, NamedColorOption, OverrideOption, + PresetEraserKindOption, PresetEraserModeOption, PresetTextField, PresetToggleField, QuadField, SessionCompressionOption, SessionStorageModeOption, StatusPositionOption, TabId, TextField, ToggleField, ToolOption, ToolbarLayoutModeOption, ToolbarOverrideField, TripletField, UiTabId, }; @@ -59,6 +59,7 @@ pub struct ConfiguratorApp { status: StatusMessage, active_tab: TabId, active_ui_tab: UiTabId, + active_keybindings_tab: KeybindingsTabId, override_mode: ToolbarLayoutModeOption, is_loading: bool, is_saving: bool, @@ -115,6 +116,7 @@ impl Application for ConfiguratorApp { status: StatusMessage::info("Loading configuration..."), active_tab: TabId::Drawing, active_ui_tab: UiTabId::Toolbar, + active_keybindings_tab: KeybindingsTabId::General, override_mode, is_loading: true, is_saving: false, @@ -226,6 +228,9 @@ impl Application for ConfiguratorApp { Message::UiTabSelected(tab) => { self.active_ui_tab = tab; } + Message::KeybindingsTabSelected(tab) => { + self.active_keybindings_tab = tab; + } Message::ToggleChanged(field, value) => { self.status = StatusMessage::idle(); self.draft.set_toggle(field, value); @@ -1975,11 +1980,34 @@ impl ConfiguratorApp { } fn keybindings_tab(&self) -> Element<'_, Message> { + let tab_bar = KeybindingsTabId::ALL.iter().fold( + Row::new().spacing(8).align_items(iced::Alignment::Center), + |row, tab| { + let label = tab.title(); + let button = button(label) + .padding([6, 12]) + .style(if *tab == self.active_keybindings_tab { + theme::Button::Primary + } else { + theme::Button::Secondary + }) + .on_press(Message::KeybindingsTabSelected(*tab)); + row.push(button) + }, + ); + let mut column = Column::new() .spacing(8) - .push(text("Keybindings (comma-separated)").size(20)); + .push(text("Keybindings (comma-separated)").size(20)) + .push(tab_bar); - for entry in &self.draft.keybindings.entries { + for entry in self + .draft + .keybindings + .entries + .iter() + .filter(|entry| entry.field.tab() == self.active_keybindings_tab) + { let default_value = self .defaults .keybindings diff --git a/configurator/src/messages.rs b/configurator/src/messages.rs index 869ebf6e..2536fecb 100644 --- a/configurator/src/messages.rs +++ b/configurator/src/messages.rs @@ -5,7 +5,7 @@ use wayscriber::config::Config; use crate::models::{ BoardModeOption, ColorMode, EraserModeOption, FontStyleOption, FontWeightOption, - KeybindingField, NamedColorOption, OverrideOption, PresetEraserKindOption, + KeybindingField, KeybindingsTabId, NamedColorOption, OverrideOption, PresetEraserKindOption, PresetEraserModeOption, PresetTextField, PresetToggleField, QuadField, SessionCompressionOption, SessionStorageModeOption, StatusPositionOption, TabId, TextField, ToggleField, ToolOption, ToolbarLayoutModeOption, ToolbarOverrideField, TripletField, UiTabId, @@ -20,6 +20,7 @@ pub enum Message { ConfigSaved(Result<(Option, Arc), String>), TabSelected(TabId), UiTabSelected(UiTabId), + KeybindingsTabSelected(KeybindingsTabId), ToggleChanged(ToggleField, bool), TextChanged(TextField, String), TripletChanged(TripletField, usize, String), diff --git a/configurator/src/models/keybindings.rs b/configurator/src/models/keybindings.rs index e34d0a4c..6f96ca32 100644 --- a/configurator/src/models/keybindings.rs +++ b/configurator/src/models/keybindings.rs @@ -1,5 +1,6 @@ use wayscriber::config::keybindings::KeybindingsConfig; +use super::KeybindingsTabId; use super::error::FormError; #[derive(Debug, Clone, PartialEq)] @@ -448,6 +449,102 @@ impl KeybindingField { } } + pub fn tab(&self) -> KeybindingsTabId { + match self { + Self::Exit | Self::OpenConfigurator => KeybindingsTabId::General, + Self::EnterTextMode + | Self::EnterStickyNoteMode + | Self::ClearCanvas + | Self::IncreaseThickness + | Self::DecreaseThickness + | Self::IncreaseMarkerOpacity + | Self::DecreaseMarkerOpacity + | Self::IncreaseFontSize + | Self::DecreaseFontSize + | Self::ToggleFill + | Self::SetColorRed + | Self::SetColorGreen + | Self::SetColorBlue + | Self::SetColorYellow + | Self::SetColorOrange + | Self::SetColorPink + | Self::SetColorWhite + | Self::SetColorBlack => KeybindingsTabId::Drawing, + Self::SelectPenTool + | Self::SelectEraserTool + | Self::ToggleEraserMode + | Self::SelectMarkerTool + | Self::SelectLineTool + | Self::SelectRectTool + | Self::SelectEllipseTool + | Self::SelectArrowTool + | Self::SelectHighlightTool + | Self::ToggleHighlightTool => KeybindingsTabId::Tools, + Self::DuplicateSelection + | Self::CopySelection + | Self::PasteSelection + | Self::SelectAll + | Self::MoveSelectionToFront + | Self::MoveSelectionToBack + | Self::MoveSelectionToStart + | Self::MoveSelectionToEnd + | Self::MoveSelectionToTop + | Self::MoveSelectionToBottom + | Self::NudgeSelectionUp + | Self::NudgeSelectionDown + | Self::NudgeSelectionLeft + | Self::NudgeSelectionRight + | Self::NudgeSelectionUpLarge + | Self::NudgeSelectionDownLarge + | Self::DeleteSelection => KeybindingsTabId::Selection, + Self::Undo + | Self::Redo + | Self::UndoAll + | Self::RedoAll + | Self::UndoAllDelayed + | Self::RedoAllDelayed => KeybindingsTabId::History, + Self::ToggleWhiteboard + | Self::ToggleBlackboard + | Self::ReturnToTransparent + | Self::ToggleHelp + | Self::ToggleStatusBar + | Self::ToggleClickHighlight + | Self::ToggleToolbar + | Self::OpenContextMenu => KeybindingsTabId::UiModes, + Self::CaptureFullScreen + | Self::CaptureActiveWindow + | Self::CaptureSelection + | Self::CaptureClipboardFull + | Self::CaptureFileFull + | Self::CaptureClipboardSelection + | Self::CaptureFileSelection + | Self::CaptureClipboardRegion + | Self::CaptureFileRegion + | Self::OpenCaptureFolder + | Self::ToggleFrozenMode + | Self::ZoomIn + | Self::ZoomOut + | Self::ResetZoom + | Self::ToggleZoomLock + | Self::RefreshZoomCapture => KeybindingsTabId::CaptureView, + Self::ApplyPreset1 + | Self::ApplyPreset2 + | Self::ApplyPreset3 + | Self::ApplyPreset4 + | Self::ApplyPreset5 + | Self::SavePreset1 + | Self::SavePreset2 + | Self::SavePreset3 + | Self::SavePreset4 + | Self::SavePreset5 + | Self::ClearPreset1 + | Self::ClearPreset2 + | Self::ClearPreset3 + | Self::ClearPreset4 + | Self::ClearPreset5 => KeybindingsTabId::Presets, + } + } + fn get<'a>(&self, config: &'a KeybindingsConfig) -> &'a Vec { match self { Self::Exit => &config.exit, diff --git a/configurator/src/models/mod.rs b/configurator/src/models/mod.rs index 7ff91043..2572efe9 100644 --- a/configurator/src/models/mod.rs +++ b/configurator/src/models/mod.rs @@ -15,4 +15,4 @@ pub use fields::{ ToggleField, ToolOption, ToolbarLayoutModeOption, ToolbarOverrideField, TripletField, }; pub use keybindings::KeybindingField; -pub use tab::{TabId, UiTabId}; +pub use tab::{KeybindingsTabId, TabId, UiTabId}; diff --git a/configurator/src/models/tab.rs b/configurator/src/models/tab.rs index 8d479611..58868971 100644 --- a/configurator/src/models/tab.rs +++ b/configurator/src/models/tab.rs @@ -70,3 +70,41 @@ impl UiTabId { } } } + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum KeybindingsTabId { + General, + Drawing, + Tools, + Selection, + History, + UiModes, + CaptureView, + Presets, +} + +impl KeybindingsTabId { + pub const ALL: [KeybindingsTabId; 8] = [ + KeybindingsTabId::General, + KeybindingsTabId::Drawing, + KeybindingsTabId::Tools, + KeybindingsTabId::Selection, + KeybindingsTabId::History, + KeybindingsTabId::UiModes, + KeybindingsTabId::CaptureView, + KeybindingsTabId::Presets, + ]; + + pub fn title(&self) -> &'static str { + match self { + KeybindingsTabId::General => "General", + KeybindingsTabId::Drawing => "Drawing", + KeybindingsTabId::Tools => "Tools", + KeybindingsTabId::Selection => "Selection", + KeybindingsTabId::History => "History", + KeybindingsTabId::UiModes => "UI & Modes", + KeybindingsTabId::CaptureView => "Capture & View", + KeybindingsTabId::Presets => "Presets", + } + } +}