Lots of owork on a calculator example, transparency, etc.
This commit is contained in:
@@ -155,6 +155,11 @@ pub fn use_window_title(compute: impl FnOnce() -> String) {
|
||||
pub enum Key {
|
||||
Character(char),
|
||||
Enter,
|
||||
Backspace,
|
||||
Escape,
|
||||
Delete,
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
ArrowUp,
|
||||
ArrowDown,
|
||||
Home,
|
||||
@@ -169,6 +174,11 @@ impl Key {
|
||||
.next()
|
||||
.is_some_and(|actual| actual.eq_ignore_ascii_case(expected)),
|
||||
(Self::Enter, KeyboardKey::Enter) => true,
|
||||
(Self::Backspace, KeyboardKey::Backspace) => true,
|
||||
(Self::Escape, KeyboardKey::Escape) => true,
|
||||
(Self::Delete, KeyboardKey::Delete) => true,
|
||||
(Self::ArrowLeft, KeyboardKey::ArrowLeft) => true,
|
||||
(Self::ArrowRight, KeyboardKey::ArrowRight) => true,
|
||||
(Self::ArrowUp, KeyboardKey::ArrowUp) => true,
|
||||
(Self::ArrowDown, KeyboardKey::ArrowDown) => true,
|
||||
(Self::Home, KeyboardKey::Home) => true,
|
||||
@@ -209,12 +219,27 @@ impl Shortcut {
|
||||
}
|
||||
|
||||
pub(crate) fn matches(&self, event: &KeyboardEvent) -> bool {
|
||||
event.kind == KeyboardEventKind::Pressed
|
||||
&& self.key.matches(event)
|
||||
&& event.modifiers.control == self.control
|
||||
&& event.modifiers.shift == self.shift
|
||||
&& event.modifiers.alt == self.alt
|
||||
&& event.modifiers.super_key == self.super_key
|
||||
if event.kind != KeyboardEventKind::Pressed {
|
||||
return false;
|
||||
}
|
||||
if !self.key.matches(event) {
|
||||
return false;
|
||||
}
|
||||
if event.modifiers.control != self.control {
|
||||
return false;
|
||||
}
|
||||
if event.modifiers.alt != self.alt {
|
||||
return false;
|
||||
}
|
||||
if event.modifiers.super_key != self.super_key {
|
||||
return false;
|
||||
}
|
||||
// For character shortcuts the produced character already encodes the shift
|
||||
// state, so don't additionally require that Shift is (un)held.
|
||||
if !matches!(self.key, Key::Character(_)) && event.modifiers.shift != self.shift {
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,6 +248,12 @@ pub struct FocusScope {
|
||||
pub(crate) element_id: Signal<Option<ElementId>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub struct InteractionState {
|
||||
pub hovered: bool,
|
||||
pub pressed: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ShortcutScope {
|
||||
Application,
|
||||
@@ -296,6 +327,18 @@ pub fn use_widget_ref<T: 'static>() -> WidgetRef<T> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn use_interaction_state<T: 'static>(widget_ref: WidgetRef<T>) -> InteractionState {
|
||||
with_render_context_state(|context| {
|
||||
let Some(element_id) = widget_ref.element_id() else {
|
||||
return InteractionState::default();
|
||||
};
|
||||
InteractionState {
|
||||
hovered: context.interaction.hovered.contains(&element_id),
|
||||
pressed: context.interaction.pressed.contains(&element_id),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn use_shortcut(shortcut: Shortcut, scope: ShortcutScope, action: impl Fn() + 'static) {
|
||||
use_shortcut_with_context(shortcut, scope, move |_| action());
|
||||
}
|
||||
@@ -371,4 +414,3 @@ where
|
||||
|slot: &mut ResourceSlot<T, E>| slot.resource.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user