diff options
author | crupest <crupest@outlook.com> | 2018-09-21 23:40:32 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-21 23:40:32 +0800 |
commit | 89f7277d47cd37f25a141ec2ebc13c4f6fceabd5 (patch) | |
tree | 1b2c2eb394e1d607eac98a1db32798a9a37e5bc8 /CruUI/ui | |
parent | 7abc054f1d33eeb72d665008083b82630781f6e0 (diff) | |
download | cru-89f7277d47cd37f25a141ec2ebc13c4f6fceabd5.tar.gz cru-89f7277d47cd37f25a141ec2ebc13c4f6fceabd5.tar.bz2 cru-89f7277d47cd37f25a141ec2ebc13c4f6fceabd5.zip |
Make some basic struct constexpr.
Diffstat (limited to 'CruUI/ui')
-rw-r--r-- | CruUI/ui/ui_base.h | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/CruUI/ui/ui_base.h b/CruUI/ui/ui_base.h index 21d41c6a..17e1bda9 100644 --- a/CruUI/ui/ui_base.h +++ b/CruUI/ui/ui_base.h @@ -19,12 +19,12 @@ namespace cru float y = 0; }; - inline bool operator==(const Point& left, const Point& right) + constexpr bool operator==(const Point& left, const Point& right) { return left.x == right.x && left.y == right.y; } - inline bool operator!=(const Point& left, const Point& right) + constexpr bool operator!=(const Point& left, const Point& right) { return !(left == right); } @@ -43,50 +43,55 @@ namespace cru float height = 0; }; - inline Size operator - (const Size& left, const Size& right) + constexpr Size operator + (const Size& left, const Size& right) + { + return Size(left.width + right.width, left.height + right.height); + } + + constexpr Size operator - (const Size& left, const Size& right) { return Size(left.width - right.width, left.height - right.height); } struct Rect { - Rect() = default; - Rect(const float left, const float top, const float width, const float height) + constexpr Rect() = default; + constexpr Rect(const float left, const float top, const float width, const float height) : left(left), top(top), width(width), height(height) { } - Rect(const Point& lefttop, const Size& size) + constexpr Rect(const Point& lefttop, const Size& size) : left(lefttop.x), top(lefttop.y), width(size.width), height(size.height) { } - static Rect FromVertices(const float left, const float top, const float right, const float bottom) + constexpr static Rect FromVertices(const float left, const float top, const float right, const float bottom) { return Rect(left, top, right - left, bottom - top); } - float GetRight() const + constexpr float GetRight() const { return left + width; } - float GetBottom() const + constexpr float GetBottom() const { return top + height; } - Point GetLeftTop() const + constexpr Point GetLeftTop() const { return Point(left, top); } - Point GetRightBottom() const + constexpr Point GetRightBottom() const { return Point(left + width, top + height); } - Size GetSize() const + constexpr Size GetSize() const { return Size(width, height); } - bool IsPointInside(const Point& point) const + constexpr bool IsPointInside(const Point& point) const { return point.x >= left && @@ -103,11 +108,12 @@ namespace cru struct Thickness { - Thickness() : Thickness(0) { } - explicit Thickness(const float width) + constexpr Thickness() : Thickness(0) { } + + constexpr explicit Thickness(const float width) : left(width), top(width), right(width), bottom(width) { } - Thickness(const float left, const float top, const float right, const float bottom) + constexpr Thickness(const float left, const float top, const float right, const float bottom) : left(left), top(top), right(right), bottom(bottom) { } |