fix color picker example
This commit is contained in:
1 parent
db04550fc8
commit
d8da8e4275
2 files changed
+15
-7
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
use dioxus::core::RenderReturn;
|
use dioxus::core::RenderReturn;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use dioxus_tui::query::Query;
|
use dioxus_tui::query::Query;
|
||||||
|
use dioxus_tui::DioxusElementToNodeId;
|
||||||
use dioxus_tui::Size;
|
use dioxus_tui::Size;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -11,6 +12,7 @@ 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();
|
||||||
|
let mapping: DioxusElementToNodeId = 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! {
|
cx.render(rsx! {
|
||||||
div{
|
div{
|
||||||
@@ -19,7 +21,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
onmousemove: move |evt| {
|
onmousemove: move |evt| {
|
||||||
if let RenderReturn::Ready(node) = cx.root_node() {
|
if let RenderReturn::Ready(node) = cx.root_node() {
|
||||||
if let Some(id) = node.root_ids.get(0){
|
if let Some(id) = node.root_ids.get(0){
|
||||||
let node = tui_query.get(id);
|
let node = tui_query.get(mapping.get_node_id(id).unwrap());
|
||||||
let Size{width, height} = node.size().unwrap();
|
let Size{width, height} = node.size().unwrap();
|
||||||
let pos = evt.inner().element_coordinates();
|
let pos = evt.inner().element_coordinates();
|
||||||
hue.set((pos.x as f32/width as f32)*255.0);
|
hue.set((pos.x as f32/width as f32)*255.0);
|
||||||
|
|||||||
@@ -23,20 +23,26 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
|
|||||||
|
|
||||||
pub fn launch_cfg_with_props<Props: 'static>(app: Component<Props>, props: Props, cfg: Config) {
|
pub fn launch_cfg_with_props<Props: 'static>(app: Component<Props>, props: Props, cfg: Config) {
|
||||||
render(cfg, |rdom, taffy, event_tx| {
|
render(cfg, |rdom, taffy, event_tx| {
|
||||||
|
let dioxus_state = {
|
||||||
|
let mut rdom = rdom.write().unwrap();
|
||||||
|
DioxusState::create(&mut rdom)
|
||||||
|
};
|
||||||
|
let dioxus_state = Rc::new(RwLock::new(dioxus_state));
|
||||||
let mut vdom = VirtualDom::new_with_props(app, props)
|
let mut vdom = VirtualDom::new_with_props(app, props)
|
||||||
.with_root_context(TuiContext { tx: event_tx })
|
.with_root_context(TuiContext { tx: event_tx })
|
||||||
.with_root_context(Query {
|
.with_root_context(Query {
|
||||||
rdom: rdom.clone(),
|
rdom: rdom.clone(),
|
||||||
stretch: taffy.clone(),
|
stretch: taffy.clone(),
|
||||||
|
})
|
||||||
|
.with_root_context(DioxusElementToNodeId {
|
||||||
|
mapping: dioxus_state.clone(),
|
||||||
});
|
});
|
||||||
let muts = vdom.rebuild();
|
let muts = vdom.rebuild();
|
||||||
let mut rdom = rdom.write().unwrap();
|
let mut rdom = rdom.write().unwrap();
|
||||||
let mut dioxus_state = DioxusState::create(&mut rdom);
|
dioxus_state
|
||||||
dioxus_state.apply_mutations(&mut rdom, muts);
|
.write()
|
||||||
let dioxus_state = Rc::new(RwLock::new(dioxus_state));
|
.unwrap()
|
||||||
vdom = vdom.with_root_context(DioxusElementToNodeId {
|
.apply_mutations(&mut rdom, muts);
|
||||||
mapping: dioxus_state.clone(),
|
|
||||||
});
|
|
||||||
DioxusRenderer {
|
DioxusRenderer {
|
||||||
vdom,
|
vdom,
|
||||||
dioxus_state,
|
dioxus_state,
|
||||||
|
|||||||
Reference in new issue
Block a user