egui_virtual_keyboard

Struct VirtualKeyboard

Source
pub struct VirtualKeyboard { /* private fields */ }
Expand description

§A Keyboard, that can be drawn in egui.

By default holds mobile version of QWERTY, Numeric & Symbols layouts.

Needs to hook into raw input with bump_events.

Example use:

use egui_virtual_keyboard::VirtualKeyboard;

pub struct ExampleApp {
    label: String,
    keyboard: VirtualKeyboard,
}

impl Default for ExampleApp {
    fn default() -> Self {
        Self {
            label: "Hello World!".to_owned(),
            keyboard: Default::default(),
        }
    }
}

impl eframe::App for ExampleApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.horizontal(|ui| {
                ui.label("Write something: ");
                ui.text_edit_singleline(&mut self.label);
            });
        });

        let scr_size = ctx.screen_rect().size();
        egui::Window::new("KBD").show(ctx, |ui| {
                self.keyboard.show(ui);
            });
    }

    fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) {
        self.keyboard.bump_events(ctx, raw_input);
    }
}


fn main() -> eframe::Result {
    let native_options = eframe::NativeOptions::default();
     
    eframe::run_native(
        "eframe template",
        native_options,
        Box::new(|_cc| Ok(Box::new(ExampleApp::default()))),
    )
}

Implementations§

Source§

impl VirtualKeyboard

Source

pub fn empty() -> Self

Creates empty VirtualKeyboard

Source

pub fn with_id(self, id: Id) -> Self

Use provided Id instead of default “VirtualKeyboard”

Source

pub fn extend(self, layout: Layout) -> Self

Add Layout to keyboard

Source

pub fn clear_layouts(&mut self)

Source

pub fn switch_layout(&mut self, name: &str)

Switches to Layout with provided name (if exists)

Source

pub fn with_butyon_spacing(self, spacing: Vec2) -> Self

Use provided button height instead of default interact_size.x * 0.9

Source

pub fn with_button_height(self, height: f32) -> Self

Use provided button height instead of default interact_size.x * 0.9

Source

pub fn with_button_width(self, width: impl Into<RangeInclusive<f32>>) -> Self

Use provided button width range instead of icon_width..=interact_size.x

Source

pub fn bump_events(&mut self, _ctx: &Context, raw_input: &mut RawInput)

Adds keyboard events to raw input

Source

pub fn show(&mut self, ui: &mut Ui)

Add Keyboard to ui. Recommended to use in separate window or panel.

Source

pub fn layout_name(&self) -> String

Trait Implementations§

Source§

impl Clone for VirtualKeyboard

Source§

fn clone(&self) -> VirtualKeyboard

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VirtualKeyboard

Source§

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

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

impl Default for VirtualKeyboard

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for VirtualKeyboard

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for VirtualKeyboard

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,