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 compiler panic when using % size in a flickable #4223

Merged
merged 2 commits into from
Sep 12, 2024
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
8 changes: 6 additions & 2 deletions internal/compiler/passes/default_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 279,11 @@ fn fix_percent_size(
return matches!(&binding.borrow().expression, Expression::PropertyReference(nr) if nr.name() == property && Rc::ptr_eq(&nr.element(), parent));
}
let mut b = binding.borrow_mut();
if let Some(parent) = parent {
if let Some(mut parent) = parent.clone() {
if parent.borrow().is_flickable_viewport {
// the `%` in a flickable need to refer to the size of the flickable, not the size of the viewport
parent = crate::object_tree::find_parent_element(&parent).unwrap_or(parent)
}
debug_assert_eq!(
parent.borrow().lookup_property(property).property_type,
Type::LogicalLength
Expand All @@ -292,7 296,7 @@ fn fix_percent_size(
&b.span,
diag,
)),
rhs: Box::new(Expression::PropertyReference(NamedReference::new(parent, property))),
rhs: Box::new(Expression::PropertyReference(NamedReference::new(&parent, property))),
op: '*',
};
fill
Expand Down
59 changes: 59 additions & 0 deletions tests/cases/issues/issue_4163_flickable_parent_percent.slint
Original file line number Diff line number Diff line change
@@ -0,0 1,59 @@
// 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

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

component ShowResult inherits Rectangle {
ogoffart marked this conversation as resolved.
Show resolved Hide resolved
width: 50%;
height: 100%;

VerticalLayout {
ListView {
for file[idx] in [1,2,3]:Rectangle {
height: 20px;
// width: parent.width; // change to this line compiles fine
width: 100%; // An error occurred!!!
}
}
}
}
export component TestCase inherits Window {
width: 300px;
height: 326px;

HorizontalLayout {
width: 100%;
height: 100%;

ShowResult {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this part is not needed for the automated test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the original testcase. Not needed but good to have in addition as it is a bit more complex.

}


fli := Flickable {
viewport-height: 1000px;
viewport-width: 2000px;
rec := Rectangle {
width: 100%;
height: parent.height;
}
}

out property <bool> test:
rec.width == 300px &&
rec.height == 326px;
}

/*

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert(instance.get_test());
```

```rust
let instance = TestCase::new().unwrap();
assert!(instance.get_test());
```

*/
Loading