diff --git a/icons.toml b/icons.toml index bfa8381..31cd238 100644 --- a/icons.toml +++ b/icons.toml @@ -18,4 +18,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..224695d 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..a0203b5 100644 --- a/src/style.rs +++ b/src/style.rs @@ -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/ellipse.rs b/src/tools/ellipse.rs index dfac064..2c818c4 100644 --- a/src/tools/ellipse.rs +++ b/src/tools/ellipse.rs @@ -32,7 +32,11 @@ impl Drawable for Ellipse { let mut path = Path::new(); path.ellipse(self.middle.x, self.middle.y, radii.x, radii.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/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 0cbbc17..ea87a8b 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)] @@ -406,7 +407,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); + }, + }, }, }