Skip to content

Commit

Permalink
Fixes Listview's element height when the height is specified in the p…
Browse files Browse the repository at this point in the history
…arent sub-component

Fixes #1057
  • Loading branch information
ogoffart committed Mar 17, 2022
1 parent 2d67807 commit 6653651
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/compiler/passes/repeater_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn create_repeater_components(component: &Rc<Component>) {
});

if let Some(listview) = is_listview {
if !comp.root_element.borrow().bindings.contains_key("height") {
if !comp.root_element.borrow().is_binding_set("height", false) {
let preferred = Expression::PropertyReference(NamedReference::new(
&comp.root_element,
"preferred-height",
Expand All @@ -61,7 +61,7 @@ fn create_repeater_components(component: &Rc<Component>) {
.bindings
.insert("height".into(), RefCell::new(preferred.into()));
}
if !comp.root_element.borrow().bindings.contains_key("width") {
if !comp.root_element.borrow().is_binding_set("width", false) {
comp.root_element.borrow_mut().bindings.insert(
"width".into(),
RefCell::new(Expression::PropertyReference(listview.listview_width).into()),
Expand Down
59 changes: 59 additions & 0 deletions tests/cases/layout/issue_1057_listview_subcomponent_height.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

import { ListView } from "std-widgets.slint";

MyListItem := Rectangle {
callback clicked <=> ta.clicked;
property <string> string;

height: 100px;

Text {
text: string;
}

ta := TouchArea { }
}

TestCase := Window {
width: 300px;
height: 500px;

property <string> value;

HorizontalLayout {
lv := ListView {
for string in [ "Blue", "Red", "Green", "Yellow", "Black", "White", "Magenta", "Cyan"] : my := MyListItem {
string: string;
clicked => { value = string; }
}
}
}
property <int> viewport-height: lv.viewport-height / 1px;
}

/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
slint::testing::send_mouse_click(&instance, 5., 205.);
assert_eq(instance.get_value(), "Green");
assert_eq(instance.get_viewport_height(), 800);
```
```rust
let instance = TestCase::new();
slint::testing::send_mouse_click(&instance, 5., 205.);
assert_eq!(instance.get_value(), "Green");
assert_eq!(instance.get_viewport_height(), 800);
```
```js
var instance = new slint.TestCase();
instance.send_mouse_click(5., 205.);
assert.equal(instance.value, "Green");
assert.equal(instance.viewport_height, 800);
```
*/

0 comments on commit 6653651

Please sign in to comment.