mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
Add a Keys
namespace in the .60 language with all the string constant for special keys
This commit is contained in:
parent
733d4ed365
commit
f7c92183db
4 changed files with 47 additions and 0 deletions
|
@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Breaking:** The internal key code for the keys left, right, home and end
|
||||||
|
has changed. This was undocumented, but if one was handling this in the
|
||||||
|
`FocusScope` event, these keys will now be ignored. Use the `Keys.LeftArrow`
|
||||||
|
and other code exposed in the `Keys` namespace instead
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Colors names can now be accessed through the `Colors` namespace
|
- Colors names can now be accessed through the `Colors` namespace
|
||||||
|
@ -10,6 +17,8 @@ All notable changes to this project will be documented in this file.
|
||||||
- `TouchArea` gained a `mouse-cursor` property to change the mouse cursor
|
- `TouchArea` gained a `mouse-cursor` property to change the mouse cursor
|
||||||
- C++: Added version macros
|
- C++: Added version macros
|
||||||
- Optimize some property access by doing more constant propagation
|
- Optimize some property access by doing more constant propagation
|
||||||
|
- More special keyboard key codes are provided in the `FocusScope`, and
|
||||||
|
special keys are handled
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -458,6 +458,10 @@ Example := Window {
|
||||||
|
|
||||||
The FocusScope exposes callback to intercept the pressed key when it has focus.
|
The FocusScope exposes callback to intercept the pressed key when it has focus.
|
||||||
|
|
||||||
|
The KeyEvent has a text property which is a character of the key entered.
|
||||||
|
When a non-printable key is pressed, the character will be either a control character,
|
||||||
|
or a private unicode character. The special characters are available in the `Keys` namespace
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
* **`has-focus`** (*bool*): Set to `true` when item is focused and receives keyboard events.
|
* **`has-focus`** (*bool*): Set to `true` when item is focused and receives keyboard events.
|
||||||
|
@ -482,6 +486,9 @@ Example := Window {
|
||||||
if (event.modifiers.control) {
|
if (event.modifiers.control) {
|
||||||
debug("control was pressed during this event");
|
debug("control was pressed during this event");
|
||||||
}
|
}
|
||||||
|
if (event.text == Keys.Escape) {
|
||||||
|
debug("Esc key was pressed")
|
||||||
|
}
|
||||||
accept
|
accept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ pub enum LookupResult {
|
||||||
pub enum BuiltinNamespace {
|
pub enum BuiltinNamespace {
|
||||||
Colors,
|
Colors,
|
||||||
Math,
|
Math,
|
||||||
|
Keys,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Expression> for LookupResult {
|
impl From<Expression> for LookupResult {
|
||||||
|
@ -149,6 +150,7 @@ impl LookupObject for LookupResult {
|
||||||
(ColorSpecific, ColorFunctions).for_each_entry(ctx, f)
|
(ColorSpecific, ColorFunctions).for_each_entry(ctx, f)
|
||||||
}
|
}
|
||||||
LookupResult::Namespace(BuiltinNamespace::Math) => MathFunctions.for_each_entry(ctx, f),
|
LookupResult::Namespace(BuiltinNamespace::Math) => MathFunctions.for_each_entry(ctx, f),
|
||||||
|
LookupResult::Namespace(BuiltinNamespace::Keys) => KeysLookup.for_each_entry(ctx, f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +162,7 @@ impl LookupObject for LookupResult {
|
||||||
(ColorSpecific, ColorFunctions).lookup(ctx, name)
|
(ColorSpecific, ColorFunctions).lookup(ctx, name)
|
||||||
}
|
}
|
||||||
LookupResult::Namespace(BuiltinNamespace::Math) => MathFunctions.lookup(ctx, name),
|
LookupResult::Namespace(BuiltinNamespace::Math) => MathFunctions.lookup(ctx, name),
|
||||||
|
LookupResult::Namespace(BuiltinNamespace::Keys) => KeysLookup.lookup(ctx, name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,6 +445,27 @@ impl ColorSpecific {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct KeysLookup;
|
||||||
|
|
||||||
|
macro_rules! for_each_special_keys {
|
||||||
|
($($char:literal # $name:ident # $($qt:ident)|* # $($winit:ident)|* ;)*) => {
|
||||||
|
use super::*;
|
||||||
|
impl LookupObject for KeysLookup {
|
||||||
|
fn for_each_entry<R>(
|
||||||
|
&self,
|
||||||
|
_ctx: &LookupCtx,
|
||||||
|
f: &mut impl FnMut(&str, LookupResult) -> Option<R>,
|
||||||
|
) -> Option<R> {
|
||||||
|
None
|
||||||
|
$(.or_else(|| {
|
||||||
|
f(stringify!($name), Expression::StringLiteral($char.into()).into())
|
||||||
|
}))*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
mod key_codes;
|
||||||
|
|
||||||
struct EasingSpecific;
|
struct EasingSpecific;
|
||||||
impl LookupObject for EasingSpecific {
|
impl LookupObject for EasingSpecific {
|
||||||
fn for_each_entry<R>(
|
fn for_each_entry<R>(
|
||||||
|
@ -567,6 +591,7 @@ impl LookupObject for BuiltinNamespaceLookup {
|
||||||
) -> Option<R> {
|
) -> Option<R> {
|
||||||
None.or_else(|| f("Colors", LookupResult::Namespace(BuiltinNamespace::Colors)))
|
None.or_else(|| f("Colors", LookupResult::Namespace(BuiltinNamespace::Colors)))
|
||||||
.or_else(|| f("Math", LookupResult::Namespace(BuiltinNamespace::Math)))
|
.or_else(|| f("Math", LookupResult::Namespace(BuiltinNamespace::Math)))
|
||||||
|
.or_else(|| f("Keys", LookupResult::Namespace(BuiltinNamespace::Keys)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,12 @@ W := Window {
|
||||||
field := FocusScope {
|
field := FocusScope {
|
||||||
vertical_stretch: 1;
|
vertical_stretch: 1;
|
||||||
key-pressed(event) => {
|
key-pressed(event) => {
|
||||||
|
if (event.text == Keys.F1) {
|
||||||
|
debug("F1");
|
||||||
|
}
|
||||||
|
if (event.text == Keys.PageUp) {
|
||||||
|
debug("PageUp");
|
||||||
|
}
|
||||||
if (event.modifiers.control) {
|
if (event.modifiers.control) {
|
||||||
debug(" (control modifier pressed)");
|
debug(" (control modifier pressed)");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue