wip: more examples
This commit is contained in:
1 parent
304259d818
commit
56e7eb83a9
21 files changed
+162
-236
No files matched your search
@@ -1,60 +0,0 @@
|
||||
fn main() {}
|
||||
|
||||
struct Title(String);
|
||||
|
||||
struct Position([f32; 3]);
|
||||
|
||||
struct Velocity([f32; 3]);
|
||||
|
||||
type Batch<T> = fn(&mut T) -> ();
|
||||
|
||||
static Atom: Batch<(Title, Position, Velocity)> = |_| {};
|
||||
|
||||
enum VNode<'a> {
|
||||
El(El<'a>),
|
||||
Text(&'a str),
|
||||
Fragment(&'a [VNode<'a>]),
|
||||
}
|
||||
struct El<'a> {
|
||||
name: &'static str,
|
||||
key: Option<&'a str>,
|
||||
attrs: &'a [(&'static str, AttrType<'a>)],
|
||||
children: &'a [El<'a>],
|
||||
}
|
||||
enum AttrType<'a> {
|
||||
Numeric(usize),
|
||||
Text(&'a str),
|
||||
}
|
||||
|
||||
fn example() {
|
||||
use AttrType::Numeric;
|
||||
let el = El {
|
||||
name: "div",
|
||||
attrs: &[("type", Numeric(10)), ("type", Numeric(10))],
|
||||
key: None,
|
||||
children: &[],
|
||||
};
|
||||
}
|
||||
|
||||
use dioxus::prelude::bumpalo::Bump;
|
||||
trait IntoVnode {
|
||||
fn into_vnode<'a>(self, b: &'a Bump) -> VNode<'a>;
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for VNode<'a> {
|
||||
type Item = VNode<'a>;
|
||||
type IntoIter = std::iter::Once<VNode<'a>>;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
std::iter::once(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn take_iterable<F: IntoVnode>(f: impl IntoIterator<Item = F>) {
|
||||
let iter = f.into_iter();
|
||||
let b = Bump::new();
|
||||
for f in iter {
|
||||
let v = f.into_vnode(&b);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
//! Example: README.md showcase
|
||||
//!
|
||||
//! The example from the README.md
|
||||
//! The example from the README.md.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
fn main() {
|
||||
dioxus::web::launch(App)
|
||||
dioxus::desktop::launch(App, |c| c);
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
@@ -12,7 +12,7 @@ static App: FC<()> = |cx| {
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
h1 { "Hifive counter: {count}" }
|
||||
h1 { "High-Five counter: {count}" }
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
//! We don't support building new webcomponents with Dioxus, however.
|
||||
//!
|
||||
|
||||
use dioxus::{builder::ElementBuilder, prelude::NodeFactory};
|
||||
|
||||
fn main() {}
|
||||
|
||||
mod dioxus_elements {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::ssr;
|
||||
|
||||
fn main() {
|
||||
let mut vdom = VirtualDom::new(App);
|
||||
vdom.rebuild_in_place();
|
||||
println!("{}", ssr::render_root(&vdom));
|
||||
}
|
||||
|
||||
const App: FC<()> = |cx| {
|
||||
cx.render(rsx!(
|
||||
div {
|
||||
h1 { "Title" }
|
||||
p { "Body" }
|
||||
}
|
||||
))
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
//
|
||||
cx.render(rsx!(
|
||||
div {
|
||||
h1 {}
|
||||
}
|
||||
))
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn blah() {}
|
||||
Reference in new issue
Block a user