Fix preferred size of the Window with a layout

A few problem:
 - the horizontal and vertical property were swapped
 - The implementation of the "preferred_xxx" property was not materialized properly
   because the `bindings` were borrowed in the materialize_fake_properties pass
 - Since the Window has a stretch factor of 0., the preferred size of the inner layout
   was not taken into account when merging the LayoutInfo.  I believe taking the
   maximum preferred size is the right solution when merging them.
This commit is contained in:
Olivier Goffart 2021-06-18 13:45:27 +02:00
parent 0a3ec534ae
commit a0bea36e43
5 changed files with 74 additions and 42 deletions

View file

@ -321,22 +321,11 @@ using cbindgen_private::sixtyfps_solve_path_layout;
inline LayoutInfo LayoutInfo::merge(const LayoutInfo &other) const
{
// Note: This "logic" is duplicated from LayoutInfo::merge in layout.rs.
const auto merge_preferred_size = [](float left_stretch, float left_size, float right_stretch,
float right_size) -> float {
if (left_stretch < right_stretch) {
return left_size;
} else if (left_stretch > right_stretch) {
return right_size;
} else {
return (left_size + right_size) / 2.;
}
};
return LayoutInfo { std::max(min, other.min),
std::min(max, other.max),
std::max(min_percent, other.min_percent),
std::min(max_percent, other.max_percent),
merge_preferred_size(stretch, preferred,
other.stretch, other.preferred),
std::max(preferred, other.preferred),
std::min(stretch, other.stretch) };
}