Skip to content

Commit

Permalink
add an option to fill shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekpoz committed Jul 13, 2024
1 parent 617dc14 commit 4f9b02e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions icons.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ icons = [
"crop-filled",
"arrow-up-right-filled",
"rectangle-landscape-regular",
"paint-bucket-filled",
"paint-bucket-regular",
]
6 changes: 6 additions & 0 deletions src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
},
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

use femtovg::Paint;
use femtovg::{Paint};
use gdk_pixbuf::{
glib::{Variant, VariantTy},
prelude::{StaticVariantType, ToVariant},
Expand All @@ -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)]
Expand Down
6 changes: 5 additions & 1 deletion src/tools/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
16 changes: 16 additions & 0 deletions src/ui/toolbars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum ToolbarEvent {
Undo,
SaveFile,
CopyClipboard,
ToggleFill,
}

#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -398,7 +399,22 @@ impl Component for StyleToolbar {
set_tooltip: "Large size",
ActionablePlus::set_action::<SizeAction>: 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);
},
},
},
}

Expand Down

0 comments on commit 4f9b02e

Please sign in to comment.