Add helpers for keyboard modifiers in vizia
This commit is contained in:
parent
e2c691ba55
commit
d8e8d80402
|
@ -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) {
|
||||
|
|
35
nih_plug_vizia/src/widgets/util.rs
Normal file
35
nih_plug_vizia/src/widgets/util.rs
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue