mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-14 16:37:14 +00:00
added component rendering and updated dioxus version
This commit is contained in:
parent
82b1735f25
commit
e2f6d87d8e
6 changed files with 87 additions and 19 deletions
|
@ -10,7 +10,7 @@ tui = { version = "0.16.0", features = ["crossterm"], default-features = false }
|
||||||
crossterm = "0.22.1"
|
crossterm = "0.22.1"
|
||||||
anyhow = "1.0.42"
|
anyhow = "1.0.42"
|
||||||
thiserror = "1.0.24"
|
thiserror = "1.0.24"
|
||||||
dioxus = "0.1.7"
|
dioxus = "0.1.8"
|
||||||
hecs = "0.7.3"
|
hecs = "0.7.3"
|
||||||
ctrlc = "3.2.1"
|
ctrlc = "3.2.1"
|
||||||
bumpalo = { version = "3.8.0", features = ["boxed"] }
|
bumpalo = { version = "3.8.0", features = ["boxed"] }
|
||||||
|
|
64
examples/components.rs
Normal file
64
examples/components.rs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
rink::launch(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Props, PartialEq)]
|
||||||
|
struct QuadrentProps {
|
||||||
|
color: String,
|
||||||
|
text: String
|
||||||
|
}
|
||||||
|
|
||||||
|
fn Quadrent(cx: Scope<QuadrentProps>) -> Element{
|
||||||
|
cx.render(rsx! {
|
||||||
|
div {
|
||||||
|
border_width: "1px",
|
||||||
|
width: "50%",
|
||||||
|
height: "100%",
|
||||||
|
background_color: "{cx.props.color}",
|
||||||
|
justify_content: "center",
|
||||||
|
align_items: "center",
|
||||||
|
|
||||||
|
"{cx.props.text}"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn app(cx: Scope) -> Element {
|
||||||
|
cx.render(rsx! {
|
||||||
|
div {
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
flex_direction: "column",
|
||||||
|
|
||||||
|
div {
|
||||||
|
width: "100%",
|
||||||
|
height: "50%",
|
||||||
|
flex_direction: "row",
|
||||||
|
Quadrent{
|
||||||
|
color: "red".to_string(),
|
||||||
|
text: "[A]".to_string()
|
||||||
|
},
|
||||||
|
Quadrent{
|
||||||
|
color: "black".to_string(),
|
||||||
|
text: "[B]".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
width: "100%",
|
||||||
|
height: "50%",
|
||||||
|
flex_direction: "row",
|
||||||
|
Quadrent{
|
||||||
|
color: "green".to_string(),
|
||||||
|
text: "[C]".to_string()
|
||||||
|
},
|
||||||
|
Quadrent{
|
||||||
|
color: "blue".to_string(),
|
||||||
|
text: "[D]".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
let count = use_state(&cx, || 0);
|
let (count, set_count) = use_state(&cx, || 0);
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div {
|
div {
|
||||||
|
@ -25,10 +25,10 @@ fn app(cx: Scope) -> Element {
|
||||||
// onkeydown: move |evt: KeyEvent| {
|
// onkeydown: move |evt: KeyEvent| {
|
||||||
// use crossterm::event::KeyCode::*;
|
// use crossterm::event::KeyCode::*;
|
||||||
// match evt.code {
|
// match evt.code {
|
||||||
// Left => count += 1,
|
// Left => set_count(count + 1),
|
||||||
// Right => count -= 1,
|
// Right => set_count(count - 1),
|
||||||
// Up => count += 10,
|
// Up => set_count(count + 10),
|
||||||
// Down => count -= 10,
|
// Down => set_count(count - 10),
|
||||||
// _ => {},
|
// _ => {},
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
|
@ -42,7 +42,7 @@ fn app(cx: Scope) -> Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app2<'a>(cx: Scope<'a>) -> Element<'a> {
|
fn app2<'a>(cx: Scope<'a>) -> Element<'a> {
|
||||||
let mut count = use_state(&cx, || 0);
|
let (count, set_count) = use_state(&cx, || 0);
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div {
|
div {
|
||||||
|
@ -51,7 +51,7 @@ fn app2<'a>(cx: Scope<'a>) -> Element<'a> {
|
||||||
background_color: "red",
|
background_color: "red",
|
||||||
justify_content: "center",
|
justify_content: "center",
|
||||||
align_items: "center",
|
align_items: "center",
|
||||||
oninput: move |_| count += 1,
|
oninput: move |_| set_count(count + 1),
|
||||||
"Hello world!",
|
"Hello world!",
|
||||||
h1 {},
|
h1 {},
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,15 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
let count = use_state(&cx, || 0);
|
let (count, set_count) = use_state(&cx, || 0);
|
||||||
|
|
||||||
use_future(&cx, || {
|
use_future(&cx, move || {
|
||||||
let set_count = count.setter();
|
let set_count = set_count.to_owned();
|
||||||
let mut mycount = 0;
|
|
||||||
let update = cx.schedule_update();
|
let update = cx.schedule_update();
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
set_count.with_mut(|f| *f += 1);
|
||||||
mycount += 1;
|
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
|
||||||
set_count(mycount);
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,13 +38,13 @@ impl RinkContext {
|
||||||
|
|
||||||
#[derive(Props)]
|
#[derive(Props)]
|
||||||
pub struct AppHandlerProps<'a> {
|
pub struct AppHandlerProps<'a> {
|
||||||
// #[props(setter(strip_option), default)]
|
#[props(default)]
|
||||||
onkeydown: EventHandler<'a, KeyEvent>,
|
onkeydown: EventHandler<'a, KeyEvent>,
|
||||||
|
|
||||||
// #[props(setter(strip_option), default)]
|
#[props(default)]
|
||||||
onmousedown: EventHandler<'a, MouseEvent>,
|
onmousedown: EventHandler<'a, MouseEvent>,
|
||||||
|
|
||||||
#[props(setter(strip_option), default)]
|
#[props(default)]
|
||||||
onresize: Option<EventHandler<'a, (u16, u16)>>,
|
onresize: Option<EventHandler<'a, (u16, u16)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,13 @@ pub fn render_vnode<'a>(
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VNode::Component(_) => todo!(),
|
|
||||||
|
VNode::Component(vcomp) => {
|
||||||
|
let idx = vcomp.scope.get().unwrap();
|
||||||
|
let new_node = vdom.get_scope(idx).unwrap().root_node();
|
||||||
|
render_vnode(frame, layout, layouts, vdom, new_node);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
VNode::Placeholder(_) | VNode::Element(_) | VNode::Text(_) => {}
|
VNode::Placeholder(_) | VNode::Element(_) | VNode::Text(_) => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue