aboutsummaryrefslogtreecommitdiff
path: root/src/ui/layout_base.hpp
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-03-28 20:39:36 +0800
committerGitHub <noreply@github.com>2019-03-28 20:39:36 +0800
commitc45a6e62298e972f5945f5f3461ed723aea80317 (patch)
treef46ef303ee87a8e3814ea8743bd7062d432bfee3 /src/ui/layout_base.hpp
parentb028e74a48de181ca078ad3bf4ababf4fa146cd3 (diff)
parent37216f211b0e22205a3a0d3373d985fc68aea59b (diff)
downloadcru-c45a6e62298e972f5945f5f3461ed723aea80317.tar.gz
cru-c45a6e62298e972f5945f5f3461ed723aea80317.tar.bz2
cru-c45a6e62298e972f5945f5f3461ed723aea80317.zip
Merge pull request #37 from crupest/render
Refactor.
Diffstat (limited to 'src/ui/layout_base.hpp')
-rw-r--r--src/ui/layout_base.hpp102
1 files changed, 0 insertions, 102 deletions
diff --git a/src/ui/layout_base.hpp b/src/ui/layout_base.hpp
deleted file mode 100644
index 527d9f98..00000000
--- a/src/ui/layout_base.hpp
+++ /dev/null
@@ -1,102 +0,0 @@
-#pragma once
-
-// ReSharper disable once CppUnusedIncludeDirective
-#include "pre.hpp"
-
-#include "ui_base.hpp"
-
-namespace cru::ui
-{
- enum class Alignment
- {
- Center,
- Start,
- End
- };
-
- enum class MeasureMode
- {
- Exactly,
- Content,
- Stretch
- };
-
- enum class RectRange
- {
- Content, // content excluding padding, border and margin
- Padding, // only including content and padding
- HalfBorder, // including content, padding and half border
- FullBorder, // including content, padding and full border
- Margin // including content, padding, border and margin
- };
-
- struct LayoutSideParams final
- {
- constexpr static LayoutSideParams Exactly(const float length, const Alignment alignment = Alignment::Center)
- {
- return LayoutSideParams(MeasureMode::Exactly, length, alignment);
- }
-
- constexpr static LayoutSideParams Content(const Alignment alignment = Alignment::Center)
- {
- return LayoutSideParams(MeasureMode::Content, 0, alignment);
- }
-
- constexpr static LayoutSideParams Stretch(const Alignment alignment = Alignment::Center)
- {
- return LayoutSideParams(MeasureMode::Stretch, 0, alignment);
- }
-
- constexpr LayoutSideParams() = default;
-
- constexpr explicit LayoutSideParams(const MeasureMode mode, const float length, const Alignment alignment)
- : length(length), mode(mode), alignment(alignment)
- {
-
- }
-
- constexpr bool Validate() const
- {
- if (length < 0.0)
- return false;
- if (min.has_value() && min.value() < 0.0)
- return false;
- if (max.has_value() && max.value() < 0.0)
- return false;
- if (min.has_value() && max.has_value() && min.value() > max.value())
- return false;
- return true;
- }
-
- // only used in exactly mode, specify the exactly side length of content.
- float length = 0.0;
- MeasureMode mode = MeasureMode::Content;
- Alignment alignment = Alignment::Center;
-
- // min and max specify the min/max side length of content.
- // they are used as hint and respect the actual size that content needs.
- // when mode is exactly, length is coerced into the min-max range.
- std::optional<float> min = std::nullopt;
- std::optional<float> max = std::nullopt;
- };
-
- struct BasicLayoutParams final
- {
- BasicLayoutParams() = default;
- BasicLayoutParams(const BasicLayoutParams&) = default;
- BasicLayoutParams(BasicLayoutParams&&) = default;
- BasicLayoutParams& operator = (const BasicLayoutParams&) = default;
- BasicLayoutParams& operator = (BasicLayoutParams&&) = default;
- ~BasicLayoutParams() = default;
-
- bool Validate() const
- {
- return width.Validate() && height.Validate() && margin.Validate() && padding.Validate();
- }
-
- LayoutSideParams width;
- LayoutSideParams height;
- Thickness padding;
- Thickness margin;
- };
-}