diff --git a/README.md b/README.md index 8a61764..9b95944 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ annotation-size-factor = 2 output-filename = "/tmp/test-%Y-%m-%d_%H:%M:%S.png" # After copying the screenshot, save it to a file as well save-after-copy = false +# Hide toolbars by default +default-hide-toolbars = false # custom colours for the colour palette [color-palette] @@ -98,7 +100,7 @@ Options: --fullscreen Start Satty in fullscreen mode --output-filename - Filename to use for saving action. Omit to disable saving to file. Might contain format specifiers: https://docs.rs/chrono/latest/chrono/format/strftime/index.html + Filename to use for saving action. Omit to disable saving to file. Might contain format specifiers: --early-exit Exit directly after copy/save action --initial-tool @@ -109,6 +111,8 @@ Options: Increase or decrease the size of the annotations --save-after-copy After copying the screenshot, save it to a file as well + -d, --default-hide-toolbars + Hide toolbars by default -h, --help Print help -V, --version diff --git a/config.toml b/config.toml index ccd6581..4c2f992 100644 --- a/config.toml +++ b/config.toml @@ -13,6 +13,8 @@ annotation-size-factor = 2 output-filename = "/tmp/test-%Y-%m-%d_%H:%M:%S.png" # After copying the screenshot, save it to a file as well save-after-copy = false +# Hide toolbars by default +dafault-hide-toolbars = false # custom colours for the colour palette [color-palette] diff --git a/src/command_line.rs b/src/command_line.rs index 319a230..b0f6300 100644 --- a/src/command_line.rs +++ b/src/command_line.rs @@ -39,6 +39,10 @@ pub struct CommandLine { /// After copying the screenshot, save it to a file as well #[arg(long)] pub save_after_copy: bool, + + /// Hide toolbars by default + #[arg(short, long)] + pub default_hide_toolbars: bool, } #[derive(Debug, Clone, Copy, Default, ValueEnum)] diff --git a/src/configuration.rs b/src/configuration.rs index 5a701b3..28f8f09 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -37,6 +37,7 @@ pub struct Configuration { annotation_size_factor: f64, save_after_copy: bool, color_palette: ColorPalette, + default_hide_toolbars: bool, } pub struct ColorPalette { @@ -142,6 +143,9 @@ impl Configuration { if let Some(v) = general.save_after_copy { self.save_after_copy = v; } + if let Some(v) = general.default_hide_toolbars { + self.default_hide_toolbars = v; + } } fn merge(&mut self, file: Option, command_line: CommandLine) { // input_filename is required and needs to be overwritten @@ -164,6 +168,9 @@ impl Configuration { if command_line.early_exit { self.early_exit = command_line.early_exit; } + if command_line.default_hide_toolbars { + self.default_hide_toolbars = command_line.default_hide_toolbars; + } if let Some(v) = command_line.initial_tool { self.initial_tool = v.into(); } @@ -216,6 +223,10 @@ impl Configuration { pub fn color_palette(&self) -> &ColorPalette { &self.color_palette } + + pub fn default_hide_toolbars(&self) -> bool { + self.default_hide_toolbars + } } impl Default for Configuration { @@ -230,6 +241,7 @@ impl Default for Configuration { annotation_size_factor: 1.0f64, save_after_copy: false, color_palette: ColorPalette::default(), + default_hide_toolbars: false, } } } @@ -264,6 +276,7 @@ struct ConfiguationFileGeneral { annotation_size_factor: Option, output_filename: Option, save_after_copy: Option, + default_hide_toolbars: Option, } #[derive(Deserialize)] diff --git a/src/main.rs b/src/main.rs index ea805ca..50fad0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use anyhow::{anyhow, Context, Result}; use sketch_board::SketchBoardOutput; use ui::toast::Toast; -use ui::toolbars::{StyleToolbar, ToolsToolbar}; +use ui::toolbars::{StyleToolbar, StyleToolbarInput, ToolsToolbar, ToolsToolbarInput}; mod command_line; mod configuration; @@ -39,6 +39,8 @@ struct App { #[derive(Debug)] enum AppInput { Realized, + ShowToast(String), + ToggleToolbarsDisplay, } #[derive(Debug)] @@ -173,6 +175,15 @@ impl Component for App { fn update(&mut self, message: Self::Input, sender: ComponentSender, root: &Self::Root) { match message { AppInput::Realized => self.resize_window_initial(root, sender), + AppInput::ShowToast(msg) => self.toast.emit(ui::toast::ToastMessage::Show(msg)), + AppInput::ToggleToolbarsDisplay => { + self.tools_toolbar + .sender() + .emit(ToolsToolbarInput::ToggleVisibility); + self.style_toolbar + .sender() + .emit(StyleToolbarInput::ToggleVisibility); + } } } @@ -203,8 +214,9 @@ impl Component for App { let sketch_board = SketchBoard::builder() .launch(image) - .forward(toast.sender(), |t| match t { - SketchBoardOutput::ShowToast(msg) => ui::toast::ToastMessage::Show(msg), + .forward(sender.input_sender(), |t| match t { + SketchBoardOutput::ShowToast(msg) => AppInput::ShowToast(msg), + SketchBoardOutput::ToggleToolbarsDisplay => AppInput::ToggleToolbarsDisplay, }); let sketch_board_sender = sketch_board.sender().clone(); diff --git a/src/sketch_board.rs b/src/sketch_board.rs index 6cd3654..ee1cbfd 100644 --- a/src/sketch_board.rs +++ b/src/sketch_board.rs @@ -30,6 +30,7 @@ pub enum SketchBoardInput { #[derive(Debug, Clone)] pub enum SketchBoardOutput { ShowToast(String), + ToggleToolbarsDisplay, } #[derive(Debug, Clone, Copy)] @@ -262,6 +263,17 @@ impl SketchBoard { } } + // Toolbars = Tools Toolbar + Style Toolbar + fn handle_toggle_toolbars_display( + &mut self, + sender: ComponentSender, + ) -> ToolUpdateResult { + sender + .output_sender() + .emit(SketchBoardOutput::ToggleToolbarsDisplay); + ToolUpdateResult::Unmodified + } + fn handle_toolbar_event( &mut self, toolbar_event: ToolbarEvent, @@ -405,6 +417,8 @@ impl Component for SketchBoard { self.handle_undo() } else if ke.key == Key::y && ke.modifier == ModifierType::CONTROL_MASK { self.handle_redo() + } else if ke.key == Key::t && ke.modifier == ModifierType::CONTROL_MASK { + self.handle_toggle_toolbars_display(sender) } else if ke.key == Key::s && ke.modifier == ModifierType::CONTROL_MASK { self.handle_save(sender); if APP_CONFIG.read().early_exit() { diff --git a/src/ui/toolbars.rs b/src/ui/toolbars.rs index 10afa9d..0dbf3c8 100644 --- a/src/ui/toolbars.rs +++ b/src/ui/toolbars.rs @@ -17,12 +17,15 @@ use relm4::{ prelude::*, }; -pub struct ToolsToolbar {} +pub struct ToolsToolbar { + visible: bool, +} pub struct StyleToolbar { custom_color: Color, custom_color_pixbuf: Pixbuf, color_action: SimpleAction, + visible: bool, } #[derive(Debug, Copy, Clone)] @@ -36,11 +39,17 @@ pub enum ToolbarEvent { CopyClipboard, } +#[derive(Debug, Copy, Clone)] +pub enum ToolsToolbarInput { + ToggleVisibility, +} + #[derive(Debug, Copy, Clone)] pub enum StyleToolbarInput { ColorButtonSelected(ColorButtons), ShowColorDialog, ColorDialogFinished(Option), + ToggleVisibility, } fn create_icon_pixbuf(color: Color) -> Pixbuf { @@ -55,7 +64,7 @@ fn create_icon(color: Color) -> gtk::Image { #[relm4::component(pub)] impl SimpleComponent for ToolsToolbar { type Init = (); - type Input = (); + type Input = ToolsToolbarInput; type Output = ToolbarEvent; view! { @@ -67,6 +76,9 @@ impl SimpleComponent for ToolsToolbar { add_css_class: "toolbar", add_css_class: "toolbar-top", + #[watch] + set_visible: model.visible, + gtk::Button { set_focusable: false, @@ -183,12 +195,22 @@ impl SimpleComponent for ToolsToolbar { }, } + fn update(&mut self, message: Self::Input, _sender: ComponentSender) { + match message { + ToolsToolbarInput::ToggleVisibility => { + self.visible = !self.visible; + } + } + } + fn init( _: Self::Init, root: &Self::Root, sender: ComponentSender, ) -> ComponentParts { - let model = ToolsToolbar {}; + let model = ToolsToolbar { + visible: !APP_CONFIG.read().default_hide_toolbars(), + }; let widgets = view_output!(); // Tools Action for selecting tools @@ -282,6 +304,9 @@ impl Component for StyleToolbar { add_css_class: "toolbar", add_css_class: "toolbar-bottom", + #[watch] + set_visible: model.visible, + gtk::ToggleButton { set_focusable: false, set_hexpand: false, @@ -398,6 +423,10 @@ impl Component for StyleToolbar { .output_sender() .emit(ToolbarEvent::ColorSelected(color)); } + + StyleToolbarInput::ToggleVisibility => { + self.visible = !self.visible; + } } } fn init( @@ -434,6 +463,7 @@ impl Component for StyleToolbar { custom_color, custom_color_pixbuf, color_action: SimpleAction::from(color_action.clone()), + visible: !APP_CONFIG.read().default_hide_toolbars(), }; // create widgets