port examples to new events
This commit is contained in:
1 parent
dee92b83be
commit
df222c121a
25 files changed
+55
-41
No files matched your search
@@ -1,7 +1,7 @@
|
||||
// todo remove deprecated
|
||||
#![allow(non_snake_case, deprecated)]
|
||||
|
||||
use dioxus::events::{KeyCode, KeyboardEvent};
|
||||
use dioxus::events::KeyboardEvent;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_tui::TuiContext;
|
||||
|
||||
@@ -26,7 +26,7 @@ fn App(cx: Scope) -> Element {
|
||||
background_color: "red",
|
||||
justify_content: "center",
|
||||
align_items: "center",
|
||||
onkeydown: move |k: KeyboardEvent| if let KeyCode::Q = k.key_code {
|
||||
onkeydown: move |k: KeyboardEvent| if let Code::KeyQ = k.code() {
|
||||
tui_ctx.quit();
|
||||
},
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ fn App(cx: Scope) -> Element {
|
||||
// we tell the component what to render
|
||||
value: "{name}",
|
||||
// and what to do when the value changes
|
||||
oninput: move |evt| name.set(evt.value.clone()),
|
||||
oninput: move |evt| name.set(evt.value()),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ fn MemeEditor(cx: Scope) -> Element {
|
||||
},
|
||||
CaptionEditor {
|
||||
caption: caption,
|
||||
on_input: move |event: FormEvent| {caption.set(event.value.clone());},
|
||||
on_input: move |event: FormEvent| {caption.set(event.value());},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -62,7 +62,7 @@ pub fn DarkModeToggle(cx: Scope) -> Element {
|
||||
input {
|
||||
r#type: "checkbox",
|
||||
oninput: move |event| {
|
||||
let is_enabled = event.value == "true";
|
||||
let is_enabled = event.value() == "true";
|
||||
dark_mode.write().0 = is_enabled;
|
||||
},
|
||||
},
|
||||
@@ -97,7 +97,7 @@ fn MemeEditor(cx: Scope) -> Element {
|
||||
},
|
||||
CaptionEditor {
|
||||
caption: caption,
|
||||
on_input: move |event: FormEvent| {caption.set(event.value.clone());},
|
||||
on_input: move |event: FormEvent| {caption.set(event.value().clone());},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -40,7 +40,7 @@ cx.render(rsx!(
|
||||
},
|
||||
input {
|
||||
value: "{comment_field}",
|
||||
oninput: |event| comment_field.set(event.value.clone()),
|
||||
oninput: |event| comment_field.set(event.value()),
|
||||
}
|
||||
input {
|
||||
r#type: "submit",
|
||||
@@ -71,7 +71,7 @@ cx.render(rsx!(
|
||||
},
|
||||
input {
|
||||
value: "{comment_field}",
|
||||
oninput: |event| comment_field.set(event.value.clone()),
|
||||
oninput: |event| comment_field.set(event.value()),
|
||||
}
|
||||
input {
|
||||
r#type: "submit",
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ fn compose(cx: Scope<ComposeProps>) -> Element {
|
||||
|
||||
input {
|
||||
oninput: move |e| {
|
||||
user_input.set(e.value.clone());
|
||||
user_input.set(e.value());
|
||||
},
|
||||
value: "{user_input}"
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ fn app(cx: Scope) -> Element {
|
||||
input {
|
||||
value: "{counter}",
|
||||
oninput: move |e| {
|
||||
if let Ok(value) = e.value.parse::<usize>() {
|
||||
if let Ok(value) = e.value().parse::<usize>() {
|
||||
counters.make_mut()[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -119,7 +119,7 @@ fn ClientAdd(cx: Scope) -> Element {
|
||||
placeholder: "First Name…",
|
||||
required: "",
|
||||
value: "{first_name}",
|
||||
oninput: move |e| first_name.set(e.value.clone())
|
||||
oninput: move |e| first_name.set(e.value())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ fn ClientAdd(cx: Scope) -> Element {
|
||||
placeholder: "Last Name…",
|
||||
required: "",
|
||||
value: "{last_name}",
|
||||
oninput: move |e| last_name.set(e.value.clone())
|
||||
oninput: move |e| last_name.set(e.value())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ fn ClientAdd(cx: Scope) -> Element {
|
||||
id: "description",
|
||||
placeholder: "Description…",
|
||||
value: "{description}",
|
||||
oninput: move |e| description.set(e.value.clone())
|
||||
oninput: move |e| description.set(e.value())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ fn App(cx: Scope) -> Element {
|
||||
r#type: "checkbox",
|
||||
checked: "{enable_directory_upload}",
|
||||
oninput: move |evt| {
|
||||
enable_directory_upload.set(evt.value.parse().unwrap());
|
||||
enable_directory_upload.set(evt.value().parse().unwrap());
|
||||
},
|
||||
},
|
||||
"Enable directory upload"
|
||||
@@ -30,7 +30,7 @@ fn App(cx: Scope) -> Element {
|
||||
onchange: |evt| {
|
||||
to_owned![files_uploaded];
|
||||
async move {
|
||||
if let Some(file_engine) = &evt.files {
|
||||
if let Some(file_engine) = &evt.files() {
|
||||
let files = file_engine.files();
|
||||
for file_name in files {
|
||||
sleep(std::time::Duration::from_secs(1)).await;
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ fn app(cx: Scope) -> Element {
|
||||
div {
|
||||
h1 { "Form" }
|
||||
form {
|
||||
onsubmit: move |ev| println!("Submitted {:?}", ev.values),
|
||||
oninput: move |ev| println!("Input {:?}", ev.values),
|
||||
onsubmit: move |ev| println!("Submitted {:?}", ev.values()),
|
||||
oninput: move |ev| println!("Input {:?}", ev.values()),
|
||||
input { r#type: "text", name: "username" }
|
||||
input { r#type: "text", name: "full-name" }
|
||||
input { r#type: "password", name: "password" }
|
||||
|
||||
@@ -13,8 +13,8 @@ fn app(cx: Scope) -> Element {
|
||||
let resp = reqwest::Client::new()
|
||||
.post("http://localhost:8080/login")
|
||||
.form(&[
|
||||
("username", &evt.values["username"]),
|
||||
("password", &evt.values["password"]),
|
||||
("username", &evt.values()["username"]),
|
||||
("password", &evt.values()["password"]),
|
||||
])
|
||||
.send()
|
||||
.await;
|
||||
|
||||
@@ -65,7 +65,7 @@ fn DataEditor(cx: Scope, id: usize) -> Element {
|
||||
fn DataView(cx: Scope, id: usize) -> Element {
|
||||
let cool_data = use_shared_state::<CoolData>(cx).unwrap();
|
||||
|
||||
let oninput = |e: FormEvent| cool_data.write().set(*id, e.value.clone());
|
||||
let oninput = |e: FormEvent| cool_data.write().set(*id, e.value());
|
||||
|
||||
let cool_data = cool_data.read();
|
||||
let my_data = &cool_data.view(id).unwrap();
|
||||
|
||||
@@ -17,7 +17,7 @@ fn app(cx: Scope) -> Element {
|
||||
rows: "10",
|
||||
cols: "80",
|
||||
value: "{model}",
|
||||
oninput: move |e| model.set(e.value.clone()),
|
||||
oninput: move |e| model.set(e.value().clone()),
|
||||
}
|
||||
})
|
||||
}
|
||||
+3
-3
@@ -66,7 +66,7 @@ pub fn app(cx: Scope<()>) -> Element {
|
||||
value: "{draft}",
|
||||
autofocus: "true",
|
||||
oninput: move |evt| {
|
||||
draft.set(evt.value.clone());
|
||||
draft.set(evt.value());
|
||||
},
|
||||
onkeydown: move |evt| {
|
||||
if evt.key() == Key::Enter && !draft.is_empty() {
|
||||
@@ -176,7 +176,7 @@ pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
||||
id: "cbg-{todo.id}",
|
||||
checked: "{todo.checked}",
|
||||
oninput: move |evt| {
|
||||
cx.props.todos.make_mut()[&cx.props.id].checked = evt.value.parse().unwrap();
|
||||
cx.props.todos.make_mut()[&cx.props.id].checked = evt.value().parse().unwrap();
|
||||
}
|
||||
}
|
||||
label {
|
||||
@@ -195,7 +195,7 @@ pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
||||
input {
|
||||
class: "edit",
|
||||
value: "{todo.contents}",
|
||||
oninput: move |evt| cx.props.todos.make_mut()[&cx.props.id].contents = evt.value.clone(),
|
||||
oninput: move |evt| cx.props.todos.make_mut()[&cx.props.id].contents = evt.value(),
|
||||
autofocus: "true",
|
||||
onfocusout: move |_| is_editing.set(false),
|
||||
onkeydown: move |evt| {
|
||||
|
||||
@@ -14,7 +14,7 @@ fn app(cx: Scope) -> Element {
|
||||
r#type: "number",
|
||||
value: "{level}",
|
||||
oninput: |e| {
|
||||
if let Ok(new_zoom) = e.value.parse::<f64>() {
|
||||
if let Ok(new_zoom) = e.value().parse::<f64>() {
|
||||
level.set(new_zoom);
|
||||
window.webview.zoom(new_zoom);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ fn app(cx: Scope) -> Element {
|
||||
input {
|
||||
value: "{contents}",
|
||||
r#type: "text",
|
||||
oninput: move |e| contents.set(e.value.clone()),
|
||||
oninput: move |e| contents.set(e.value()),
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -78,7 +78,7 @@ toml_edit = "0.19.11"
|
||||
# dioxus-rsx = "0.0.1"
|
||||
|
||||
# bundling
|
||||
tauri-bundler = { version = "1.2", features = ["native-tls-vendored"] }
|
||||
tauri-bundler = { version = "=1.2", features = ["native-tls-vendored"] }
|
||||
tauri-utils = "1.3"
|
||||
|
||||
dioxus-autofmt = { workspace = true }
|
||||
|
||||
@@ -56,7 +56,14 @@ fn events_generate() {
|
||||
let mut dom = VirtualDom::new(app);
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.handle_event("click", Rc::new(MouseData::default()), ElementId(1), true);
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(PlatformEventData::new(Box::new(MouseData::new(
|
||||
SerializedMouseData::default(),
|
||||
)))),
|
||||
ElementId(1),
|
||||
true,
|
||||
);
|
||||
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
let edits = dom.render_immediate();
|
||||
|
||||
@@ -9,7 +9,14 @@ fn miri_rollover() {
|
||||
_ = dom.rebuild();
|
||||
|
||||
for _ in 0..3 {
|
||||
dom.handle_event("click", Rc::new(MouseData::default()), ElementId(2), true);
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(PlatformEventData::new(Box::new(MouseData::new(
|
||||
SerializedMouseData::default(),
|
||||
)))),
|
||||
ElementId(2),
|
||||
true,
|
||||
);
|
||||
dom.process_events();
|
||||
_ = dom.render_immediate();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ fn suspended_child(cx: Scope) -> Element {
|
||||
cx.spawn(async move {
|
||||
val += 1;
|
||||
});
|
||||
return cx.suspend()?;
|
||||
cx.suspend()?;
|
||||
}
|
||||
|
||||
render!("child")
|
||||
|
||||
@@ -304,7 +304,7 @@ fn app(cx: Scope) -> Element {
|
||||
assert!(event.data.modifiers().is_empty());
|
||||
assert_eq!(event.data.key().to_string(), "a");
|
||||
assert_eq!(event.data.code().to_string(), "KeyA");
|
||||
assert_eq!(event.data.location, 0);
|
||||
assert_eq!(event.data.location(), Location::Standard);
|
||||
assert!(event.data.is_auto_repeating());
|
||||
|
||||
recieved_events.modify(|x| *x + 1)
|
||||
@@ -317,7 +317,7 @@ fn app(cx: Scope) -> Element {
|
||||
assert!(event.data.modifiers().is_empty());
|
||||
assert_eq!(event.data.key().to_string(), "a");
|
||||
assert_eq!(event.data.code().to_string(), "KeyA");
|
||||
assert_eq!(event.data.location, 0);
|
||||
assert_eq!(event.data.location(), Location::Standard);
|
||||
assert!(!event.data.is_auto_repeating());
|
||||
|
||||
recieved_events.modify(|x| *x + 1)
|
||||
@@ -330,7 +330,7 @@ fn app(cx: Scope) -> Element {
|
||||
assert!(event.data.modifiers().is_empty());
|
||||
assert_eq!(event.data.key().to_string(), "a");
|
||||
assert_eq!(event.data.code().to_string(), "KeyA");
|
||||
assert_eq!(event.data.location, 0);
|
||||
assert_eq!(event.data.location(), Location::Standard);
|
||||
assert!(!event.data.is_auto_repeating());
|
||||
|
||||
recieved_events.modify(|x| *x + 1)
|
||||
|
||||
@@ -18,7 +18,7 @@ fn app(cx: Scope) -> Element {
|
||||
justify_content: "center",
|
||||
|
||||
input {
|
||||
oninput: |data| if &data.value == "good"{
|
||||
oninput: |data| if &data.value()== "good"{
|
||||
bg_green.set(true);
|
||||
} else{
|
||||
bg_green.set(false);
|
||||
@@ -30,7 +30,7 @@ fn app(cx: Scope) -> Element {
|
||||
checked: "true",
|
||||
}
|
||||
input {
|
||||
oninput: |data| if &data.value == "hello world"{
|
||||
oninput: |data| if &data.value()== "hello world"{
|
||||
bg_green.set(true);
|
||||
} else{
|
||||
bg_green.set(false);
|
||||
@@ -41,7 +41,7 @@ fn app(cx: Scope) -> Element {
|
||||
}
|
||||
input {
|
||||
oninput: |data| {
|
||||
if (data.value.parse::<f32>().unwrap() - 40.0).abs() < 5.0 {
|
||||
if (data.value().parse::<f32>().unwrap() - 40.0).abs() < 5.0 {
|
||||
bg_green.set(true);
|
||||
} else{
|
||||
bg_green.set(false);
|
||||
@@ -55,7 +55,7 @@ fn app(cx: Scope) -> Element {
|
||||
}
|
||||
input {
|
||||
oninput: |data| {
|
||||
if data.value == "10"{
|
||||
if data.value()== "10"{
|
||||
bg_green.set(true);
|
||||
} else{
|
||||
bg_green.set(false);
|
||||
@@ -68,7 +68,7 @@ fn app(cx: Scope) -> Element {
|
||||
}
|
||||
input {
|
||||
oninput: |data| {
|
||||
if data.value == "hello world"{
|
||||
if data.value()== "hello world"{
|
||||
bg_green.set(true);
|
||||
} else{
|
||||
bg_green.set(false);
|
||||
|
||||
@@ -46,5 +46,5 @@ pub mod prelude {
|
||||
pub use crate::eval::*;
|
||||
pub use crate::events::*;
|
||||
pub use crate::point_interaction::PointInteraction;
|
||||
pub use keyboard_types::{self, Code, Key, Modifiers};
|
||||
pub use keyboard_types::{self, Code, Key, Location, Modifiers};
|
||||
}
|
||||
@@ -225,7 +225,7 @@ impl EventData {
|
||||
fn test_back_and_forth() {
|
||||
let data = HtmlEvent {
|
||||
element: ElementId(0),
|
||||
data: EventData::Mouse(SerializedMouseData::default().into()),
|
||||
data: EventData::Mouse(SerializedMouseData::default()),
|
||||
name: "click".to_string(),
|
||||
bubbles: true,
|
||||
};
|
||||
|
||||
@@ -80,7 +80,7 @@ fn Route3(cx: Scope, dynamic: String) -> Element {
|
||||
render! {
|
||||
input {
|
||||
oninput: move |evt| {
|
||||
*current_route_str.write() = evt.value.clone();
|
||||
*current_route_str.write() = evt.value();
|
||||
},
|
||||
value: "{current_route_str.read()}"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user