Fix compiler panic when optimizing child of layout

Normally, child of layout don't get optimized anyway because
the layout sets their `x` and `y` prop, preventing the optimization.
But if the rectangle has an opacity, its `x` and `y` property are
stolen by the opacity element, and then it can get optimized anyway

Fixes #1267
This commit is contained in:
Olivier Goffart 2022-05-13 15:44:32 +02:00 committed by Olivier Goffart
parent 1d18bd634b
commit b3fe9cc96d
2 changed files with 16 additions and 0 deletions

View file

@ -40,6 +40,11 @@ fn can_optimize(elem: &ElementRc) -> bool {
return false;
};
if e.child_of_layout {
// The `LayoutItem` still has reference to this component, so we cannot remove it
return false;
}
let base_type = match &e.base_type {
Type::Builtin(base_type) if base_type.name == "Rectangle" => base_type,
_ => return false,

View file

@ -0,0 +1,11 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
MainWindow := Window {
VerticalLayout {
Rectangle {
opacity: 0.5;
}
}
}