update color picker example
This commit is contained in:
1 parent
57ef56511c
commit
f10d47b53d
1 file changed
+10
-8
@@ -1,5 +1,5 @@
|
|||||||
use dioxus::core_macro::rsx_without_templates;
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
use dioxus::core::RenderReturn;
|
||||||
use dioxus_tui::query::Query;
|
use dioxus_tui::query::Query;
|
||||||
use dioxus_tui::Size;
|
use dioxus_tui::Size;
|
||||||
|
|
||||||
@@ -10,18 +10,20 @@ fn main() {
|
|||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
let hue = use_state(&cx, || 0.0);
|
let hue = use_state(&cx, || 0.0);
|
||||||
let brightness = use_state(&cx, || 0.0);
|
let brightness = use_state(&cx, || 0.0);
|
||||||
let tui_query: Query = cx.consume_context().unwrap();
|
let tui_query: &Query = cx.consume_context().unwrap();
|
||||||
// disable templates so that every node has an id and can be queried
|
// disable templates so that every node has an id and can be queried
|
||||||
cx.render(rsx_without_templates! {
|
cx.render(rsx! {
|
||||||
div{
|
div{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
background_color: "hsl({hue}, 70%, {brightness}%)",
|
background_color: "hsl({hue}, 70%, {brightness}%)",
|
||||||
onmousemove: move |evt| {
|
onmousemove: move |evt| {
|
||||||
let node = tui_query.get(cx.root_node().mounted_id());
|
if let RenderReturn::Sync(Ok(node))=cx.root_node(){
|
||||||
let Size{width, height} = node.size().unwrap();
|
let node = tui_query.get(node.root_ids[0].get());
|
||||||
let pos = evt.data.element_coordinates();
|
let Size{width, height} = node.size().unwrap();
|
||||||
hue.set((pos.x as f32/width as f32)*255.0);
|
let pos = evt.inner().element_coordinates();
|
||||||
brightness.set((pos.y as f32/height as f32)*100.0);
|
hue.set((pos.x as f32/width as f32)*255.0);
|
||||||
|
brightness.set((pos.y as f32/height as f32)*100.0);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"hsl({hue}, 70%, {brightness}%)",
|
"hsl({hue}, 70%, {brightness}%)",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user