Skip to content

Commit

Permalink
tweak backlog policies
Browse files Browse the repository at this point in the history
  • Loading branch information
flxzt committed Mar 4, 2023
1 parent a97fe74 commit 8ffeb17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions rnote-engine/src/pens/penholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::widgetflags::WidgetFlags;
use crate::DrawOnDocBehaviour;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum BackLogPolicy {
pub enum BacklogPolicy {
NoLimit,
Limit(Duration),
DisableBacklog,
Expand All @@ -34,7 +34,7 @@ pub struct PenHolder {
pub pen_mode_state: PenModeState,
/// Indicates the policy for the retrieval of the event backlog
#[serde(skip)]
pub backlog_policy: BackLogPolicy,
pub backlog_policy: BacklogPolicy,

#[serde(skip)]
pub(super) current_pen: Pen,
Expand All @@ -51,7 +51,7 @@ impl Default for PenHolder {
Self {
shortcuts: Shortcuts::default(),
pen_mode_state: PenModeState::default(),
backlog_policy: BackLogPolicy::NoLimit,
backlog_policy: BacklogPolicy::NoLimit,

current_pen: Pen::default(),
pen_progress: PenProgress::Idle,
Expand Down Expand Up @@ -265,12 +265,12 @@ impl PenHolder {
let current_style = self.pen_mode_state.current_style_w_override();

self.backlog_policy = match current_style {
PenStyle::Brush => BackLogPolicy::NoLimit,
PenStyle::Shaper => BackLogPolicy::Limit(Duration::from_millis(16)),
PenStyle::Typewriter => BackLogPolicy::Limit(Duration::from_millis(16)),
PenStyle::Eraser => BackLogPolicy::Limit(Duration::from_millis(16)),
PenStyle::Selector => BackLogPolicy::Limit(Duration::from_millis(16)),
PenStyle::Tools => BackLogPolicy::Limit(Duration::from_millis(16)),
PenStyle::Brush => BacklogPolicy::NoLimit,
PenStyle::Shaper => BacklogPolicy::Limit(Duration::from_millis(16)),
PenStyle::Typewriter => BacklogPolicy::Limit(Duration::from_millis(33)),
PenStyle::Eraser => BacklogPolicy::Limit(Duration::from_millis(33)),
PenStyle::Selector => BacklogPolicy::Limit(Duration::from_millis(33)),
PenStyle::Tools => BacklogPolicy::DisableBacklog,
};

// Enable text preprocessing for typewriter
Expand Down
8 changes: 4 additions & 4 deletions rnote-ui/src/canvas/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rnote_compose::penevents::ShortcutKey;
use rnote_compose::penevents::{KeyboardKey, PenState};
use rnote_compose::penevents::{ModifierKey, PenEvent};
use rnote_compose::penpath::Element;
use rnote_engine::pens::penholder::BackLogPolicy;
use rnote_engine::pens::penholder::BacklogPolicy;
use rnote_engine::pens::PenMode;
use rnote_engine::WidgetFlags;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -288,7 +288,7 @@ fn retrieve_pointer_elements(
canvas: &RnCanvas,
now: Instant,
event: &gdk::Event,
backlog_policy: BackLogPolicy,
backlog_policy: BacklogPolicy,
) -> Option<Vec<(Element, Instant)>> {
let root = canvas.root().unwrap();
let (surface_trans_x, surface_trans_y) = root.surface_transform();
Expand All @@ -311,7 +311,7 @@ fn retrieve_pointer_elements(
};

if event.event_type() == gdk::EventType::MotionNotify
&& backlog_policy != BackLogPolicy::DisableBacklog
&& backlog_policy != BacklogPolicy::DisableBacklog
{
let mut prev_delta = Duration::ZERO;

Expand All @@ -327,7 +327,7 @@ fn retrieve_pointer_elements(
let entry_delta = Duration::from_millis(event_time.saturating_sub(entry.time()) as u64);
let Some(entry_time) = now.checked_sub(entry_delta) else {continue;};

if let BackLogPolicy::Limit(delta_limit) = backlog_policy {
if let BacklogPolicy::Limit(delta_limit) = backlog_policy {
// We go back in time, so `entry_delta` will increase
//
// If the backlog input rate is higher than the limit, filter it out
Expand Down

0 comments on commit 8ffeb17

Please sign in to comment.