diff --git a/icons.toml b/icons.toml index b705806..f35f5e2 100644 --- a/icons.toml +++ b/icons.toml @@ -17,4 +17,6 @@ icons = [ "crop-filled", "arrow-up-right-filled", "rectangle-landscape-regular", + "paint-bucket-filled", + "paint-bucket-regular", ] diff --git a/src/sketch_board.rs b/src/sketch_board.rs index 437d224..f4330f4 100644 --- a/src/sketch_board.rs +++ b/src/sketch_board.rs @@ -348,6 +348,12 @@ impl SketchBoard { } ToolbarEvent::Undo => self.handle_undo(), ToolbarEvent::Redo => self.handle_redo(), + ToolbarEvent::ToggleFill => { + self.style.fill = !self.style.fill; + self.active_tool + .borrow_mut() + .handle_event(ToolEvent::StyleChanged(self.style)) + }, } } } diff --git a/src/style.rs b/src/style.rs index 1dcc045..017b4b4 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use femtovg::Paint; +use femtovg::{Paint}; use gdk_pixbuf::{ glib::{Variant, VariantTy}, prelude::{StaticVariantType, ToVariant}, @@ -15,6 +15,7 @@ use crate::configuration::APP_CONFIG; pub struct Style { pub color: Color, pub size: Size, + pub fill: bool, } #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] diff --git a/src/tools/rectangle.rs b/src/tools/rectangle.rs index 3928893..ed6fc93 100644 --- a/src/tools/rectangle.rs +++ b/src/tools/rectangle.rs @@ -32,7 +32,11 @@ impl Drawable for Rectangle { let mut path = Path::new(); path.rect(self.top_left.x, self.top_left.y, size.x, size.y); - canvas.stroke_path(&path, &self.style.into()); + if self.style.fill { + canvas.fill_path(&path, &self.style.into()); + } else { + canvas.stroke_path(&path, &self.style.into()); + } canvas.restore(); Ok(()) diff --git a/src/ui/toolbars.rs b/src/ui/toolbars.rs index 2d22e72..722c19a 100644 --- a/src/ui/toolbars.rs +++ b/src/ui/toolbars.rs @@ -37,6 +37,7 @@ pub enum ToolbarEvent { Undo, SaveFile, CopyClipboard, + ToggleFill, } #[derive(Debug, Copy, Clone)] @@ -398,7 +399,22 @@ impl Component for StyleToolbar { set_tooltip: "Large size", ActionablePlus::set_action::: Size::Large, }, + gtk::Button { + set_focusable: false, + set_hexpand: false, + set_icon_name: "paint-bucket-regular", + set_tooltip: "Fill shape", + connect_clicked[sender] => move |button| { + sender.output_sender().emit(ToolbarEvent::ToggleFill); + let new_icon = if button.icon_name() == Some("paint-bucket-regular".into()) { + "paint-bucket-filled" + } else { + "paint-bucket-regular" + }; + button.set_icon_name(new_icon); + }, + }, }, }