Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ fn main() -> Result<(), io::Error> {
"page-fit-regular",
"resize-large-regular",
"arrow-counterclockwise-regular",
"dismiss-regular",
"checkmark-regular",
],
);

Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ impl Component for App {
self.tools_toolbar
.sender()
.emit(ToolsToolbarInput::SetToolEditing(editing));
self.style_toolbar
.sender()
.emit(StyleToolbarInput::SetToolEditing(editing));
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,12 +880,8 @@ impl SketchBoard {
ToolbarEvent::SaveFileAs => self.handle_action(&[Action::SaveToFileAs]),
ToolbarEvent::Resize => self.handle_resize(),
ToolbarEvent::OriginalScale => self.handle_original_scale(),
/* ToolbarEvent::CropDimensionsUpdated(dimensions) => {
sender
.output_sender()
.emit(SketchBoardOutput::DimensionsUpdate(Some(dimensions)));
ToolUpdateResult::Unmodified
}*/
ToolbarEvent::ToolCommit => self.active_tool.borrow_mut().handle_deactivated(),
ToolbarEvent::ToolDismiss => self.active_tool.borrow_mut().handle_dismissed(),
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/tools/crop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,6 @@ impl CropTool {
}
}
}

fn handle_deactivate_and_reset(&mut self) -> ToolUpdateResult {
self.crop = None;
self.action = None;

if let Some(sender) = &self.sender {
sender
.send(SketchBoardInput::Output(
SketchBoardOutput::DimensionsUpdate(None),
))
.ok();
}
ToolUpdateResult::RedrawAndStopPropagation
}
}

impl Tool for CropTool {
Expand Down Expand Up @@ -429,7 +415,7 @@ impl Tool for CropTool {
//FIXME: use if let guards as soon as they're stabilized (1.95)
Key::Escape if self.crop.is_some() => {
if self.crop.as_mut().unwrap().active {
self.handle_deactivate_and_reset()
self.handle_dismissed()
} else {
ToolUpdateResult::Unmodified
}
Expand All @@ -452,7 +438,7 @@ impl Tool for CropTool {
if let Some(crop) = &self.crop
&& crop.active
{
self.handle_deactivate_and_reset()
self.handle_dismissed()
} else {
ToolUpdateResult::Unmodified
}
Expand Down Expand Up @@ -486,6 +472,20 @@ impl Tool for CropTool {
ToolUpdateResult::Redraw
}

fn handle_dismissed(&mut self) -> ToolUpdateResult {
self.crop = None;
self.action = None;

if let Some(sender) = &self.sender {
sender
.send(SketchBoardInput::Output(
SketchBoardOutput::DimensionsUpdate(None),
))
.ok();
}
ToolUpdateResult::RedrawAndStopPropagation
}

fn get_drawable(&self) -> Option<&dyn Drawable> {
// the reason we always return None is because we dont want this tool
// to show up with the standard rendering mechanism. Instead it will always
Expand Down
6 changes: 6 additions & 0 deletions src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod text;
pub enum ToolEvent {
Activated,
Deactivated,
Dismissed,
Input(InputEvent),
StyleChanged(Style),
}
Expand All @@ -53,6 +54,7 @@ pub trait Tool {
match event {
ToolEvent::Activated => self.handle_activated(),
ToolEvent::Deactivated => self.handle_deactivated(),
ToolEvent::Dismissed => self.handle_dismissed(),
ToolEvent::Input(e) => self.handle_input_event(e),
ToolEvent::StyleChanged(s) => self.handle_style_event(s),
}
Expand All @@ -66,6 +68,10 @@ pub trait Tool {
ToolUpdateResult::Unmodified
}

fn handle_dismissed(&mut self) -> ToolUpdateResult {
ToolUpdateResult::Unmodified
}

fn handle_input_event(&mut self, event: InputEvent) -> ToolUpdateResult {
match event {
InputEvent::Mouse(e) => self.handle_mouse_event(e),
Expand Down
8 changes: 7 additions & 1 deletion src/tools/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ impl Tool for TextTool {
}
},
Key::Escape => {
tool_update_result = self.handle_deactivated();
tool_update_result = self.handle_dismissed();
}
Key::BackSpace | Key::Delete => {
let ctrl_mask = match event.key {
Expand Down Expand Up @@ -1315,6 +1315,12 @@ impl Tool for TextTool {
}
}

fn handle_dismissed(&mut self) -> ToolUpdateResult {
self.input_enabled = false;
self.text = None;
ToolUpdateResult::Redraw
}

fn active(&self) -> bool {
self.text.is_some()
}
Expand Down
32 changes: 32 additions & 0 deletions src/ui/toolbars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct StyleToolbar {
color_action: SimpleAction,
visible: bool,
output_dimensions: String,
editing: bool,
}

#[derive(Debug, Copy, Clone)]
Expand All @@ -52,6 +53,8 @@ pub enum ToolbarEvent {
SaveFileAs,
Resize,
OriginalScale,
ToolCommit,
ToolDismiss,
}

#[derive(Debug, Copy, Clone)]
Expand All @@ -70,6 +73,7 @@ pub enum StyleToolbarInput {
SetVisibility(bool),
ToggleVisibility,
DimensionsChanged((i32, i32)),
SetToolEditing(bool),
}

fn create_icon_pixbuf(color: Color) -> Pixbuf {
Expand Down Expand Up @@ -594,6 +598,30 @@ impl Component for StyleToolbar {
button.set_icon_name(new_icon);
},
},
gtk::Separator {},
gtk::Button {
set_focusable: false,
set_hexpand: false,
set_icon_name: "dismiss-regular",
set_tooltip: "tool dismiss",
#[watch]
set_sensitive: model.editing,
connect_clicked[sender] => move |_| {
sender.output_sender().emit(ToolbarEvent::ToolDismiss);
},
},
gtk::Button {
set_focusable: false,
set_hexpand: false,
set_icon_name: "checkmark-regular",
set_tooltip: "tool commit",
#[watch]
set_sensitive: model.editing,
connect_clicked[sender] => move |_| {
sender.output_sender().emit(ToolbarEvent::ToolCommit);
},
},

},
}

Expand Down Expand Up @@ -632,6 +660,9 @@ impl Component for StyleToolbar {
StyleToolbarInput::DimensionsChanged((width, height)) => {
self.output_dimensions = format!("{}x{}", width, height);
}
StyleToolbarInput::SetToolEditing(editing) => {
self.editing = editing;
}
}
}

Expand Down Expand Up @@ -694,6 +725,7 @@ impl Component for StyleToolbar {
color_action: SimpleAction::from(color_action.clone()),
visible: !APP_CONFIG.read().default_hide_toolbars(),
output_dimensions: String::new(),
editing: false,
};

// create widgets
Expand Down
Loading