#pragma once #include namespace cru { namespace ui { enum class MeasureMode { Exactly, Content, Stretch }; struct MeasureLength final { explicit MeasureLength(const float length = 0.0, const MeasureMode mode = MeasureMode::Exactly) : length(length), mode(mode) { } bool Validate() const { return !(mode == MeasureMode::Exactly && length < 0.0); } float length; MeasureMode mode; }; struct MeasureSize final { MeasureLength width; MeasureLength height; bool Validate() const { return width.Validate() && height.Validate(); } }; struct OptionalSize final { OptionalSize() : width(std::nullopt), height(std::nullopt) { } OptionalSize(const std::optional width, const std::optional height) : width(width), height(height) { } OptionalSize(const OptionalSize& other) = default; OptionalSize(OptionalSize&& other) = default; OptionalSize& operator = (const OptionalSize& other) = default; OptionalSize& operator = (OptionalSize&& other) = default; ~OptionalSize() = default; bool Validate() const { if (width.has_value() && width.value() < 0.0) return false; if (height.has_value() && height.value() < 0.0) return false; return true; } std::optional width; std::optional height; }; struct BasicLayoutParams { BasicLayoutParams() = default; BasicLayoutParams(const BasicLayoutParams&) = default; BasicLayoutParams(BasicLayoutParams&&) = default; BasicLayoutParams& operator = (const BasicLayoutParams&) = default; BasicLayoutParams& operator = (BasicLayoutParams&&) = default; virtual ~BasicLayoutParams() = default; bool Validate() const { if (!(size.Validate() && max_size.Validate() && min_size.Validate())) return false; auto&& f = [](const std::optional max_length, const std::optional min_length) -> bool { return max_length.has_value() && min_length.has_value() && max_length.value() < min_length.value(); }; if (!f(max_size.width, min_size.width)) return false; if (!f(max_size.height, min_size.height)) return false; return true; } MeasureSize size; OptionalSize min_size; OptionalSize max_size; }; } }