aboutsummaryrefslogtreecommitdiff
path: root/src/ui/ui_base.hpp
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2018-11-10 22:39:26 +0800
committerGitHub <noreply@github.com>2018-11-10 22:39:26 +0800
commit8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df (patch)
tree2d00b4f6a7af93a13d271d78e6ef682c335c91c7 /src/ui/ui_base.hpp
parent7c2fb4578b6997b5ab0d98121cda253f734139c1 (diff)
parentb2eced8d9719eb00796c2674fc2c23ab0c9bbdbf (diff)
downloadcru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.tar.gz
cru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.tar.bz2
cru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.zip
Merge pull request #11 from crupest/listitem
Add ListItem.
Diffstat (limited to 'src/ui/ui_base.hpp')
-rw-r--r--src/ui/ui_base.hpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ui/ui_base.hpp b/src/ui/ui_base.hpp
index 8daa43d7..c20d44b6 100644
--- a/src/ui/ui_base.hpp
+++ b/src/ui/ui_base.hpp
@@ -63,6 +63,45 @@ namespace cru::ui
return !(left == right);
}
+ 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 Validate() const
+ {
+ return left >= 0.0 && top >= 0.0 && right >= 0.0 && bottom >= 0.0;
+ }
+
+ float left;
+ float top;
+ float right;
+ float bottom;
+ };
+
struct Rect
{
constexpr Rect() = default;
@@ -101,6 +140,11 @@ namespace cru::ui
return Size(width, height);
}
+ constexpr Rect Shrink(const Thickness& thickness) const
+ {
+ return Rect(left + thickness.left, top + thickness.top, width - thickness.GetHorizontalTotal(), height - thickness.GetVerticalTotal());
+ }
+
constexpr bool IsPointInside(const Point& point) const
{
return
@@ -154,4 +198,5 @@ namespace cru::ui
bool IsKeyDown(int virtual_code);
bool IsKeyToggled(int virtual_code);
+ bool IsAnyMouseButtonDown();
}