Skip to main content

KeyBinder

Struct KeyBinder 

Source
pub struct KeyBinder<T> { /* private fields */ }
Expand description

§Main Keybinder struct

This struct is a safe wrapper for KeyBinder and contains functions to initialize KeyBinder, bind keys and then unbind keys.

The struct guarantees that keybinder_init is called only once. This means you can use this struct anywhere inside your code. Only the first time you call KeyBinder::new() will call keybinder_init.

§Note

Make sure you initialize GTK before initializing KeyBinder

Example:

use keybinder::KeyBinder;

fn main() {
    gtk::init().expect("Failed to init GTK");
    let data = String::from("some data");
    let mut keybinder = KeyBinder::<String>::new(true).expect("Keybinder is not supported");

    assert_eq!(keybinder.bind("<Shift>space", |key, data| {
        println!("key: {} , data: {}", key, data);
        gtk::main_quit();
    }, data), true);
    println!("Successfully bound keystring to handler");
    gtk::main();
}

Implementations§

Source§

impl<T> KeyBinder<T>

Source

pub fn new(use_cooked: bool) -> Result<Self, ()>

Creates and initializes Keybinder(It it’s not already initialized).

§Returns

Ok(Self) if KeyBinder is supported. Otherwise, Err(()).

Source

pub fn bind( &mut self, keystring: &str, user_handler: fn(String, &T), user_data: T, ) -> bool

Binds handler to given keystring and passes the user data to handler when key is pressed.

Source

pub fn unbind(&mut self, keystring: &str)

Unbinds the given keystring. If it’s not bound, it does nothing.

Trait Implementations§

Source§

impl<T: Debug> Debug for KeyBinder<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for KeyBinder<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> Freeze for KeyBinder<T>

§

impl<T> RefUnwindSafe for KeyBinder<T>
where T: RefUnwindSafe,

§

impl<T> !Send for KeyBinder<T>

§

impl<T> !Sync for KeyBinder<T>

§

impl<T> Unpin for KeyBinder<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for KeyBinder<T>

§

impl<T> UnwindSafe for KeyBinder<T>
where T: UnwindSafe,

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.