mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-21 05:48:12 +08:00
Reduce tool code duplication and boilerplate (#993)
* Reduce tool code duplication * Add doc comments * Fix Mac key variant, which can't be auto-converted without false positives * Rename "key" to "keys" --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
78b01b46ec
commit
d367b99bef
@@ -423,6 +423,10 @@ impl<const LENGTH: usize> BitVector<LENGTH> {
|
||||
(self.0[offset] & bit) != 0
|
||||
}
|
||||
|
||||
pub fn key(&self, key: Key) -> bool {
|
||||
self.get(key as usize)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
let mut result = 0;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use crate::consts::DRAG_THRESHOLD;
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
use bitflags::bitflags;
|
||||
use glam::DVec2;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
// Origin is top left
|
||||
pub type ViewportPosition = DVec2;
|
||||
@@ -85,6 +89,13 @@ impl MouseState {
|
||||
scroll_delta: ScrollDelta::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn finish_transaction(&self, drag_start: DVec2, responses: &mut VecDeque<Message>) {
|
||||
match drag_start.distance(self.position) <= DRAG_THRESHOLD {
|
||||
true => responses.push_back(DocumentMessage::AbortTransaction.into()),
|
||||
false => responses.push_back(DocumentMessage::CommitTransaction.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user