|
@@ -102,6 +102,9 @@ impl SizePolicy {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+pub struct SizePolicyTag;
|
|
|
|
+pub type SizePolicy2D = euclid::Size2D<SizePolicy, SizePolicyTag>;
|
|
|
|
+
|
|
impl std::ops::Add<Self> for SizePolicy {
|
|
impl std::ops::Add<Self> for SizePolicy {
|
|
type Output = Self;
|
|
type Output = Self;
|
|
fn add(self, rhs: Self) -> Self::Output {
|
|
fn add(self, rhs: Self) -> Self::Output {
|
|
@@ -155,6 +158,7 @@ pub enum NodeBehaviour {
|
|
#[derive(Clone)]
|
|
#[derive(Clone)]
|
|
pub enum ChildArrangement {
|
|
pub enum ChildArrangement {
|
|
Custom(std::rc::Rc<dyn arr::ArrangementCalculator>),
|
|
Custom(std::rc::Rc<dyn arr::ArrangementCalculator>),
|
|
|
|
+ Container,
|
|
Column,
|
|
Column,
|
|
Row,
|
|
Row,
|
|
Table,
|
|
Table,
|
|
@@ -164,6 +168,7 @@ impl std::fmt::Debug for ChildArrangement {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
match self {
|
|
Self::Custom(_) => f.write_str("ChildArrangement::Custom"),
|
|
Self::Custom(_) => f.write_str("ChildArrangement::Custom"),
|
|
|
|
+ Self::Container => f.write_str("ChildArrangement::Container"),
|
|
Self::Column => f.write_str("ChildArrangement::Column"),
|
|
Self::Column => f.write_str("ChildArrangement::Column"),
|
|
Self::Row => f.write_str("ChildArrangement::Row"),
|
|
Self::Row => f.write_str("ChildArrangement::Row"),
|
|
Self::Table => f.write_str("ChildArrangement::Table"),
|
|
Self::Table => f.write_str("ChildArrangement::Table"),
|
|
@@ -176,6 +181,7 @@ impl Deref for ChildArrangement {
|
|
fn deref(&self) -> &Self::Target {
|
|
fn deref(&self) -> &Self::Target {
|
|
match self {
|
|
match self {
|
|
Self::Custom(calc) => calc.as_ref(),
|
|
Self::Custom(calc) => calc.as_ref(),
|
|
|
|
+ Self::Container => &arr::ContainerArrangement,
|
|
Self::Column => &arr::LineArrangement::Column,
|
|
Self::Column => &arr::LineArrangement::Column,
|
|
Self::Row => &arr::LineArrangement::Row,
|
|
Self::Row => &arr::LineArrangement::Row,
|
|
Self::Table => &arr::TableArrangement,
|
|
Self::Table => &arr::TableArrangement,
|
|
@@ -245,6 +251,10 @@ impl LayoutNode {
|
|
&self.cache
|
|
&self.cache
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ fn with_state<R, F: FnOnce(&mut NodeState) -> R>(&self, f: F) -> Option<R> {
|
|
|
|
+ self.cache.with_state(self.cache_key, f)
|
|
|
|
+ }
|
|
|
|
+
|
|
pub fn relayout(&self) {
|
|
pub fn relayout(&self) {
|
|
self.cache.update_queue.borrow_mut().push(self.cache_key);
|
|
self.cache.update_queue.borrow_mut().push(self.cache_key);
|
|
}
|
|
}
|
|
@@ -260,21 +270,17 @@ impl LayoutNode {
|
|
}
|
|
}
|
|
|
|
|
|
pub fn render_area(&self) -> Option<PixelBox> {
|
|
pub fn render_area(&self) -> Option<PixelBox> {
|
|
- self.cache
|
|
|
|
- .with_state(self.cache_key, |ns| ns.area)
|
|
|
|
- .flatten()
|
|
|
|
- .map(|pb| pb.inner_box(self.margin))
|
|
|
|
|
|
+ self.with_state(|ns| ns.area).flatten()
|
|
}
|
|
}
|
|
|
|
|
|
/// Checks if node needs to be rerendered, clearing the flag if so.
|
|
/// Checks if node needs to be rerendered, clearing the flag if so.
|
|
pub fn render_check(&self) -> bool {
|
|
pub fn render_check(&self) -> bool {
|
|
- self.cache
|
|
|
|
- .with_state(self.cache_key, |ns| {
|
|
|
|
- let ret = ns.needs_render;
|
|
|
|
- ns.needs_render = false;
|
|
|
|
- ret
|
|
|
|
- })
|
|
|
|
- .unwrap_or(false)
|
|
|
|
|
|
+ self.with_state(|ns| {
|
|
|
|
+ let ret = ns.needs_render;
|
|
|
|
+ ns.needs_render = false;
|
|
|
|
+ ret
|
|
|
|
+ })
|
|
|
|
+ .unwrap_or(false)
|
|
}
|
|
}
|
|
|
|
|
|
pub fn render_needed(&self) {
|
|
pub fn render_needed(&self) {
|
|
@@ -349,6 +355,12 @@ impl LayoutNode {
|
|
pub fn margin_mut(&mut self) -> &mut PixelSideOffsets {
|
|
pub fn margin_mut(&mut self) -> &mut PixelSideOffsets {
|
|
&mut self.margin
|
|
&mut self.margin
|
|
}
|
|
}
|
|
|
|
+ pub fn margin_as_policy(&self) -> SizePolicy2D {
|
|
|
|
+ SizePolicy2D::new(
|
|
|
|
+ SizePolicy::fixed((self.margin.left + self.margin.right) as usize),
|
|
|
|
+ SizePolicy::fixed((self.margin.top + self.margin.bottom) as usize),
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
|
|
pub fn table_cell(&self) -> &Option<TableCell> {
|
|
pub fn table_cell(&self) -> &Option<TableCell> {
|
|
&self.table_cell
|
|
&self.table_cell
|
|
@@ -400,13 +412,16 @@ fn dump_node_tree_helper(lna: LayoutNodeAccess, indent: usize, out: &mut String)
|
|
lna.height_policy.desired,
|
|
lna.height_policy.desired,
|
|
lna.height_policy.slack_weight,
|
|
lna.height_policy.slack_weight,
|
|
lna.behaviour,
|
|
lna.behaviour,
|
|
- lna.cache.with_state(lna.cache_key, |v| v.needs_update),
|
|
|
|
- lna.cache.with_state(lna.cache_key, |v| v.needs_render),
|
|
|
|
|
|
+ lna.with_state(|v| v.needs_update),
|
|
|
|
+ lna.with_state(|v| v.needs_render),
|
|
)
|
|
)
|
|
.as_str(),
|
|
.as_str(),
|
|
);
|
|
);
|
|
out.push_str(ind.as_str());
|
|
out.push_str(ind.as_str());
|
|
out.push_str(" ");
|
|
out.push_str(" ");
|
|
|
|
+ out.push_str(format!("net policy: {:?}\n", lna.with_state(|v| v.net_policy)).as_str());
|
|
|
|
+ out.push_str(ind.as_str());
|
|
|
|
+ out.push_str(" ");
|
|
out.push_str(format!("render area: {:?}\n", lna.render_area()).as_str());
|
|
out.push_str(format!("render area: {:?}\n", lna.render_area()).as_str());
|
|
|
|
|
|
for child in lna.child_iter() {
|
|
for child in lna.child_iter() {
|