Also set the preferred size for the GridLayout

Issue #182
This commit is contained in:
Olivier Goffart 2021-04-21 18:55:42 +02:00
parent f1338c39ef
commit 1f64f7ab27
2 changed files with 67 additions and 2 deletions

View file

@ -293,7 +293,7 @@ pub fn solve_grid_layout(data: &GridLayoutData) {
let row_max = cnstr.max_height.min(data.height * cnstr.max_height_percent / 100.); let row_max = cnstr.max_height.min(data.height * cnstr.max_height_percent / 100.);
let row_min = cnstr.min_height.max(data.height * cnstr.min_height_percent / 100.) let row_min = cnstr.min_height.max(data.height * cnstr.min_height_percent / 100.)
/ (cell.rowspan as f32); / (cell.rowspan as f32);
let row_pref = row_min; let row_pref = cnstr.preferred_height;
for r in 0..(cell.rowspan as usize) { for r in 0..(cell.rowspan as usize) {
let rdata = &mut row_layout_data[cell.row as usize + r]; let rdata = &mut row_layout_data[cell.row as usize + r];
@ -306,7 +306,7 @@ pub fn solve_grid_layout(data: &GridLayoutData) {
let col_max = cnstr.max_width.min(data.width * cnstr.max_width_percent / 100.); let col_max = cnstr.max_width.min(data.width * cnstr.max_width_percent / 100.);
let col_min = cnstr.min_width.max(data.width * cnstr.min_width_percent / 100.) let col_min = cnstr.min_width.max(data.width * cnstr.min_width_percent / 100.)
/ (cell.colspan as f32); / (cell.colspan as f32);
let col_pref = col_min; let col_pref = cnstr.preferred_width;
for c in 0..(cell.colspan as usize) { for c in 0..(cell.colspan as usize) {
let cdata = &mut col_layout_data[cell.col as usize + c]; let cdata = &mut col_layout_data[cell.col as usize + c];

View file

@ -0,0 +1,65 @@
/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
TestCase := Rectangle {
background: green;
width: 300phx;
height: 50phx;
GridLayout {
padding: 0px;
fake-image := Rectangle {
background: blue;
preferred-width: 25phx;
// Don't apply the preferred height for the horizontal layout.
preferred-height: 500phx;
horizontal-stretch: 0;
vertical-stretch: 0;
}
Rectangle {
background: green;
// implicit: horizontal-stretch: 1
}
Rectangle {
row: 1;
background: red;
// implicit: horizontal-stretch: 1
}
}
property <bool> fake-image-width-ok: fake-image.width == 25phx;
property <bool> fake-image-height-ok: fake-image.height == 50phx;
}
/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_fake_image_width_ok());
assert(instance.get_fake_image_height_ok());
```
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_fake_image_width_ok());
assert!(instance.get_fake_image_height_ok());
```
```js
var instance = new sixtyfps.TestCase();
instance.send_mouse_click(5., 5.);
assert(instance.fake_image_width_ok);
assert(instance.fake_image_height_ok);
```
*/