-
Notifications
You must be signed in to change notification settings - Fork 713
compiler: Have a key-sequence
type
#8906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ pub enum Type { | |
Array(Rc<Type>), | ||
Struct(Rc<Struct>), | ||
Enumeration(Rc<Enumeration>), | ||
KeyboardShortcut, | ||
|
||
/// A type made up of the product of several "unit" types. | ||
/// The first parameter is the unit, and the second parameter is the power. | ||
|
@@ -101,6 +102,7 @@ impl core::cmp::PartialEq for Type { | |
matches!(other, Type::Struct(rhs) if lhs.fields == rhs.fields && lhs.name == rhs.name) | ||
} | ||
Type::Enumeration(lhs) => matches!(other, Type::Enumeration(rhs) if lhs == rhs), | ||
Type::KeyboardShortcut => matches!(other, Type::KeyboardShortcut), | ||
Type::UnitProduct(a) => matches!(other, Type::UnitProduct(b) if a == b), | ||
Type::ElementReference => matches!(other, Type::ElementReference), | ||
Type::LayoutCache => matches!(other, Type::LayoutCache), | ||
|
@@ -160,6 +162,7 @@ impl Display for Type { | |
Type::Easing => write!(f, "easing"), | ||
Type::Brush => write!(f, "brush"), | ||
Type::Enumeration(enumeration) => write!(f, "enum {}", enumeration.name), | ||
Type::KeyboardShortcut => write!(f, "keyboard-shortcut"), | ||
Type::UnitProduct(vec) => { | ||
const POWERS: &[char] = &['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹']; | ||
let mut x = vec.iter().map(|(unit, power)| { | ||
|
@@ -208,6 +211,7 @@ impl Type { | |
| Self::Bool | ||
| Self::Easing | ||
| Self::Enumeration(_) | ||
| Self::KeyboardShortcut | ||
| Self::ElementReference | ||
| Self::Struct { .. } | ||
| Self::Array(_) | ||
|
@@ -265,6 +269,7 @@ impl Type { | |
| (Type::LogicalLength, Type::Rem) | ||
| (Type::PhysicalLength, Type::Rem) | ||
| (Type::Percent, Type::Float32) | ||
| (Type::KeyboardShortcut, Type::String) | ||
| (Type::Brush, Type::Color) | ||
| (Type::Color, Type::Brush) => true, | ||
(Type::Array(a), Type::Model) if a.is_property_type() => true, | ||
|
@@ -311,6 +316,7 @@ impl Type { | |
Type::Array(_) => None, | ||
Type::Struct { .. } => None, | ||
Type::Enumeration(_) => None, | ||
Type::KeyboardShortcut => None, | ||
Type::UnitProduct(_) => None, | ||
Type::ElementReference => None, | ||
Type::LayoutCache => None, | ||
|
@@ -839,6 +845,40 @@ impl Enumeration { | |
} | ||
} | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct KeyboardModifiers { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we already have such a type somewhere else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do. But I can not get to it from here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have this type in |
||
pub alt: bool, | ||
pub control: bool, | ||
pub meta: bool, | ||
pub shift: bool, | ||
} | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct KeyboardShortcut { | ||
pub key: char, | ||
pub modifiers: KeyboardModifiers, | ||
} | ||
|
||
impl PartialEq for KeyboardShortcut { | ||
fn eq(&self, _other: &Self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
impl std::fmt::Display for KeyboardShortcut { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let alt = if self.modifiers.alt { "alt+" } else { "" }; | ||
let ctrl = if self.modifiers.control { "ctrl+" } else { "" }; | ||
let meta = if self.modifiers.meta { "meta+" } else { "" }; | ||
let shift = if self.modifiers.shift { "shift+" } else { "" }; | ||
write!(f, "{alt}{ctrl}{meta}{shift}{}", self.key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking we also want to support key that are not printable like arrows, enter, media keys, F keys and so on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that will be needed. |
||
} | ||
} | ||
|
||
pub fn keyboard_shortcuts_to_string(shortcuts: &[KeyboardShortcut]) -> String { | ||
shortcuts.iter().map(|ks| ks.to_string()).join(", ") | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct EnumerationValue { | ||
pub value: usize, // index in enumeration.values | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tired to return a String that contains the stringified definition, but that causes infinite recursion... I need to check out why that happens in detail.