1
0
Fork 0

Add helpers for keyboard modifiers in vizia

This commit is contained in:
Robbert van der Helm 2022-03-19 00:38:26 +01:00
parent e2c691ba55
commit d8e8d80402
2 changed files with 37 additions and 0 deletions

View file

@ -11,6 +11,8 @@ use std::sync::Arc;
use vizia::{Context, Model};
pub mod util;
/// Register the default theme for the widgets exported by this module. This is automatically called
/// for you when using [`create_vizia_editor()`][super::create_vizia_editor()].
pub fn register_theme(cx: &mut Context) {

View file

@ -0,0 +1,35 @@
//! Utilities for writing VIZIA widgets.
use vizia::Modifiers;
/// An extension trait for [`Modifiers`] that adds platform-independent getters.
pub trait ModifiersExt {
/// Returns true if the Command (on macOS) or Ctrl (on any other platform) key is pressed.
fn command(&self) -> bool;
/// Returns true if the Alt (or Option on macOS) key is pressed.
fn alt(&self) -> bool;
/// Returns true if the Shift key is pressed.
fn shift(&self) -> bool;
}
impl ModifiersExt for Modifiers {
fn command(&self) -> bool {
#[cfg(target_os = "macos")]
let result = self.contains(Modifiers::LOGO);
#[cfg(not(target_os = "macos"))]
let result = self.contains(Modifiers::CTRL);
result
}
fn alt(&self) -> bool {
self.contains(Modifiers::ALT)
}
fn shift(&self) -> bool {
self.contains(Modifiers::SHIFT)
}
}