added component rendering and updated dioxus version

This commit is contained in:
Evan Almloff 2022-02-04 07:24:02 -06:00
parent 82b1735f25
commit e2f6d87d8e
6 changed files with 87 additions and 19 deletions

View file

@ -10,7 +10,7 @@ tui = { version = "0.16.0", features = ["crossterm"], default-features = false }
crossterm = "0.22.1"
anyhow = "1.0.42"
thiserror = "1.0.24"
dioxus = "0.1.7"
dioxus = "0.1.8"
hecs = "0.7.3"
ctrlc = "3.2.1"
bumpalo = { version = "3.8.0", features = ["boxed"] }

64
examples/components.rs Normal file
View 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()
}
}
}
})
}

View file

@ -9,7 +9,7 @@ fn main() {
}
fn app(cx: Scope) -> Element {
let count = use_state(&cx, || 0);
let (count, set_count) = use_state(&cx, || 0);
cx.render(rsx! {
div {
@ -25,10 +25,10 @@ fn app(cx: Scope) -> Element {
// onkeydown: move |evt: KeyEvent| {
// use crossterm::event::KeyCode::*;
// match evt.code {
// Left => count += 1,
// Right => count -= 1,
// Up => count += 10,
// Down => count -= 10,
// Left => set_count(count + 1),
// Right => set_count(count - 1),
// Up => set_count(count + 10),
// Down => set_count(count - 10),
// _ => {},
// }
// },
@ -42,7 +42,7 @@ fn app(cx: Scope) -> Element {
}
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! {
div {
@ -51,7 +51,7 @@ fn app2<'a>(cx: Scope<'a>) -> Element<'a> {
background_color: "red",
justify_content: "center",
align_items: "center",
oninput: move |_| count += 1,
oninput: move |_| set_count(count + 1),
"Hello world!",
h1 {},
}

View file

@ -5,17 +5,15 @@ fn main() {
}
fn app(cx: Scope) -> Element {
let count = use_state(&cx, || 0);
let (count, set_count) = use_state(&cx, || 0);
use_future(&cx, || {
let set_count = count.setter();
let mut mycount = 0;
use_future(&cx, move || {
let set_count = set_count.to_owned();
let update = cx.schedule_update();
async move {
loop {
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
mycount += 1;
set_count(mycount);
set_count.with_mut(|f| *f += 1);
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
update();
}
}

View file

@ -38,13 +38,13 @@ impl RinkContext {
#[derive(Props)]
pub struct AppHandlerProps<'a> {
// #[props(setter(strip_option), default)]
#[props(default)]
onkeydown: EventHandler<'a, KeyEvent>,
// #[props(setter(strip_option), default)]
#[props(default)]
onmousedown: EventHandler<'a, MouseEvent>,
#[props(setter(strip_option), default)]
#[props(default)]
onresize: Option<EventHandler<'a, (u16, u16)>>,
}

View file

@ -45,7 +45,13 @@ pub fn render_vnode<'a>(
}
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(_) => {}
}