Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime panic with colpan or rowspan set to zero #7379

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/core/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,15 @@ mod grid_internal {
spacing: Coord,
size: Option<Coord>,
) -> Vec<LayoutData> {
let mut num = 0;
let mut num = 0usize;
for cell in data {
num = num.max(cell.col_or_row + cell.span);
num = num.max(cell.col_or_row as usize + cell.span.max(1) as usize);
}
if num < 1 {
return Default::default();
}
let mut layout_data = alloc::vec![grid_internal::LayoutData { stretch: 1., ..Default::default() }; num as usize];
let mut layout_data =
alloc::vec![grid_internal::LayoutData { stretch: 1., ..Default::default() }; num];
let mut has_spans = false;
for cell in data {
let constraint = &cell.constraint;
Expand Down
11 changes: 8 additions & 3 deletions tests/cases/layout/grid_span.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

TestCase := Window {
export component TestCase inherits Window {
width: 400phx;
height: 400phx;

Expand Down Expand Up @@ -44,12 +44,17 @@ TestCase := Window {
horizontal_stretch: 10;
vertical_stretch: 10;
}
zero2 := Rectangle {
col: 5;
colspan: 0;
}
}

property <bool> test: {
out property <bool> test: {
rr.x == 50phx && rr.y == 50phx && rr.width == 30phx && rr.height == (200phx - 10phx) / 2 &&
rb.width == 40phx && rg.width == 20phx && rg.height == (400phx - 200phx - 100phx - 20phx) / 2 &&
zero.height == 0 && zero.width == rb.width && zero.x == rb.x && zero.y == rg.y
zero.height == 0 && zero.width == rb.width && zero.x == rb.x && zero.y == rg.y &&
zero2.height == rg.height && zero2.width == 0 && zero2.x > rb.x && zero2.y == rg.y

}

Expand Down
Loading