From b8e621a76bd8bafb1ba1b84b8ccd8362d9bccfdf Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 8 Apr 2021 13:16:06 +0200 Subject: [PATCH] Fix C++ build Add the preferred size merging logic also to C++ LayoutInfo::merge. Amends commit 843f52b3c57cf1c49f924524f473abbc0b6f51ab --- api/sixtyfps-cpp/include/sixtyfps.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index 4c574689f..8796259ad 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -337,6 +337,16 @@ 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_width, other.min_width), std::min(max_width, other.max_width), std::max(min_height, other.min_height), @@ -345,6 +355,10 @@ inline LayoutInfo LayoutInfo::merge(const LayoutInfo &other) const std::min(max_width_percent, other.max_width_percent), std::max(min_height_percent, other.min_height_percent), std::min(max_height_percent, other.max_height_percent), + merge_preferred_size(horizontal_stretch, preferred_width, + other.horizontal_stretch, other.preferred_width), + merge_preferred_size(vertical_stretch, preferred_height, + other.vertical_stretch, other.preferred_height), std::min(horizontal_stretch, other.horizontal_stretch), std::min(vertical_stretch, other.vertical_stretch) }; }