diff options
| author | Martin <mhaug@live.de> | 2021-06-17 14:18:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-17 14:18:43 +0200 |
| commit | e14e8047890afad5896c9f38ccdd8551f869be64 (patch) | |
| tree | e65a448e88c0de84ae0790a92a00fd903ba197da /src/layout/fixed.rs | |
| parent | e2cdda67dc0e16b9a482aa3a4bfd5991db06d143 (diff) | |
Constraints (#31)
Diffstat (limited to 'src/layout/fixed.rs')
| -rw-r--r-- | src/layout/fixed.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs index 233c27f3..19876987 100644 --- a/src/layout/fixed.rs +++ b/src/layout/fixed.rs @@ -12,16 +12,37 @@ pub struct FixedNode { } impl Layout for FixedNode { - fn layout(&self, ctx: &mut LayoutContext, regions: &Regions) -> Vec<Frame> { + fn layout( + &self, + ctx: &mut LayoutContext, + regions: &Regions, + ) -> Vec<Constrained<Frame>> { let Regions { current, base, .. } = regions; + let mut constraints = Constraints::new(regions.expand); + constraints.set_base_using_linears(Spec::new(self.width, self.height), ®ions); + let size = Size::new( self.width.map_or(current.width, |w| w.resolve(base.width)), self.height.map_or(current.height, |h| h.resolve(base.height)), ); + // If one dimension was not specified, the `current` size needs to remain static. + if self.width.is_none() { + constraints.exact.horizontal = Some(current.width); + } + if self.height.is_none() { + constraints.exact.vertical = Some(current.height); + } + let expand = Spec::new(self.width.is_some(), self.height.is_some()); let regions = Regions::one(size, expand); - self.child.layout(ctx, ®ions) + let mut frames = self.child.layout(ctx, ®ions); + + if let Some(frame) = frames.first_mut() { + frame.constraints = constraints; + } + + frames } } |
