embedded_ui/kit/virtual_keyboard.rs
1// use crate::{
2// el::ElId,
3// event::Event,
4// layout::{Layout, Viewport},
5// render::Renderer,
6// size::{Length, Size},
7// widget::Widget,
8// };
9
10// #[derive(Clone, Copy)]
11// enum KeyAction {
12// CaseToggle,
13// Enter,
14// Char(char),
15// }
16
17// macro_rules! keyboard_layout {
18// (@key $key: ident) => {
19// KeyAction::$key
20// };
21
22// (@key $key: literal) => {
23// KeyAction::Char($key)
24// };
25
26// ($([$($key: tt),* $(,)?]),* $(,)?) => [
27// &[
28// $(
29// &[$(keyboard_layout!(@key $key)),*]
30// ),*
31// ]
32// ];
33// }
34
35// const KEYBOARD_LAYOUT: &[&[KeyAction]] = keyboard_layout![
36// ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
37// ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
38// ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';'],
39// ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'],
40// ];
41
42// pub struct VirtualKeyboard<'a, Message> {
43// id: ElId,
44// size: Size<Length>,
45// on_char: Box<dyn Fn(char) -> Message + 'a>,
46// }
47
48// impl<'a, Message> VirtualKeyboard<'a, Message> {
49// pub fn new<F>(on_char: F) -> Self
50// where
51// F: Fn(char) -> Message + 'a,
52// {
53// Self { id: ElId::unique(), size: Size::fill(), on_char: Box::new(on_char) }
54// }
55// }
56
57// impl<'a, Message, R, E, S> Widget<Message, R, E, S> for VirtualKeyboard<'a, Message>
58// where
59// R: Renderer,
60// E: Event,
61// {
62// fn id(&self) -> Option<crate::el::ElId> {
63// Some(self.id)
64// }
65
66// fn tree_ids(&self) -> Vec<crate::el::ElId> {
67// vec![]
68// }
69
70// fn size(&self) -> Size<Length> {
71// Size::fill()
72// }
73
74// fn position(&self) -> crate::layout::Position {
75// crate::layout::Position::Absolute
76// }
77
78// fn layout(
79// &self,
80// ctx: &mut crate::ui::UiCtx<Message>,
81// state: &mut crate::state::StateNode,
82// styler: &S,
83// limits: &crate::layout::Limits,
84// viewport: &Viewport,
85// ) -> crate::layout::LayoutNode {
86// Layout::flex(ctx, state, styler, axis, limits, size, position, viewport, padding, gap, align, children)
87// }
88
89// fn draw(
90// &self,
91// ctx: &mut crate::ui::UiCtx<Message>,
92// state: &mut crate::state::StateNode,
93// renderer: &mut R,
94// styler: &S,
95// layout: crate::layout::Layout,
96// ) {
97// todo!()
98// }
99// }