colorpicker.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. use dioxus::dioxus_core::RenderReturn;
  2. use dioxus::prelude::*;
  3. use dioxus_tui::DioxusElementToNodeId;
  4. use dioxus_tui::Query;
  5. use dioxus_tui::Size;
  6. fn main() {
  7. dioxus_tui::launch(app);
  8. }
  9. fn app() -> Element {
  10. let mut hue = use_signal(|| 0.0);
  11. let mut brightness = use_signal(|| 0.0);
  12. let tui_query: Query = consume_context();
  13. let mapping: DioxusElementToNodeId = consume_context();
  14. // disable templates so that every node has an id and can be queried
  15. rsx! {
  16. div {
  17. width: "100%",
  18. background_color: "hsl({hue}, 70%, {brightness}%)",
  19. onmousemove: move |evt| {
  20. todo!()
  21. // if let RenderReturn::Ready(node) = root_node() {
  22. // if let Some(id) = node.root_ids.borrow().first().cloned() {
  23. // let node = tui_query.get(mapping.get_node_id(id).unwrap());
  24. // let Size { width, height } = node.size().unwrap();
  25. // let pos = evt.inner().element_coordinates();
  26. // hue.set((pos.x as f32 / width as f32) * 255.0);
  27. // brightness.set((pos.y as f32 / height as f32) * 100.0);
  28. // }
  29. // }
  30. },
  31. "hsl({hue}, 70%, {brightness}%)"
  32. }
  33. }
  34. }