|
@@ -1,7 +1,7 @@
|
|
|
use kahlo::math::{PixelBox, PixelSideOffsets};
|
|
|
use std::ops::Add;
|
|
|
|
|
|
-use super::{LayoutNodeAccess, SizePolicy, HorizontalAlignment, VerticalAlignment};
|
|
|
+use super::{HorizontalAlignment, LayoutNodeAccess, SizePolicy, VerticalAlignment, SizePolicy2D};
|
|
|
|
|
|
/// Child arrangement calculator trait.
|
|
|
///
|
|
@@ -10,50 +10,49 @@ use super::{LayoutNodeAccess, SizePolicy, HorizontalAlignment, VerticalAlignment
|
|
|
/// node. The layout step then uses the computed constraints and size policies to compute a set of
|
|
|
/// pixel-space rects.
|
|
|
pub trait ArrangementCalculator {
|
|
|
- fn arrange_step(&self, node: LayoutNodeAccess) -> (SizePolicy, SizePolicy);
|
|
|
+ fn arrange_step(&self, node: LayoutNodeAccess) -> SizePolicy2D;
|
|
|
fn layout_step(&self, node: LayoutNodeAccess, inside: PixelBox);
|
|
|
}
|
|
|
|
|
|
+mod container;
|
|
|
+pub use container::ContainerArrangement;
|
|
|
mod line;
|
|
|
pub use line::LineArrangement;
|
|
|
mod table;
|
|
|
pub use table::TableArrangement;
|
|
|
|
|
|
fn do_align(node: &LayoutNodeAccess, mut inside: PixelBox) -> PixelBox {
|
|
|
- let net_policy = node.cache.with_state(node.cache_key, |ns| ns.net_policy).expect("do_align invoked with node that has no net_policy");
|
|
|
+ let net_policy = node
|
|
|
+ .with_state(|ns| ns.net_policy)
|
|
|
+ .expect("do_align invoked with node that has no net_policy");
|
|
|
println!("do_align | net: {net_policy:?}");
|
|
|
- println!(" | alignments: {:?} {:?}", node.halign(), node.valign());
|
|
|
+ println!(
|
|
|
+ " | alignments: {:?} {:?}",
|
|
|
+ node.halign(),
|
|
|
+ node.valign()
|
|
|
+ );
|
|
|
println!(" | inside before: {inside:?}");
|
|
|
- if net_policy.0.slack_weight == 0 {
|
|
|
- let slack = (inside.width() - net_policy.0.desired as i32).max(0);
|
|
|
+ if net_policy.width.slack_weight == 0 {
|
|
|
+ let slack = (inside.width() - net_policy.width.desired as i32).max(0);
|
|
|
let hshrink = match node.halign() {
|
|
|
- HorizontalAlignment::Left => {
|
|
|
- PixelSideOffsets::new(0, slack, 0, 0)
|
|
|
- },
|
|
|
+ HorizontalAlignment::Left => PixelSideOffsets::new(0, slack, 0, 0),
|
|
|
HorizontalAlignment::Centre => {
|
|
|
- PixelSideOffsets::new(0, slack/2, 0, slack - (slack/2))
|
|
|
- },
|
|
|
- HorizontalAlignment::Right => {
|
|
|
- PixelSideOffsets::new(0, 0, 0, slack)
|
|
|
- },
|
|
|
+ PixelSideOffsets::new(0, slack / 2, 0, slack - (slack / 2))
|
|
|
+ }
|
|
|
+ HorizontalAlignment::Right => PixelSideOffsets::new(0, 0, 0, slack),
|
|
|
};
|
|
|
inside = inside.inner_box(hshrink);
|
|
|
}
|
|
|
- if net_policy.1.slack_weight == 0 {
|
|
|
- let slack = (inside.height() - net_policy.1.desired as i32).max(0);
|
|
|
+ if net_policy.height.slack_weight == 0 {
|
|
|
+ let slack = (inside.height() - net_policy.height.desired as i32).max(0);
|
|
|
let vshrink = match node.valign() {
|
|
|
- VerticalAlignment::Top => {
|
|
|
- PixelSideOffsets::new(0, 0, slack, 0)
|
|
|
- },
|
|
|
+ VerticalAlignment::Top => PixelSideOffsets::new(0, 0, slack, 0),
|
|
|
VerticalAlignment::Centre => {
|
|
|
- PixelSideOffsets::new(slack/2, 0, slack-(slack/2), 0)
|
|
|
- },
|
|
|
- VerticalAlignment::Bottom => {
|
|
|
- PixelSideOffsets::new(slack, 0, 0, 0)
|
|
|
- },
|
|
|
+ PixelSideOffsets::new(slack / 2, 0, slack - (slack / 2), 0)
|
|
|
+ }
|
|
|
+ VerticalAlignment::Bottom => PixelSideOffsets::new(slack, 0, 0, 0),
|
|
|
};
|
|
|
inside = inside.inner_box(vshrink);
|
|
|
-
|
|
|
}
|
|
|
println!(" | inside after: {inside:?}");
|
|
|
inside
|