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