calculate absolute position
This commit is contained in:
1 parent
dab24e9ad9
commit
a5b9200e47
4 files changed
+20
-8
No files matched your search
@@ -15,7 +15,7 @@ dioxus-core = { path = "../core", version = "^0.2.1" }
|
|||||||
dioxus-html = { path = "../html", version = "^0.2.1" }
|
dioxus-html = { path = "../html", version = "^0.2.1" }
|
||||||
dioxus-core-macro = { path = "../core-macro", version = "^0.2.1" }
|
dioxus-core-macro = { path = "../core-macro", version = "^0.2.1" }
|
||||||
|
|
||||||
stretch2 = "0.4.2"
|
stretch2 = { git = "https://github.com/mockersf/stretch/", branch = "remove_round_layout_changes" }
|
||||||
smallvec = "1.6"
|
smallvec = "1.6"
|
||||||
fxhash = "0.2"
|
fxhash = "0.2"
|
||||||
anymap = "0.12.1"
|
anymap = "0.12.1"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ crossterm = "0.23.0"
|
|||||||
anyhow = "1.0.42"
|
anyhow = "1.0.42"
|
||||||
tokio = { version = "1.15.0", features = ["full"] }
|
tokio = { version = "1.15.0", features = ["full"] }
|
||||||
futures = "0.3.19"
|
futures = "0.3.19"
|
||||||
stretch2 = "0.4.2"
|
stretch2 = { git = "https://github.com/mockersf/stretch/", branch = "remove_round_layout_changes" }
|
||||||
smallvec = "1.6"
|
smallvec = "1.6"
|
||||||
fxhash = "0.2"
|
fxhash = "0.2"
|
||||||
anymap = "0.12.1"
|
anymap = "0.12.1"
|
||||||
@@ -17,7 +17,7 @@ use layout::StretchLayout;
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{io, time::Duration};
|
use std::{io, time::Duration};
|
||||||
use stretch2::{prelude::Size, Stretch};
|
use stretch2::{geometry::Point, prelude::Size, Stretch};
|
||||||
use style_attributes::StyleModifier;
|
use style_attributes::StyleModifier;
|
||||||
use tui::{backend::CrosstermBackend, layout::Rect, Terminal};
|
use tui::{backend::CrosstermBackend, layout::Rect, Terminal};
|
||||||
|
|
||||||
@@ -166,7 +166,14 @@ fn render_vdom(
|
|||||||
// size is guaranteed to not change when rendering
|
// size is guaranteed to not change when rendering
|
||||||
resize(frame.size(), &mut stretch.borrow_mut(), &rdom);
|
resize(frame.size(), &mut stretch.borrow_mut(), &rdom);
|
||||||
let root = &rdom[0];
|
let root = &rdom[0];
|
||||||
render::render_vnode(frame, &stretch.borrow(), &rdom, root, cfg);
|
render::render_vnode(
|
||||||
|
frame,
|
||||||
|
&stretch.borrow(),
|
||||||
|
&rdom,
|
||||||
|
root,
|
||||||
|
cfg,
|
||||||
|
Point::zero(),
|
||||||
|
);
|
||||||
})?;
|
})?;
|
||||||
} else {
|
} else {
|
||||||
resize(
|
resize(
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ pub(crate) fn render_vnode(
|
|||||||
rdom: &Dom,
|
rdom: &Dom,
|
||||||
node: &Node,
|
node: &Node,
|
||||||
cfg: Config,
|
cfg: Config,
|
||||||
|
parent_location: Point<f32>,
|
||||||
) {
|
) {
|
||||||
use dioxus_native_core::real_dom::NodeType;
|
use dioxus_native_core::real_dom::NodeType;
|
||||||
|
|
||||||
@@ -29,7 +30,11 @@ pub(crate) fn render_vnode(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Layout { location, size, .. } = layout.layout(node.state.layout.node.unwrap()).unwrap();
|
let Layout {
|
||||||
|
mut location, size, ..
|
||||||
|
} = layout.layout(node.state.layout.node.unwrap()).unwrap();
|
||||||
|
location.x += parent_location.x;
|
||||||
|
location.y += parent_location.y;
|
||||||
|
|
||||||
let Point { x, y } = location;
|
let Point { x, y } = location;
|
||||||
let Size { width, height } = size;
|
let Size { width, height } = size;
|
||||||
@@ -57,7 +62,7 @@ pub(crate) fn render_vnode(
|
|||||||
text,
|
text,
|
||||||
style: node.state.style.core,
|
style: node.state.style.core,
|
||||||
};
|
};
|
||||||
let area = Rect::new(*x as u16, *y as u16, *width as u16, *height as u16);
|
let area = Rect::new(x as u16, y as u16, *width as u16, *height as u16);
|
||||||
|
|
||||||
// the renderer will panic if a node is rendered out of range even if the size is zero
|
// the renderer will panic if a node is rendered out of range even if the size is zero
|
||||||
if area.width > 0 && area.height > 0 {
|
if area.width > 0 && area.height > 0 {
|
||||||
@@ -65,7 +70,7 @@ pub(crate) fn render_vnode(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
NodeType::Element { children, .. } => {
|
NodeType::Element { children, .. } => {
|
||||||
let area = Rect::new(*x as u16, *y as u16, *width as u16, *height as u16);
|
let area = Rect::new(x as u16, y as u16, *width as u16, *height as u16);
|
||||||
|
|
||||||
// the renderer will panic if a node is rendered out of range even if the size is zero
|
// the renderer will panic if a node is rendered out of range even if the size is zero
|
||||||
if area.width > 0 && area.height > 0 {
|
if area.width > 0 && area.height > 0 {
|
||||||
@@ -73,7 +78,7 @@ pub(crate) fn render_vnode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for c in children {
|
for c in children {
|
||||||
render_vnode(frame, layout, rdom, &rdom[c.0], cfg);
|
render_vnode(frame, layout, rdom, &rdom[c.0], cfg, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NodeType::Placeholder => unreachable!(),
|
NodeType::Placeholder => unreachable!(),
|
||||||
|
|||||||
Reference in new issue
Block a user