Fix fr rows in infinite region

This commit is contained in:
Laurenz 2021-09-10 13:26:53 +02:00
parent f592662aa0
commit 50a464488c
2 changed files with 15 additions and 5 deletions

View File

@ -31,6 +31,7 @@ pub enum FrameChild {
impl Frame { impl Frame {
/// Create a new, empty frame. /// Create a new, empty frame.
#[track_caller]
pub fn new(size: Size, baseline: Length) -> Self { pub fn new(size: Size, baseline: Length) -> Self {
assert!(size.is_finite()); assert!(size.is_finite());
Self { size, baseline, children: vec![] } Self { size, baseline, children: vec![] }

View File

@ -470,10 +470,15 @@ impl<'a> GridLayouter<'a> {
/// Finish rows for one region. /// Finish rows for one region.
fn finish_region(&mut self, ctx: &mut LayoutContext) { fn finish_region(&mut self, ctx: &mut LayoutContext) {
// Determine the size of the region. // Determine the block size of the region.
let length = if self.fr.is_zero() { self.used.block } else { self.full }; let block = if self.fr.is_zero() || self.full.is_infinite() {
let size = self.to_size(length); self.used.block
self.constraints.min.set(self.block, Some(length)); } else {
self.full
};
let size = self.to_size(block);
self.constraints.min.set(self.block, Some(block));
// The frame for the region. // The frame for the region.
let mut output = Frame::new(size, size.h); let mut output = Frame::new(size, size.h);
@ -488,7 +493,10 @@ impl<'a> GridLayouter<'a> {
Row::Frame(frame) => frame, Row::Frame(frame) => frame,
Row::Fr(v, y) => { Row::Fr(v, y) => {
let ratio = v / self.fr; let ratio = v / self.fr;
if remaining > Length::zero() && ratio.is_finite() { if remaining > Length::zero()
&& remaining.is_finite()
&& ratio.is_finite()
{
let resolved = ratio * remaining; let resolved = ratio * remaining;
self.layout_single_row(ctx, resolved, y) self.layout_single_row(ctx, resolved, y)
} else { } else {
@ -513,6 +521,7 @@ impl<'a> GridLayouter<'a> {
/// Get the node in the cell in column `x` and row `y`. /// Get the node in the cell in column `x` and row `y`.
/// ///
/// Returns `None` if it's a gutter cell. /// Returns `None` if it's a gutter cell.
#[track_caller]
fn cell(&self, x: usize, y: usize) -> Option<&'a LayoutNode> { fn cell(&self, x: usize, y: usize) -> Option<&'a LayoutNode> {
assert!(x < self.cols.len()); assert!(x < self.cols.len());
assert!(y < self.rows.len()); assert!(y < self.rows.len());