|
@@ -71,6 +71,20 @@ impl SizePolicy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ pub fn with_minimum(mut self, new_min: usize) -> Self {
|
|
|
+ self.minimum = new_min;
|
|
|
+ self.desired = self.desired.max(new_min);
|
|
|
+ self
|
|
|
+ }
|
|
|
+ pub fn with_desired(mut self, new_desire: usize) -> Self {
|
|
|
+ self.desired = new_desire;
|
|
|
+ self
|
|
|
+ }
|
|
|
+ pub fn with_slack(mut self, new_slack: usize) -> Self {
|
|
|
+ self.slack_weight = new_slack;
|
|
|
+ self
|
|
|
+ }
|
|
|
+
|
|
|
pub fn max(self, rhs: SizePolicy) -> SizePolicy {
|
|
|
Self {
|
|
|
minimum: self.minimum.max(rhs.minimum),
|
|
@@ -88,6 +102,9 @@ impl SizePolicy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+pub struct SizePolicyTag;
|
|
|
+pub type SizePolicy2D = euclid::Size2D<SizePolicy, SizePolicyTag>;
|
|
|
+
|
|
|
impl std::ops::Add<Self> for SizePolicy {
|
|
|
type Output = Self;
|
|
|
fn add(self, rhs: Self) -> Self::Output {
|
|
@@ -141,6 +158,7 @@ pub enum NodeBehaviour {
|
|
|
#[derive(Clone)]
|
|
|
pub enum ChildArrangement {
|
|
|
Custom(std::rc::Rc<dyn arr::ArrangementCalculator>),
|
|
|
+ Container,
|
|
|
Column,
|
|
|
Row,
|
|
|
Table,
|
|
@@ -150,6 +168,7 @@ impl std::fmt::Debug for ChildArrangement {
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
match self {
|
|
|
Self::Custom(_) => f.write_str("ChildArrangement::Custom"),
|
|
|
+ Self::Container => f.write_str("ChildArrangement::Container"),
|
|
|
Self::Column => f.write_str("ChildArrangement::Column"),
|
|
|
Self::Row => f.write_str("ChildArrangement::Row"),
|
|
|
Self::Table => f.write_str("ChildArrangement::Table"),
|
|
@@ -162,6 +181,7 @@ impl Deref for ChildArrangement {
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
match self {
|
|
|
Self::Custom(calc) => calc.as_ref(),
|
|
|
+ Self::Container => &arr::ContainerArrangement,
|
|
|
Self::Column => &arr::LineArrangement::Column,
|
|
|
Self::Row => &arr::LineArrangement::Row,
|
|
|
Self::Table => &arr::TableArrangement,
|
|
@@ -184,13 +204,13 @@ pub struct LayoutNode {
|
|
|
width_policy: SizePolicy,
|
|
|
/// Height policy: how does this widget take up vertical space?
|
|
|
height_policy: SizePolicy,
|
|
|
- /// Horizontal alignment of children inside this node.
|
|
|
+ /// Horizontal alignment of this node inside its parent.
|
|
|
halign: HorizontalAlignment,
|
|
|
- /// Vertical alignment of children inside this node.
|
|
|
+ /// Vertical alignment of this node inside its parent.
|
|
|
valign: VerticalAlignment,
|
|
|
/// User-exposed margins, or spacing between the parent and the render area of this node.
|
|
|
margin: PixelSideOffsets,
|
|
|
- /// Table row/column assignment for child nodes, coordinates stored as (row, column).
|
|
|
+ /// Table row/column assignment for this node insite its parent.
|
|
|
table_cell: Option<TableCell>,
|
|
|
}
|
|
|
|
|
@@ -231,6 +251,10 @@ impl LayoutNode {
|
|
|
&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) {
|
|
|
self.cache.update_queue.borrow_mut().push(self.cache_key);
|
|
|
}
|
|
@@ -246,21 +270,17 @@ impl LayoutNode {
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
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) {
|
|
@@ -335,6 +355,12 @@ impl LayoutNode {
|
|
|
pub fn margin_mut(&mut self) -> &mut PixelSideOffsets {
|
|
|
&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> {
|
|
|
&self.table_cell
|
|
@@ -386,13 +412,16 @@ fn dump_node_tree_helper(lna: LayoutNodeAccess, indent: usize, out: &mut String)
|
|
|
lna.height_policy.desired,
|
|
|
lna.height_policy.slack_weight,
|
|
|
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(),
|
|
|
);
|
|
|
out.push_str(ind.as_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());
|
|
|
|
|
|
for child in lna.child_iter() {
|