Skip to content

Commit

Permalink
update the canvas for edit mode state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
justDeeevin committed Sep 25, 2024
1 parent 41c6f91 commit 48b2ba4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/nuhxboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub enum Message {
ToggleSaveStyleAsGlobal,
ChangeBackground(Color),
ToggleColorPicker(ColorPicker),
UpdateCanvas,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -260,6 +261,7 @@ impl NuhxBoard {
self.canvas.clear();
return self.input_event(event);
}
Message::Listener(_) => clear_canvas = false,
Message::ReleaseScroll(button) => {
match self.pressed_scroll_buttons.get_mut(&button).unwrap() {
1 => {
Expand Down Expand Up @@ -362,7 +364,6 @@ impl NuhxBoard {
Message::ClearPressedKeys => {
self.pressed_keys.clear();
}
Message::Listener(_) => clear_canvas = false,
Message::ToggleEditMode => {
self.edit_mode = !self.edit_mode;
}
Expand Down Expand Up @@ -418,7 +419,6 @@ impl NuhxBoard {
self.history_depth = 0;
}
self.edit_history.push(change);
clear_canvas = false;
}
Message::Undo => {
if self.history_depth < self.edit_history.len() {
Expand Down Expand Up @@ -519,6 +519,7 @@ impl NuhxBoard {
clear_canvas = false;
}
},
Message::UpdateCanvas => {}
}
if clear_canvas {
self.canvas.clear();
Expand Down
49 changes: 44 additions & 5 deletions src/ui/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,18 @@ impl canvas::Program<Message> for NuhxBoard {
state.hovered_element = Some(index);
}
state.previous_cursor_position = cursor_position_geo;
return (Status::Captured, None);

return (
Status::Captured,
if cfg!(target_os = "linux")
&& std::env::var("XDG_SESSION_TYPE").unwrap()
== "wayland"
{
Some(Message::UpdateCanvas)
} else {
None
},
);
}
}
_ => {
Expand All @@ -382,7 +393,17 @@ impl canvas::Program<Message> for NuhxBoard {
state.hovered_element = Some(index);
}
state.previous_cursor_position = cursor_position_geo;
return (Status::Captured, None);
return (
Status::Captured,
if cfg!(target_os = "linux")
&& std::env::var("XDG_SESSION_TYPE").unwrap()
== "wayland"
{
Some(Message::UpdateCanvas)
} else {
None
},
);
}
}
}
Expand All @@ -391,7 +412,16 @@ impl canvas::Program<Message> for NuhxBoard {
if state.hovered_element.is_some() {
state.hovered_element = None;
state.previous_cursor_position = cursor_position_geo;
return (Status::Captured, None);
return (
Status::Captured,
if cfg!(target_os = "linux")
&& std::env::var("XDG_SESSION_TYPE").unwrap() == "wayland"
{
Some(Message::UpdateCanvas)
} else {
None
},
);
}
}
Interaction::Dragging => {
Expand Down Expand Up @@ -422,7 +452,16 @@ impl canvas::Program<Message> for NuhxBoard {
state.selected_element = None;
}

return (Status::Captured, None);
return (
Status::Captured,
if cfg!(target_os = "linux")
&& std::env::var("XDG_SESSION_TYPE").unwrap() == "wayland"
{
Some(Message::UpdateCanvas)
} else {
None
},
);
}
mouse::Event::ButtonReleased(mouse::Button::Left) => {
let message = if state.delta_accumulator != Coord::default() {
Expand All @@ -438,7 +477,7 @@ impl canvas::Program<Message> for NuhxBoard {
out
} else {
state.selected_element = state.hovered_element;
None
Some(Message::UpdateCanvas)
};

state.held_element = None;
Expand Down

0 comments on commit 48b2ba4

Please sign in to comment.