mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-01 20:08:11 +08:00
Hints backend (#234)
* Generate hints from list of actions * Remove redundant Key from output * Improve formatting * Change logging verbosity for hints
This commit is contained in:
committed by
Keavon Chambers
parent
76d57ab25d
commit
8cab7222a2
@@ -33,6 +33,7 @@ impl Dispatcher {
|
|||||||
) || MessageDiscriminant::from(&message).local_name().ends_with("MouseMove"))
|
) || MessageDiscriminant::from(&message).local_name().ends_with("MouseMove"))
|
||||||
{
|
{
|
||||||
log::trace!("Message: {}", message.to_discriminant().local_name());
|
log::trace!("Message: {}", message.to_discriminant().local_name());
|
||||||
|
log::trace!("Hints:{}", self.input_mapper.hints(self.collect_actions()));
|
||||||
}
|
}
|
||||||
match message {
|
match message {
|
||||||
NoOp => (),
|
NoOp => (),
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
use crate::consts::{MINUS_KEY_ZOOM_RATE, PLUS_KEY_ZOOM_RATE};
|
|
||||||
use crate::message_prelude::*;
|
|
||||||
use crate::tool::ToolType;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
keyboard::{Key, KeyStates, NUMBER_OF_KEYS},
|
keyboard::{Key, KeyStates, NUMBER_OF_KEYS},
|
||||||
InputPreprocessor,
|
InputPreprocessor,
|
||||||
};
|
};
|
||||||
|
use crate::consts::{MINUS_KEY_ZOOM_RATE, PLUS_KEY_ZOOM_RATE};
|
||||||
|
use crate::message_prelude::*;
|
||||||
|
use crate::tool::ToolType;
|
||||||
|
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
const NUDGE_AMOUNT: f64 = 1.;
|
const NUDGE_AMOUNT: f64 = 1.;
|
||||||
const SHIFT_NUDGE_AMOUNT: f64 = 10.;
|
const SHIFT_NUDGE_AMOUNT: f64 = 10.;
|
||||||
@@ -16,6 +17,7 @@ pub enum InputMapperMessage {
|
|||||||
PointerMove,
|
PointerMove,
|
||||||
MouseScroll,
|
MouseScroll,
|
||||||
KeyUp(Key),
|
KeyUp(Key),
|
||||||
|
#[child]
|
||||||
KeyDown(Key),
|
KeyDown(Key),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +283,32 @@ pub struct InputMapper {
|
|||||||
mapping: Mapping,
|
mapping: Mapping,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl InputMapper {
|
||||||
|
pub fn hints(&self, actions: ActionList) -> String {
|
||||||
|
let mut output = String::new();
|
||||||
|
let actions: Vec<MessageDiscriminant> = actions
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.filter(|a| !matches!(*a, MessageDiscriminant::Tool(ToolMessageDiscriminant::SelectTool) | MessageDiscriminant::Global(_)))
|
||||||
|
.collect();
|
||||||
|
self.mapping
|
||||||
|
.key_down
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(i, m)| {
|
||||||
|
let ma =
|
||||||
|
m.0.iter()
|
||||||
|
.find_map(|m| actions.iter().find_map(|a| (a == &m.action.to_discriminant()).then(|| m.action.to_discriminant())));
|
||||||
|
|
||||||
|
ma.map(|a| unsafe { (std::mem::transmute_copy::<usize, Key>(&i), a) })
|
||||||
|
})
|
||||||
|
.for_each(|(k, a)| {
|
||||||
|
let _ = write!(output, "{}: {}, ", k.to_discriminant().local_name(), a.local_name().split('.').last().unwrap());
|
||||||
|
});
|
||||||
|
output.replace("Key", "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MessageHandler<InputMapperMessage, (&InputPreprocessor, ActionList)> for InputMapper {
|
impl MessageHandler<InputMapperMessage, (&InputPreprocessor, ActionList)> for InputMapper {
|
||||||
fn process_action(&mut self, message: InputMapperMessage, data: (&InputPreprocessor, ActionList), responses: &mut VecDeque<Message>) {
|
fn process_action(&mut self, message: InputMapperMessage, data: (&InputPreprocessor, ActionList), responses: &mut VecDeque<Message>) {
|
||||||
let (input, actions) = data;
|
let (input, actions) = data;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::message_prelude::*;
|
||||||
|
|
||||||
pub const NUMBER_OF_KEYS: usize = Key::NumKeys as usize;
|
pub const NUMBER_OF_KEYS: usize = Key::NumKeys as usize;
|
||||||
// Edit this to specify the storage type used
|
// Edit this to specify the storage type used
|
||||||
// TODO: Increase size of type
|
// TODO: Increase size of type
|
||||||
@@ -9,6 +11,7 @@ const STORAGE_SIZE_BITS: usize = 1 << STORAGE_SIZE;
|
|||||||
const KEY_MASK_STORAGE_LENGTH: usize = (NUMBER_OF_KEYS + STORAGE_SIZE_BITS - 1) >> STORAGE_SIZE;
|
const KEY_MASK_STORAGE_LENGTH: usize = (NUMBER_OF_KEYS + STORAGE_SIZE_BITS - 1) >> STORAGE_SIZE;
|
||||||
pub type KeyStates = BitVector<KEY_MASK_STORAGE_LENGTH>;
|
pub type KeyStates = BitVector<KEY_MASK_STORAGE_LENGTH>;
|
||||||
|
|
||||||
|
#[impl_message(Message, InputMapperMessage, KeyDown)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum Key {
|
pub enum Key {
|
||||||
UnknownKey,
|
UnknownKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user