diff options
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/common/event.hpp | 11 | ||||
-rw-r--r-- | include/cru/common/format.hpp | 4 | ||||
-rw-r--r-- | include/cru/platform/basic_types.hpp | 1 | ||||
-rw-r--r-- | include/cru/platform/matrix.hpp | 7 | ||||
-rw-r--r-- | include/cru/platform/painter.hpp | 2 | ||||
-rw-r--r-- | include/cru/platform/win/win_text_layout.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/controls/button.hpp | 39 | ||||
-rw-r--r-- | include/cru/ui/controls/flex_layout.hpp | 41 | ||||
-rw-r--r-- | include/cru/ui/controls/text_block.hpp | 39 | ||||
-rw-r--r-- | include/cru/ui/render/text_render_object.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/window.hpp | 2 |
11 files changed, 137 insertions, 13 deletions
diff --git a/include/cru/common/event.hpp b/include/cru/common/event.hpp index 763f8378..6228d867 100644 --- a/include/cru/common/event.hpp +++ b/include/cru/common/event.hpp @@ -22,7 +22,7 @@ class Event { : resolver_(resolver), token_(token) {} EventHandlerRevokerImpl(const EventHandlerRevokerImpl& other) = default; EventHandlerRevokerImpl(EventHandlerRevokerImpl&& other) = default; - EventHandlerRevokerImpl& operator=(EventHandlerRevokerImpl&& other) = + EventHandlerRevokerImpl& operator=(const EventHandlerRevokerImpl& other) = default; EventHandlerRevokerImpl& operator=(EventHandlerRevokerImpl&& other) = default; @@ -31,7 +31,7 @@ class Event { void operator()() { const auto true_resolver = resolver_.lock(); if (true_resolver) { - true_resolver()->RemoveHandler(token_); + (*true_resolver)()->RemoveHandler(token_); } } @@ -63,10 +63,11 @@ class Event { return EventHandlerRevoker(EventHandlerRevokerImpl(event_resolver_, token)); } - template <typename... Args> - EventHandlerRevoker AddHandler(Args&& args...) { + template <typename Arg> + EventHandlerRevoker AddHandler(Arg&& handler) { + static_assert(std::is_invocable_v<Arg, TArgs...>, "Handler not invocable."); const auto token = current_token_++; - handlers_.emplace(token, EventHandler(std::forward<Args>(args)...)); + handlers_.emplace(token, EventHandler(std::forward<Arg>(handler))); return EventHandlerRevoker(EventHandlerRevokerImpl(event_resolver_, token)); } diff --git a/include/cru/common/format.hpp b/include/cru/common/format.hpp index 1fb6863a..f085635a 100644 --- a/include/cru/common/format.hpp +++ b/include/cru/common/format.hpp @@ -83,7 +83,7 @@ inline std::string_view FormatToString(const std::string& string, } inline std::wstring_view FormatToString(const std::wstring_view& string, - details::TypeTag<String>) { + details::TypeTag<std::wstring>) { return string; } @@ -93,7 +93,7 @@ inline std::string_view FormatToString(const std::string_view& string, } inline std::wstring_view FormatToString(const wchar_t* string, - details::TypeTag<String>) { + details::TypeTag<std::wstring>) { return std::wstring_view(string); } diff --git a/include/cru/platform/basic_types.hpp b/include/cru/platform/basic_types.hpp index 81ee3e34..e6ab4b59 100644 --- a/include/cru/platform/basic_types.hpp +++ b/include/cru/platform/basic_types.hpp @@ -1,3 +1,4 @@ +#pragma once #include "cru/common/pre_config.hpp" namespace cru::platform { diff --git a/include/cru/platform/matrix.hpp b/include/cru/platform/matrix.hpp index e5e5cf42..37e4725e 100644 --- a/include/cru/platform/matrix.hpp +++ b/include/cru/platform/matrix.hpp @@ -1,3 +1,4 @@ +#pragma once #include "cru/common/pre_config.hpp" #include "cru/common/ui_base.hpp" @@ -29,12 +30,14 @@ struct Matrix { m31 == 0.0f && m32 == 0.0f; } - Matrix& operator*=(const Matrix& matrix) const { + Matrix& operator*=(const Matrix& matrix) { *this = Product(*this, matrix); return *this; } - Matrix operator*(const Matrix& matrix) const { return Product(this, matrix); } + Matrix operator*(const Matrix& matrix) const { + return Product(*this, matrix); + } ui::Point TransformPoint(const ui::Point& point) const { return ui::Point{point.x * m11 + point.y * m21 + m31, diff --git a/include/cru/platform/painter.hpp b/include/cru/platform/painter.hpp index eaaf61f9..b7b89fc9 100644 --- a/include/cru/platform/painter.hpp +++ b/include/cru/platform/painter.hpp @@ -19,7 +19,7 @@ struct Painter : virtual Interface { virtual void StrokeGeometry(Geometry* geometry, Brush* brush, float width) = 0; virtual void FillGeometry(Geometry* geometry, Brush* brush) = 0; - virtual void DrawText(const ui::Point& offset, TextLayout* text_layout, Brush* brush); + virtual void DrawText(const ui::Point& offset, TextLayout* text_layout, Brush* brush) = 0; virtual void EndDraw() = 0; virtual bool IsDisposed() = 0; }; diff --git a/include/cru/platform/win/win_text_layout.hpp b/include/cru/platform/win/win_text_layout.hpp index 9c93aa8c..dfb54264 100644 --- a/include/cru/platform/win/win_text_layout.hpp +++ b/include/cru/platform/win/win_text_layout.hpp @@ -17,7 +17,7 @@ class WinTextLayout : public Object, public virtual TextLayout { WinTextLayout(WinTextLayout&& other) = delete; WinTextLayout& operator=(const WinTextLayout& other) = delete; WinTextLayout& operator=(WinTextLayout&& other) = delete; - ~WinTextLayout() override; + ~WinTextLayout() override = default; std::wstring GetText() override; void SetText(std::wstring new_text) override; diff --git a/include/cru/ui/controls/button.hpp b/include/cru/ui/controls/button.hpp new file mode 100644 index 00000000..348416c5 --- /dev/null +++ b/include/cru/ui/controls/button.hpp @@ -0,0 +1,39 @@ +#pragma once +#include "../content_control.hpp" + +#include <memory> + +namespace cru::ui::render { +class BorderRenderObject; +} + +namespace cru::ui::controls { +class Button : public ContentControl { + public: + static constexpr auto control_type = L"Button"; + + static Button* Create() { return new Button(); } + + protected: + Button(); + + public: + Button(const Button& other) = delete; + Button(Button&& other) = delete; + Button& operator=(const Button& other) = delete; + Button& operator=(Button&& other) = delete; + ~Button() override = default; + + std::wstring_view GetControlType() const override final { + return control_type; + } + + render::RenderObject* GetRenderObject() const override; + + protected: + void OnChildChanged(Control* old_child, Control* new_child) override; + + private: + std::shared_ptr<render::BorderRenderObject> render_object_{}; +}; +} // namespace cru::ui::controls diff --git a/include/cru/ui/controls/flex_layout.hpp b/include/cru/ui/controls/flex_layout.hpp new file mode 100644 index 00000000..7422bc05 --- /dev/null +++ b/include/cru/ui/controls/flex_layout.hpp @@ -0,0 +1,41 @@ +#pragma once +#include "../layout_control.hpp" + +#include <memory> + +namespace cru::ui::render { +class FlexLayoutRenderObject; +} + +namespace cru::ui::controls { + +class FlexLayout : public LayoutControl { + public: + static constexpr auto control_type = L"FlexLayout"; + + static FlexLayout* Create() { return new FlexLayout(); } + + protected: + FlexLayout(); + + public: + FlexLayout(const FlexLayout& other) = delete; + FlexLayout(FlexLayout&& other) = delete; + FlexLayout& operator=(const FlexLayout& other) = delete; + FlexLayout& operator=(FlexLayout&& other) = delete; + ~FlexLayout() override = default; + + std::wstring_view GetControlType() const override final { + return control_type; + } + + render::RenderObject* GetRenderObject() const override; + + protected: + void OnAddChild(Control* child, int position) override; + void OnRemoveChild(Control* child, int position) override; + + private: + std::shared_ptr<render::FlexLayoutRenderObject> render_object_; +}; +} // namespace cru::ui::controls diff --git a/include/cru/ui/controls/text_block.hpp b/include/cru/ui/controls/text_block.hpp new file mode 100644 index 00000000..45cd12b9 --- /dev/null +++ b/include/cru/ui/controls/text_block.hpp @@ -0,0 +1,39 @@ +#pragma once +#include "../no_child_control.hpp" + +#include <memory> + +namespace cru::ui::render { +class TextRenderObject; +} + +namespace cru::ui::controls { +class TextBlock : public NoChildControl { + public: + static constexpr auto control_type = L"TextBlock"; + + static TextBlock* Create() { return new TextBlock(); } + + protected: + TextBlock(); + + public: + TextBlock(const TextBlock& other) = delete; + TextBlock(TextBlock&& other) = delete; + TextBlock& operator=(const TextBlock& other) = delete; + TextBlock& operator=(TextBlock&& other) = delete; + ~TextBlock() override = default; + + std::wstring_view GetControlType() const override final { + return control_type; + } + + render::RenderObject* GetRenderObject() const override; + + std::wstring GetText() const; + void SetText(std::wstring text); + + private: + std::shared_ptr<render::TextRenderObject> render_object_; +}; +} // namespace cru::ui::controls diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp index 329af18a..527fcd71 100644 --- a/include/cru/ui/render/text_render_object.hpp +++ b/include/cru/ui/render/text_render_object.hpp @@ -21,7 +21,7 @@ class TextRenderObject : public RenderObject { TextRenderObject(TextRenderObject&& other) = delete; TextRenderObject& operator=(const TextRenderObject& other) = delete; TextRenderObject& operator=(TextRenderObject&& other) = delete; - ~TextRenderObject() override; + ~TextRenderObject() override = default; std::wstring GetText() const; void SetText(std::wstring new_text); diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp index 94deb4c5..991ebf70 100644 --- a/include/cru/ui/window.hpp +++ b/include/cru/ui/window.hpp @@ -38,7 +38,7 @@ class Window final : public ContentControl { render::RenderObject* GetRenderObject() const override; - platform::NativeWindow* GetNativeWindow() const; + platform::NativeWindow* GetNativeWindow() const { return native_window_; } Control* GetMouseHoverControl() const { return mouse_hover_control_; } |