generated from ElnuDev/rust-project
parent
5bdd3f6556
commit
d488b99765
File diff suppressed because it is too large
Load Diff
@ -1,49 +1,22 @@
|
||||
mod render;
|
||||
pub mod svg;
|
||||
|
||||
use svg::{SVGUnit, SVGMeasure};
|
||||
use sycamore::{prelude::*, view::ToView, builder::t};
|
||||
use leptos::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Default)]
|
||||
struct Color {
|
||||
red: u8,
|
||||
green: u8,
|
||||
blue: u8,
|
||||
}
|
||||
#[component]
|
||||
fn App(cx: Scope) -> impl IntoView {
|
||||
let (count, set_count) = create_signal(cx, 0);
|
||||
|
||||
impl<G: Html> ToView<G> for SVGUnit {
|
||||
fn to_view(&self) -> View<G> {
|
||||
t(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[component(inline_props)]
|
||||
fn Slider<'a, G: Html>(cx: Scope<'a>, value: &'a Signal<f64>, unit: Option<SVGUnit>) -> View<G> {
|
||||
view! { cx,
|
||||
div(class="f-row align-items:center") {
|
||||
span { (value.get())(unit) }
|
||||
input(type="range", bind:valueAsNumber=value)
|
||||
}
|
||||
<button on:click=move |_| set_count(count.get() + 1)>
|
||||
"Click me: "
|
||||
{move || count.get()}
|
||||
</button>
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
sycamore::render_to(
|
||||
|cx| {
|
||||
let x = create_signal(cx, 0.0);
|
||||
let y = create_signal(cx, 0.0);
|
||||
let z = create_signal(cx, 0.0);
|
||||
view! { cx,
|
||||
"Total: "(*x.get() + *y.get() + *z.get())
|
||||
Slider(value=x, unit=SVGUnit::Inch)
|
||||
Slider(value=y)
|
||||
Slider(value=z)
|
||||
}
|
||||
},
|
||||
{
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
&document.query_selector("main").unwrap().unwrap()
|
||||
},
|
||||
);
|
||||
}
|
||||
pub fn main() {
|
||||
let root = document().query_selector("main").unwrap().unwrap();
|
||||
mount_to(root.unchecked_into(), |cx| view! { cx, <App/> });
|
||||
}
|
Loading…
Reference in new issue