aboutsummaryrefslogtreecommitdiff
path: root/src/ui/layout_base.h
diff options
context:
space:
mode:
authorYuqian Yang <crupest@outlook.com>2018-10-04 16:52:11 +0000
committerYuqian Yang <crupest@outlook.com>2018-10-04 16:52:11 +0000
commit7e870dd16e2f5b41fa6c6f687723aaa50c16274d (patch)
treebe2b26a42dc9fde97379f98f035113e08e0bc331 /src/ui/layout_base.h
parent30ecda8bb354d5982978af97aa90b5f49d9ea195 (diff)
parentc5384d496e9ed429ca2baa3ca5e586ff255235eb (diff)
downloadcru-7e870dd16e2f5b41fa6c6f687723aaa50c16274d.tar.gz
cru-7e870dd16e2f5b41fa6c6f687723aaa50c16274d.tar.bz2
cru-7e870dd16e2f5b41fa6c6f687723aaa50c16274d.zip
Merge branch '12-layout' into 'master'
Resolve "Add padding, margin, border to Control." Closes #12 See merge request crupest/CruUI!12
Diffstat (limited to 'src/ui/layout_base.h')
-rw-r--r--src/ui/layout_base.h62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/ui/layout_base.h b/src/ui/layout_base.h
index 126437cd..e1759da2 100644
--- a/src/ui/layout_base.h
+++ b/src/ui/layout_base.h
@@ -1,6 +1,5 @@
#pragma once
-#include "system_headers.h"
#include <unordered_set>
#include "base.h"
@@ -27,6 +26,40 @@ namespace cru
Stretch
};
+ struct Thickness
+ {
+ constexpr static Thickness Zero()
+ {
+ return Thickness(0);
+ }
+
+ constexpr Thickness() : Thickness(0) { }
+
+ constexpr explicit Thickness(const float width)
+ : left(width), top(width), right(width), bottom(width) { }
+
+ constexpr explicit Thickness(const float horizontal, const float vertical)
+ : left(horizontal), top(vertical), right(horizontal), bottom(vertical) { }
+
+ constexpr Thickness(const float left, const float top, const float right, const float bottom)
+ : left(left), top(top), right(right), bottom(bottom) { }
+
+ float GetHorizontalTotal() const
+ {
+ return left + right;
+ }
+
+ float GetVerticalTotal() const
+ {
+ return top + bottom;
+ }
+
+ float left;
+ float top;
+ float right;
+ float bottom;
+ };
+
struct LayoutSideParams final
{
constexpr static LayoutSideParams Exactly(const float length, const Alignment alignment = Alignment::Center)
@@ -54,14 +87,7 @@ namespace cru
constexpr bool Validate() const
{
- if (mode == MeasureMode::Exactly && length < 0.0)
- {
-#ifdef CRU_DEBUG
- ::OutputDebugStringW(L"LayoutSideParams validation error: mode is Exactly but length is less than 0.\n");
-#endif
- return false;
- }
- return true;
+ return !(mode == MeasureMode::Exactly && length < 0.0);
}
float length = 0.0;
@@ -80,25 +106,13 @@ namespace cru
bool Validate() const
{
- if (!width.Validate())
- {
-#ifdef CRU_DEBUG
- ::OutputDebugStringW(L"Width(LayoutSideParams) is not valid.");
-#endif
- return false;
- }
- if (!height.Validate())
- {
-#ifdef CRU_DEBUG
- ::OutputDebugStringW(L"Height(LayoutSideParams) is not valid.");
-#endif
- return false;
- }
- return true;
+ return width.Validate() && height.Validate();
}
LayoutSideParams width;
LayoutSideParams height;
+ Thickness padding;
+ Thickness margin;
};