pub struct Layer { /* private fields */ }Expand description
A named collection of bindings that can be activated and deactivated.
Construct via the builder pattern, then register with
Dispatcher::define_layer.
§Examples
Basic layer with vim-style navigation:
use kbd::action::Action;
use kbd::key::Key;
use kbd::layer::Layer;
let nav = Layer::new("nav")
.bind(Key::H, Action::Suppress)
.bind(Key::J, Action::Suppress)
.bind(Key::K, Action::Suppress)
.bind(Key::L, Action::Suppress)
.description("Vim navigation keys")
.swallow();
assert_eq!(nav.name().as_str(), "nav");
assert_eq!(nav.binding_count(), 4);Oneshot layer that auto-pops after one keypress:
use kbd::action::Action;
use kbd::key::Key;
use kbd::layer::Layer;
let leader = Layer::new("leader")
.bind(Key::F, Action::Suppress)
.bind(Key::B, Action::Suppress)
.oneshot(1);Layer with a timeout that auto-pops after inactivity:
use std::time::Duration;
use kbd::action::Action;
use kbd::key::Key;
use kbd::layer::Layer;
let timed = Layer::new("quick-nav")
.bind(Key::N, Action::Suppress)
.bind(Key::P, Action::Suppress)
.timeout(Duration::from_secs(2));Implementations§
Source§impl Layer
impl Layer
Sourcepub fn bind(self, hotkey: impl Into<Hotkey>, action: impl Into<Action>) -> Self
pub fn bind(self, hotkey: impl Into<Hotkey>, action: impl Into<Action>) -> Self
Add a binding to this layer.
Sourcepub fn swallow(self) -> Self
pub fn swallow(self) -> Self
Set the layer to swallow unmatched keys (consume instead of fallthrough).
Sourcepub fn oneshot(self, depth: usize) -> Self
pub fn oneshot(self, depth: usize) -> Self
Set the layer to auto-pop after depth keypresses (oneshot mode).
Sourcepub fn timeout(self, duration: Duration) -> Self
pub fn timeout(self, duration: Duration) -> Self
Set the layer to auto-pop after duration of inactivity.
Sourcepub fn description(self, description: impl Into<Box<str>>) -> Self
pub fn description(self, description: impl Into<Box<str>>) -> Self
Set a human-readable description for this layer.
Used for overlay grouping and help screen display.
Sourcepub fn options(&self) -> &LayerOptions
pub fn options(&self) -> &LayerOptions
The layer’s options.
Sourcepub fn binding_count(&self) -> usize
pub fn binding_count(&self) -> usize
The number of bindings in this layer.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Layer
impl !RefUnwindSafe for Layer
impl Send for Layer
impl Sync for Layer
impl Unpin for Layer
impl UnsafeUnpin for Layer
impl !UnwindSafe for Layer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more