Skip to content

Commit

Permalink
Merge pull request #99 from jacekpoz/fill
Browse files Browse the repository at this point in the history
add an option to fill shapes
  • Loading branch information
gabm authored Jul 14, 2024
2 parents 2bd25b2 + 4e9ec75 commit c5e50bf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions icons.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,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
1 change: 1 addition & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/ellipse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
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 @@ -406,7 +407,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 c5e50bf

Please sign in to comment.