diff options
Diffstat (limited to 'include/cru/ui/base.hpp')
-rw-r--r-- | include/cru/ui/base.hpp | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/include/cru/ui/base.hpp b/include/cru/ui/base.hpp index 703d61fc..fe53edd4 100644 --- a/include/cru/ui/base.hpp +++ b/include/cru/ui/base.hpp @@ -1,10 +1,15 @@ #pragma once #include "cru/common/base.hpp" -#include "cru/platform/graph_base.hpp" -#include "cru/platform/matrix.hpp" -#include "cru/platform/native/basic_types.hpp" +#include "cru/platform/graph/base.hpp" +#include "cru/platform/native/base.hpp" + +#include <functional> +#include <memory> +#include <optional> +#include <vector> namespace cru::ui { +//-------------------- region: import -------------------- using cru::platform::Color; using cru::platform::Ellipse; using cru::platform::Matrix; @@ -28,6 +33,12 @@ using cru::platform::colors::skyblue; using cru::platform::colors::white; } // namespace colors +//-------------------- region: forward declaration -------------------- +class Window; +class Control; +class ClickDetector; + +//-------------------- region: basic types -------------------- namespace internal { constexpr int align_start = 0; constexpr int align_end = align_start + 1; @@ -41,4 +52,77 @@ enum class Alignment { Center = internal::align_center, Stretch = internal::align_stretch }; + +struct CornerRadius { + constexpr CornerRadius() + : left_top(), right_top(), left_bottom(), right_bottom() {} + constexpr CornerRadius(const Point& value) + : left_top(value), + right_top(value), + left_bottom(value), + right_bottom(value) {} + constexpr CornerRadius(Point left_top, Point right_top, Point left_bottom, + Point right_bottom) + : left_top(left_top), + right_top(right_top), + left_bottom(left_bottom), + right_bottom(right_bottom) {} + + Point left_top; + Point right_top; + Point left_bottom; + Point right_bottom; +}; + +inline bool operator==(const CornerRadius& left, const CornerRadius& right) { + return left.left_top == right.left_top && + left.left_bottom == right.left_bottom && + left.right_top == right.right_top && + left.right_bottom == right.right_bottom; +} + +inline bool operator!=(const CornerRadius& left, const CornerRadius& right) { + return !(left == right); +} + +class CanvasPaintEventArgs { + public: + CanvasPaintEventArgs(platform::graph::IPainter* painter, + const Rect& paint_rect) + : painter_(painter), paint_rect_(paint_rect) {} + CRU_DEFAULT_COPY(CanvasPaintEventArgs) + CRU_DEFAULT_MOVE(CanvasPaintEventArgs) + ~CanvasPaintEventArgs() = default; + + platform::graph::IPainter* GetPainter() const { return painter_; } + Rect GetPaintRect() const { return paint_rect_; } + + private: + platform::graph::IPainter* painter_; + Rect paint_rect_; +}; + +enum class FlexDirection { + Horizontal, + HorizontalReverse, + Vertical, + VertivalReverse +}; + +using FlexMainAlignment = Alignment; +using FlexCrossAlignment = Alignment; + +struct FlexChildLayoutData { + // nullopt stands for looking at my content + std::optional<float> flex_basis = std::nullopt; + float flex_grow = 0; + float flex_shrink = 0; + // nullopt stands for looking at parent's setting + std::optional<FlexCrossAlignment> cross_alignment = std::nullopt; +}; + +struct StackChildLayoutData { + Alignment horizontal = Alignment::Start; + Alignment vertical = Alignment::Start; +}; } // namespace cru::ui |