diff options
author | crupest <crupest@outlook.com> | 2020-06-28 21:25:09 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-28 21:25:09 +0800 |
commit | b3c0c076e5a1b1e7d76fa8d32af0bcbb2c1cd4cf (patch) | |
tree | df90c6ae501508931fbd46ebc6340c90391e1ed5 /src/ui/render/LayoutHelper.cpp | |
parent | 698242c10cbef4ceaade848fa6aedac71baaf1f2 (diff) | |
download | cru-b3c0c076e5a1b1e7d76fa8d32af0bcbb2c1cd4cf.tar.gz cru-b3c0c076e5a1b1e7d76fa8d32af0bcbb2c1cd4cf.tar.bz2 cru-b3c0c076e5a1b1e7d76fa8d32af0bcbb2c1cd4cf.zip |
...
Diffstat (limited to 'src/ui/render/LayoutHelper.cpp')
-rw-r--r-- | src/ui/render/LayoutHelper.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/ui/render/LayoutHelper.cpp b/src/ui/render/LayoutHelper.cpp new file mode 100644 index 00000000..31cf5c08 --- /dev/null +++ b/src/ui/render/LayoutHelper.cpp @@ -0,0 +1,36 @@ +#include "cru/ui/render/LayoutHelper.hpp" + +#include "cru/common/Logger.hpp" + +namespace cru::ui::render { +float CalculateAnchorByAlignment(Alignment alignment, float start_point, + float content_length, float child_length) { + switch (alignment) { + case FlexCrossAlignment::Start: + return start_point; + case FlexCrossAlignment::Center: + return start_point + (content_length - child_length) / 2.0f; + case FlexCrossAlignment::End: + return start_point + content_length - child_length; + default: + return start_point; + } +} + +MeasureLength StackLayoutCalculateChildMaxLength( + MeasureLength parent_preferred_size, MeasureLength parent_max_size, + MeasureLength child_min_size, std::string_view exceeds_message) { + if (parent_max_size.GetLengthOrMax() < child_min_size.GetLengthOr0()) { + log::Warn(exceeds_message); + return parent_max_size; + } + + if (parent_preferred_size.IsSpecified() && + parent_preferred_size.GetLengthOrUndefined() >= + child_min_size.GetLengthOr0()) { + return parent_preferred_size; + } else { + return parent_max_size; + } +} +} // namespace cru::ui::render |