Update examples to avoid deprecated API
This commit is contained in:
1 parent
aaf9d4665f
commit
45980f9a1e
9 files changed
+25
-26
No files matched your search
@@ -204,7 +204,6 @@ fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent {
|
|||||||
fn ctrl_key(&self) -> bool { self.0.ctrl_key() }
|
fn ctrl_key(&self) -> bool { self.0.ctrl_key() }
|
||||||
fn key(&self) -> String { self.0.key() }
|
fn key(&self) -> String { self.0.key() }
|
||||||
fn key_code(&self) -> usize { self.0.key_code() }
|
fn key_code(&self) -> usize { self.0.key_code() }
|
||||||
fn locale(&self) -> String { self.0.locale() }
|
|
||||||
fn location(&self) -> usize { self.0.location() }
|
fn location(&self) -> usize { self.0.location() }
|
||||||
fn meta_key(&self) -> bool { self.0.meta_key() }
|
fn meta_key(&self) -> bool { self.0.meta_key() }
|
||||||
fn repeat(&self) -> bool { self.0.repeat() }
|
fn repeat(&self) -> bool { self.0.repeat() }
|
||||||
|
|||||||
@@ -206,7 +206,6 @@ fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent {
|
|||||||
ctrl_key: event.ctrl_key(),
|
ctrl_key: event.ctrl_key(),
|
||||||
meta_key: event.meta_key(),
|
meta_key: event.meta_key(),
|
||||||
shift_key: event.shift_key(),
|
shift_key: event.shift_key(),
|
||||||
locale: "".to_string(),
|
|
||||||
location: event.location(),
|
location: event.location(),
|
||||||
repeat: event.repeat(),
|
repeat: event.repeat(),
|
||||||
which: event.which(),
|
which: event.which(),
|
||||||
|
|||||||
+21
-16
@@ -20,6 +20,7 @@
|
|||||||
use dioxus::desktop::wry::application::dpi::LogicalSize;
|
use dioxus::desktop::wry::application::dpi::LogicalSize;
|
||||||
use dioxus::events::*;
|
use dioxus::events::*;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_html::input_data::keyboard_types::Key;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dioxus::desktop::launch_cfg(app, |cfg| {
|
dioxus::desktop::launch_cfg(app, |cfg| {
|
||||||
@@ -212,22 +213,26 @@ impl Calculator {
|
|||||||
self.waiting_for_operand = true;
|
self.waiting_for_operand = true;
|
||||||
}
|
}
|
||||||
fn handle_keydown(&mut self, evt: KeyboardEvent) {
|
fn handle_keydown(&mut self, evt: KeyboardEvent) {
|
||||||
match evt.key_code {
|
match evt.key() {
|
||||||
KeyCode::Backspace => self.backspace(),
|
Key::Backspace => self.backspace(),
|
||||||
KeyCode::Num0 => self.input_digit(0),
|
Key::Character(c) => match c.as_str() {
|
||||||
KeyCode::Num1 => self.input_digit(1),
|
"0" => self.input_digit(0),
|
||||||
KeyCode::Num2 => self.input_digit(2),
|
"1" => self.input_digit(1),
|
||||||
KeyCode::Num3 => self.input_digit(3),
|
"2" => self.input_digit(2),
|
||||||
KeyCode::Num4 => self.input_digit(4),
|
"3" => self.input_digit(3),
|
||||||
KeyCode::Num5 => self.input_digit(5),
|
"4" => self.input_digit(4),
|
||||||
KeyCode::Num6 => self.input_digit(6),
|
"5" => self.input_digit(5),
|
||||||
KeyCode::Num7 => self.input_digit(7),
|
"6" => self.input_digit(6),
|
||||||
KeyCode::Num8 => self.input_digit(8),
|
"7" => self.input_digit(7),
|
||||||
KeyCode::Num9 => self.input_digit(9),
|
"8" => self.input_digit(8),
|
||||||
KeyCode::Add => self.operator = Some(Operator::Add),
|
"9" => self.input_digit(9),
|
||||||
KeyCode::Subtract => self.operator = Some(Operator::Sub),
|
"+" => self.operator = Some(Operator::Add),
|
||||||
KeyCode::Divide => self.operator = Some(Operator::Div),
|
"-" => self.operator = Some(Operator::Sub),
|
||||||
KeyCode::Multiply => self.operator = Some(Operator::Mul),
|
"/" => self.operator = Some(Operator::Div),
|
||||||
|
"*" => self.operator = Some(Operator::Mul),
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -1,4 +1,5 @@
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_elements::input_data::keyboard_types::Key;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dioxus::desktop::launch(app);
|
dioxus::desktop::launch(app);
|
||||||
@@ -56,7 +57,7 @@ pub fn app(cx: Scope<()>) -> Element {
|
|||||||
autofocus: "true",
|
autofocus: "true",
|
||||||
oninput: move |evt| draft.set(evt.value.clone()),
|
oninput: move |evt| draft.set(evt.value.clone()),
|
||||||
onkeydown: move |evt| {
|
onkeydown: move |evt| {
|
||||||
if evt.key == "Enter" && !draft.is_empty() {
|
if evt.key() == Key::Enter && !draft.is_empty() {
|
||||||
todos.make_mut().insert(
|
todos.make_mut().insert(
|
||||||
**todo_id,
|
**todo_id,
|
||||||
TodoItem {
|
TodoItem {
|
||||||
@@ -148,8 +149,8 @@ pub fn todo_entry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
|||||||
autofocus: "true",
|
autofocus: "true",
|
||||||
onfocusout: move |_| is_editing.set(false),
|
onfocusout: move |_| is_editing.set(false),
|
||||||
onkeydown: move |evt| {
|
onkeydown: move |evt| {
|
||||||
match evt.key.as_str() {
|
match evt.key() {
|
||||||
"Enter" | "Escape" | "Tab" => is_editing.set(false),
|
Key::Enter | Key::Escape | Key::Tab => is_editing.set(false),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use dioxus_html::geometry::ScreenPoint;
|
|||||||
use dioxus_html::input_data::keyboard_types::Code;
|
use dioxus_html::input_data::keyboard_types::Code;
|
||||||
use dioxus_html::input_data::MouseButtonSet;
|
use dioxus_html::input_data::MouseButtonSet;
|
||||||
use dioxus_html::on::{KeyboardEvent, MouseEvent};
|
use dioxus_html::on::{KeyboardEvent, MouseEvent};
|
||||||
use dioxus_html::KeyCode;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dioxus::tui::launch(app);
|
dioxus::tui::launch(app);
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ impl From<&KeyboardEvent> for KeyboardData {
|
|||||||
key: e.key(),
|
key: e.key(),
|
||||||
key_code: KeyCode::from_raw_code(e.key_code() as u8),
|
key_code: KeyCode::from_raw_code(e.key_code() as u8),
|
||||||
ctrl_key: e.ctrl_key(),
|
ctrl_key: e.ctrl_key(),
|
||||||
locale: "not implemented".to_string(),
|
|
||||||
location: e.location() as usize,
|
location: e.location() as usize,
|
||||||
meta_key: e.meta_key(),
|
meta_key: e.meta_key(),
|
||||||
repeat: e.repeat(),
|
repeat: e.repeat(),
|
||||||
|
|||||||
@@ -347,7 +347,6 @@ export function serialize_event(event) {
|
|||||||
location: location,
|
location: location,
|
||||||
repeat: repeat,
|
repeat: repeat,
|
||||||
which: which,
|
which: which,
|
||||||
locale: "locale",
|
|
||||||
code,
|
code,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,7 +358,6 @@ function serialize_event(event) {
|
|||||||
location: location,
|
location: location,
|
||||||
repeat: repeat,
|
repeat: repeat,
|
||||||
which: which,
|
which: which,
|
||||||
locale: "locale",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case "focus":
|
case "focus":
|
||||||
|
|||||||
@@ -521,7 +521,6 @@ fn virtual_event_from_websys_event(event: web_sys::Event) -> Arc<dyn Any + Send
|
|||||||
key: evt.key(),
|
key: evt.key(),
|
||||||
key_code: KeyCode::from_raw_code(evt.key_code() as u8),
|
key_code: KeyCode::from_raw_code(evt.key_code() as u8),
|
||||||
ctrl_key: evt.ctrl_key(),
|
ctrl_key: evt.ctrl_key(),
|
||||||
locale: "not implemented".to_string(),
|
|
||||||
location: evt.location() as usize,
|
location: evt.location() as usize,
|
||||||
meta_key: evt.meta_key(),
|
meta_key: evt.meta_key(),
|
||||||
repeat: evt.repeat(),
|
repeat: evt.repeat(),
|
||||||
|
|||||||
Reference in new issue
Block a user