Skip to content

Commit

Permalink
improv: refactor unnecessary use of widget flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Kneemund committed Nov 21, 2024
1 parent 071ed42 commit 96dce63
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/rnote-engine/src/engine/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ impl Engine {
spellcheck: &mut self.spellcheck,
});
widget_flags |= self.doc_resize_to_fit_content();
widget_flags |= self.refresh_spellcheck_language();
widget_flags.redraw = true;
widget_flags.refresh_ui = true;
widget_flags.spellcheck_language_modified = true;
widget_flags
}

Expand Down
10 changes: 9 additions & 1 deletion crates/rnote-engine/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ impl Engine {
}
}

pub fn refresh_spellcheck_language(&mut self) {
pub fn refresh_spellcheck_language(&mut self) -> WidgetFlags {
let mut widget_flags = WidgetFlags::default();

self.spellcheck.dict = self
.document
.spellcheck_language
Expand All @@ -370,7 +372,11 @@ impl Engine {
audioplayer: &mut self.audioplayer,
spellcheck: &mut self.spellcheck,
});

widget_flags.redraw = true;
}

widget_flags
}

pub fn optimize_epd(&self) -> bool {
Expand Down Expand Up @@ -446,6 +452,7 @@ impl Engine {
| self.doc_resize_autoexpand()
| self.current_pen_update_state()
| self.update_rendering_current_viewport()
| self.refresh_spellcheck_language()
}

/// Redo the latest changes.
Expand All @@ -454,6 +461,7 @@ impl Engine {
| self.doc_resize_autoexpand()
| self.current_pen_update_state()
| self.update_rendering_current_viewport()
| self.refresh_spellcheck_language()
}

pub fn can_undo(&self) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions crates/rnote-engine/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ impl StrokeStore {
widget_flags.hide_undo = Some(!self.can_undo());
widget_flags.hide_redo = Some(!self.can_redo());
widget_flags.store_modified = true;
widget_flags.spellcheck_language_modified = true;

widget_flags
}
Expand All @@ -285,7 +284,6 @@ impl StrokeStore {
widget_flags.hide_undo = Some(!self.can_undo());
widget_flags.hide_redo = Some(!self.can_redo());
widget_flags.store_modified = true;
widget_flags.spellcheck_language_modified = true;

widget_flags
}
Expand Down
4 changes: 0 additions & 4 deletions crates/rnote-engine/src/widgetflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ pub struct WidgetFlags {
pub refresh_ui: bool,
/// Indicates that the store was modified, i.e. new strokes inserted, modified, etc. .
pub store_modified: bool,
/// Indicates that the spellcheck language was modified.
pub spellcheck_language_modified: bool,
/// Update the current view offsets and size.
pub view_modified: bool,
/// Indicates that the camera has changed it's temporary zoom.
Expand All @@ -37,7 +35,6 @@ impl Default for WidgetFlags {
resize: false,
refresh_ui: false,
store_modified: false,
spellcheck_language_modified: false,
view_modified: false,
zoomed_temporarily: false,
zoomed: false,
Expand All @@ -64,7 +61,6 @@ impl std::ops::BitOrAssign for WidgetFlags {
self.resize |= rhs.resize;
self.refresh_ui |= rhs.refresh_ui;
self.store_modified |= rhs.store_modified;
self.spellcheck_language_modified |= rhs.spellcheck_language_modified;
self.view_modified |= rhs.view_modified;
self.zoomed_temporarily |= rhs.zoomed_temporarily;
self.zoomed |= rhs.zoomed;
Expand Down
4 changes: 0 additions & 4 deletions crates/rnote-ui/src/appwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@ impl RnAppWindow {
canvas.set_unsaved_changes(true);
canvas.set_empty(false);
}
if widget_flags.spellcheck_language_modified {
canvas.engine_mut().refresh_spellcheck_language();
canvas.queue_draw();
}
if widget_flags.view_modified {
let widget_size = canvas.widget_size();
let offset_mins_maxs = canvas.engine_ref().camera_offset_mins_maxs();
Expand Down
1 change: 0 additions & 1 deletion crates/rnote-ui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(missing_debug_implementations)]
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::single_match)]
// Turns off console window on Windows, but not when building with dev profile.
#![cfg_attr(
Expand Down
5 changes: 1 addition & 4 deletions crates/rnote-ui/src/settingspanel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use rnote_engine::document::format::{self, Format, PredefinedFormat};
use rnote_engine::document::Layout;
use rnote_engine::engine::SPELLCHECK_AVAILABLE_LANGUAGES;
use rnote_engine::ext::GdkRGBAExt;
use rnote_engine::WidgetFlags;
use std::cell::RefCell;

mod imp {
Expand Down Expand Up @@ -989,9 +988,7 @@ impl RnSettingsPanel {
let language = settings_panel.spellcheck_language();
canvas.engine_mut().document.spellcheck_language = language;

let mut widget_flags = WidgetFlags::default();
widget_flags.spellcheck_language_modified = true;

let widget_flags = canvas.engine_mut().refresh_spellcheck_language();
appwindow.handle_widget_flags(widget_flags, &canvas);
}
));
Expand Down

0 comments on commit 96dce63

Please sign in to comment.