|
@@ -1,7 +1,7 @@
|
|
|
-use kahlo::math::PixelBox;
|
|
|
+use kahlo::math::{PixelBox, PixelSideOffsets};
|
|
|
use std::ops::Add;
|
|
|
|
|
|
-use super::{LayoutNodeAccess, SizePolicy};
|
|
|
+use super::{LayoutNodeAccess, SizePolicy, HorizontalAlignment, VerticalAlignment};
|
|
|
|
|
|
/// Child arrangement calculator trait.
|
|
|
///
|
|
@@ -19,6 +19,46 @@ 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");
|
|
|
+ println!("do_align | net: {net_policy:?}");
|
|
|
+ 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);
|
|
|
+ let hshrink = match node.halign() {
|
|
|
+ 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)
|
|
|
+ },
|
|
|
+ };
|
|
|
+ inside = inside.inner_box(hshrink);
|
|
|
+ }
|
|
|
+ if net_policy.1.slack_weight == 0 {
|
|
|
+ let slack = (inside.height() - net_policy.1.desired as i32).max(0);
|
|
|
+ let vshrink = match node.valign() {
|
|
|
+ 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)
|
|
|
+ },
|
|
|
+ };
|
|
|
+ inside = inside.inner_box(vshrink);
|
|
|
+
|
|
|
+ }
|
|
|
+ println!(" | inside after: {inside:?}");
|
|
|
+ inside
|
|
|
+}
|
|
|
+
|
|
|
/// Calculate the fit of a number of size policies inside a given length.
|
|
|
///
|
|
|
/// Returns the endpoints of each item.
|