diff options
author | crupest <crupest@outlook.com> | 2020-06-25 23:44:43 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-25 23:44:43 +0800 |
commit | a48ff30f9d4ac8ae6cc9adef4a07f8d9beb69e7a (patch) | |
tree | 077a74943214da7627cca2ba9966d90d5bed144a /src/ui/render/StackLayoutRenderObject.cpp | |
parent | ce0ae2c3727f83f1943d528b006eec94ad80ece9 (diff) | |
download | cru-a48ff30f9d4ac8ae6cc9adef4a07f8d9beb69e7a.tar.gz cru-a48ff30f9d4ac8ae6cc9adef4a07f8d9beb69e7a.tar.bz2 cru-a48ff30f9d4ac8ae6cc9adef4a07f8d9beb69e7a.zip |
Write layout logic at half way.
Diffstat (limited to 'src/ui/render/StackLayoutRenderObject.cpp')
-rw-r--r-- | src/ui/render/StackLayoutRenderObject.cpp | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/src/ui/render/StackLayoutRenderObject.cpp b/src/ui/render/StackLayoutRenderObject.cpp index 7dce1a83..b953ae7e 100644 --- a/src/ui/render/StackLayoutRenderObject.cpp +++ b/src/ui/render/StackLayoutRenderObject.cpp @@ -4,47 +4,57 @@ namespace cru::ui::render { Size StackLayoutRenderObject::OnMeasureContent( - const MeasureRequirement& requirement) { - auto size = Size{}; - for (const auto child : GetChildren()) { - child->Measure(requirement); - const auto& measure_result = child->GetMeasuredSize(); - size.width = std::max(size.width, measure_result.width); - size.height = std::max(size.height, measure_result.height); - } - return size; + const MeasureRequirement& requirement, const MeasureSize& preferred_size) { + // TODO: Rewrite this. + CRU_UNUSED(requirement); + CRU_UNUSED(preferred_size); + throw std::runtime_error("Not implemented."); + + // throw std::runtime_error("Not implemented."); + // auto size = Size{}; + // for (const auto child : GetChildren()) { + // child->Measure(requirement); + // const auto& measure_result = child->GetMeasuredSize(); + // size.width = std::max(size.width, measure_result.width); + // size.height = std::max(size.height, measure_result.height); + // } + // return size; } -void StackLayoutRenderObject::OnLayoutContent(const Rect& rect) { - auto calculate_anchor = [](int alignment, float start_point, - float total_length, - float content_length) -> float { - switch (alignment) { - case internal::align_start: - return start_point; - case internal::align_center: - return start_point + (total_length - content_length) / 2.0f; - case internal::align_end: - return start_point + total_length - content_length; - default: - return start_point; - } - }; +void StackLayoutRenderObject::OnLayoutContent(const Rect& content_rect) { + // TODO: Rewrite this. + CRU_UNUSED(content_rect); + throw std::runtime_error("Not implemented."); - const auto count = GetChildCount(); - const auto& children = GetChildren(); + // auto calculate_anchor = [](int alignment, float start_point, + // float total_length, + // float content_length) -> float { + // switch (alignment) { + // case internal::align_start: + // return start_point; + // case internal::align_center: + // return start_point + (total_length - content_length) / 2.0f; + // case internal::align_end: + // return start_point + total_length - content_length; + // default: + // return start_point; + // } + // }; - for (int i = 0; i < count; i++) { - const auto layout_data = GetChildLayoutData(i); - const auto child = children[i]; - const auto& size = child->GetMeasuredSize(); - child->Layout( - Rect{calculate_anchor(static_cast<int>(layout_data->horizontal), - rect.left, rect.width, size.width), - calculate_anchor(static_cast<int>(layout_data->vertical), rect.top, - rect.height, size.height), - size.width, size.height}); - } -} + // const auto count = GetChildCount(); + // const auto& children = GetChildren(); + // for (int i = 0; i < count; i++) { + // const auto layout_data = GetChildLayoutData(i); + // const auto child = children[i]; + // const auto& size = child->GetMeasuredSize(); + // child->Layout( + // Rect{calculate_anchor(static_cast<int>(layout_data->horizontal), + // rect.left, rect.width, size.width), + // calculate_anchor(static_cast<int>(layout_data->vertical), + // rect.top, + // rect.height, size.height), + // size.width, size.height}); + // } +} } // namespace cru::ui::render |