Skip to main content

Layer

Struct Layer 

Source
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

Source

pub fn new(name: impl Into<LayerName>) -> Self

Create a new layer with the given name.

Source

pub fn bind(self, hotkey: impl Into<Hotkey>, action: impl Into<Action>) -> Self

Add a binding to this layer.

Source

pub fn swallow(self) -> Self

Set the layer to swallow unmatched keys (consume instead of fallthrough).

Source

pub fn oneshot(self, depth: usize) -> Self

Set the layer to auto-pop after depth keypresses (oneshot mode).

Source

pub fn timeout(self, duration: Duration) -> Self

Set the layer to auto-pop after duration of inactivity.

Source

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.

Source

pub fn name(&self) -> &LayerName

The layer’s name.

Source

pub fn options(&self) -> &LayerOptions

The layer’s options.

Source

pub fn binding_count(&self) -> usize

The number of bindings in this layer.

Trait Implementations§

Source§

impl Debug for Layer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.