aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/ui')
-rw-r--r--include/cru/ui/Base.hpp4
-rw-r--r--include/cru/ui/controls/Base.hpp10
-rw-r--r--include/cru/ui/controls/Button.hpp7
-rw-r--r--include/cru/ui/controls/Container.hpp2
-rw-r--r--include/cru/ui/controls/ContentControl.hpp (renamed from include/cru/ui/ContentControl.hpp)4
-rw-r--r--include/cru/ui/controls/Control.hpp (renamed from include/cru/ui/Control.hpp)8
-rw-r--r--include/cru/ui/controls/FlexLayout.hpp2
-rw-r--r--include/cru/ui/controls/LayoutControl.hpp (renamed from include/cru/ui/LayoutControl.hpp)2
-rw-r--r--include/cru/ui/controls/NoChildControl.hpp (renamed from include/cru/ui/NoChildControl.hpp)2
-rw-r--r--include/cru/ui/controls/StackLayout.hpp2
-rw-r--r--include/cru/ui/controls/TextBlock.hpp2
-rw-r--r--include/cru/ui/controls/TextBox.hpp3
-rw-r--r--include/cru/ui/controls/Window.hpp (renamed from include/cru/ui/Window.hpp)2
-rw-r--r--include/cru/ui/events/UiEvent.hpp (renamed from include/cru/ui/UiEvent.hpp)2
-rw-r--r--include/cru/ui/helper/ClickDetector.hpp (renamed from include/cru/ui/ClickDetector.hpp)18
-rw-r--r--include/cru/ui/helper/ShortcutHub.hpp (renamed from include/cru/ui/ShortcutHub.hpp)19
-rw-r--r--include/cru/ui/host/WindowHost.hpp50
-rw-r--r--include/cru/ui/render/RenderObject.hpp12
18 files changed, 76 insertions, 75 deletions
diff --git a/include/cru/ui/Base.hpp b/include/cru/ui/Base.hpp
index 39fbb035..8595258d 100644
--- a/include/cru/ui/Base.hpp
+++ b/include/cru/ui/Base.hpp
@@ -26,9 +26,11 @@ namespace mouse_buttons = cru::platform::gui::mouse_buttons;
namespace colors = cru::platform::colors;
//-------------------- region: forward declaration --------------------
+
+namespace controls {
class Window;
class Control;
-class ClickDetector;
+} // namespace controls
namespace host {
class WindowHost;
diff --git a/include/cru/ui/controls/Base.hpp b/include/cru/ui/controls/Base.hpp
index b550601b..82c31d1e 100644
--- a/include/cru/ui/controls/Base.hpp
+++ b/include/cru/ui/controls/Base.hpp
@@ -2,7 +2,7 @@
#include "../Base.hpp"
namespace cru::ui::controls {
-using ButtonStateStyle = BorderStyle;
+using ButtonStateStyle = ui::BorderStyle;
struct ButtonStyle {
// corresponds to ClickState::None
@@ -16,9 +16,9 @@ struct ButtonStyle {
};
struct TextBoxBorderStyle {
- BorderStyle normal;
- BorderStyle hover;
- BorderStyle focus;
- BorderStyle focus_hover;
+ ui::BorderStyle normal;
+ ui::BorderStyle hover;
+ ui::BorderStyle focus;
+ ui::BorderStyle focus_hover;
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/Button.hpp b/include/cru/ui/controls/Button.hpp
index a4f727d6..e8285507 100644
--- a/include/cru/ui/controls/Button.hpp
+++ b/include/cru/ui/controls/Button.hpp
@@ -1,8 +1,7 @@
#pragma once
-#include "../ContentControl.hpp"
-#include "Base.hpp"
+#include "ContentControl.hpp"
-#include "../ClickDetector.hpp"
+#include "../helper/ClickDetector.hpp"
namespace cru::ui::controls {
class Button : public ContentControl {
@@ -37,6 +36,6 @@ class Button : public ContentControl {
ButtonStyle style_;
- ClickDetector click_detector_;
+ helper::ClickDetector click_detector_;
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/Container.hpp b/include/cru/ui/controls/Container.hpp
index 304d402c..d9cb8aec 100644
--- a/include/cru/ui/controls/Container.hpp
+++ b/include/cru/ui/controls/Container.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include "../ContentControl.hpp"
+#include "ContentControl.hpp"
namespace cru::ui::controls {
class Container : public ContentControl {
diff --git a/include/cru/ui/ContentControl.hpp b/include/cru/ui/controls/ContentControl.hpp
index ba5b6b2f..47720a87 100644
--- a/include/cru/ui/ContentControl.hpp
+++ b/include/cru/ui/controls/ContentControl.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "Control.hpp"
-namespace cru::ui {
+namespace cru::ui::controls {
class ContentControl : public Control {
protected:
ContentControl() = default;
@@ -23,4 +23,4 @@ class ContentControl : public Control {
using Control::AddChild;
using Control::RemoveChild;
};
-} // namespace cru::ui
+} // namespace cru::ui::controls
diff --git a/include/cru/ui/Control.hpp b/include/cru/ui/controls/Control.hpp
index fe50624a..96aad2bd 100644
--- a/include/cru/ui/Control.hpp
+++ b/include/cru/ui/controls/Control.hpp
@@ -1,13 +1,13 @@
#pragma once
#include "Base.hpp"
-#include "UiEvent.hpp"
+#include "../events/UiEvent.hpp"
+#include "../render/Base.hpp"
#include "cru/common/Event.hpp"
-#include "render/Base.hpp"
#include <string_view>
-namespace cru::ui {
+namespace cru::ui::controls {
class Control : public Object {
friend host::WindowHost;
@@ -148,4 +148,4 @@ class Control : public Object {
std::shared_ptr<platform::gui::ICursor> cursor_ = nullptr;
};
-} // namespace cru::ui
+} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/FlexLayout.hpp b/include/cru/ui/controls/FlexLayout.hpp
index 0ffedba5..a6c6a40c 100644
--- a/include/cru/ui/controls/FlexLayout.hpp
+++ b/include/cru/ui/controls/FlexLayout.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include "../LayoutControl.hpp"
+#include "LayoutControl.hpp"
namespace cru::ui::controls {
class FlexLayout : public LayoutControl {
diff --git a/include/cru/ui/LayoutControl.hpp b/include/cru/ui/controls/LayoutControl.hpp
index 69d5cd0b..cbdb8aa2 100644
--- a/include/cru/ui/LayoutControl.hpp
+++ b/include/cru/ui/controls/LayoutControl.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "Control.hpp"
-namespace cru::ui {
+namespace cru::ui::controls {
class LayoutControl : public Control {
protected:
LayoutControl() = default;
diff --git a/include/cru/ui/NoChildControl.hpp b/include/cru/ui/controls/NoChildControl.hpp
index 0d8a8e34..562137f1 100644
--- a/include/cru/ui/NoChildControl.hpp
+++ b/include/cru/ui/controls/NoChildControl.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "Control.hpp"
-namespace cru::ui {
+namespace cru::ui::controls {
class NoChildControl : public Control {
protected:
NoChildControl() = default;
diff --git a/include/cru/ui/controls/StackLayout.hpp b/include/cru/ui/controls/StackLayout.hpp
index c0b95044..373b4681 100644
--- a/include/cru/ui/controls/StackLayout.hpp
+++ b/include/cru/ui/controls/StackLayout.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include "../LayoutControl.hpp"
+#include "LayoutControl.hpp"
namespace cru::ui::controls {
class StackLayout : public LayoutControl {
diff --git a/include/cru/ui/controls/TextBlock.hpp b/include/cru/ui/controls/TextBlock.hpp
index 8a9a3bff..fdfdb2fa 100644
--- a/include/cru/ui/controls/TextBlock.hpp
+++ b/include/cru/ui/controls/TextBlock.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include "../NoChildControl.hpp"
+#include "NoChildControl.hpp"
namespace cru::ui::controls {
template <typename TControl>
diff --git a/include/cru/ui/controls/TextBox.hpp b/include/cru/ui/controls/TextBox.hpp
index 5976f6da..91d38c61 100644
--- a/include/cru/ui/controls/TextBox.hpp
+++ b/include/cru/ui/controls/TextBox.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include "../NoChildControl.hpp"
-#include "Base.hpp"
+#include "NoChildControl.hpp"
#include <memory>
diff --git a/include/cru/ui/Window.hpp b/include/cru/ui/controls/Window.hpp
index 70423a14..616e2ee7 100644
--- a/include/cru/ui/Window.hpp
+++ b/include/cru/ui/controls/Window.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "LayoutControl.hpp"
-namespace cru::ui {
+namespace cru::ui::controls {
class Window final : public LayoutControl {
public:
static constexpr std::u16string_view control_type = u"Window";
diff --git a/include/cru/ui/UiEvent.hpp b/include/cru/ui/events/UiEvent.hpp
index c0b2a902..660b33f5 100644
--- a/include/cru/ui/UiEvent.hpp
+++ b/include/cru/ui/events/UiEvent.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include "Base.hpp"
+#include "../Base.hpp"
#include "cru/common/Event.hpp"
#include "cru/platform/gui/Keyboard.hpp"
diff --git a/include/cru/ui/ClickDetector.hpp b/include/cru/ui/helper/ClickDetector.hpp
index 4ffe5d05..0df77c60 100644
--- a/include/cru/ui/ClickDetector.hpp
+++ b/include/cru/ui/helper/ClickDetector.hpp
@@ -1,10 +1,10 @@
#pragma once
-#include "Control.hpp"
+#include "../controls/Control.hpp"
-namespace cru::ui {
+namespace cru::ui::helper {
class ClickEventArgs : Object {
public:
- ClickEventArgs(Control* sender, const Point& down_point,
+ ClickEventArgs(controls::Control* sender, const Point& down_point,
const Point& up_point, MouseButton button)
: sender_(sender),
down_point_(down_point),
@@ -16,13 +16,13 @@ class ClickEventArgs : Object {
~ClickEventArgs() override = default;
- Control* GetSender() const { return sender_; }
+ controls::Control* GetSender() const { return sender_; }
Point GetDownPoint() const { return down_point_; }
Point GetUpPoint() const { return up_point_; }
MouseButton GetButton() const { return button_; }
private:
- Control* sender_;
+ controls::Control* sender_;
Point down_point_;
Point up_point_;
MouseButton button_;
@@ -39,14 +39,14 @@ class ClickDetector : public Object {
CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::ClickDetector")
public:
- explicit ClickDetector(Control* control);
+ explicit ClickDetector(controls::Control* control);
CRU_DELETE_COPY(ClickDetector)
CRU_DELETE_MOVE(ClickDetector)
~ClickDetector() override = default;
- Control* GetControl() const { return control_; }
+ controls::Control* GetControl() const { return control_; }
ClickState GetState() const { return state_; }
@@ -69,7 +69,7 @@ class ClickDetector : public Object {
void SetState(ClickState state);
private:
- Control* control_;
+ controls::Control* control_;
ClickState state_;
@@ -84,4 +84,4 @@ class ClickDetector : public Object {
Point down_point_;
MouseButton button_;
};
-} // namespace cru::ui
+} // namespace cru::ui::helper
diff --git a/include/cru/ui/ShortcutHub.hpp b/include/cru/ui/helper/ShortcutHub.hpp
index 1145c661..a4ff2da2 100644
--- a/include/cru/ui/ShortcutHub.hpp
+++ b/include/cru/ui/helper/ShortcutHub.hpp
@@ -1,10 +1,9 @@
#pragma once
-#include "Base.hpp"
+#include "../Base.hpp"
-#include "cru/common/Base.hpp"
+#include "../events/UiEvent.hpp"
#include "cru/common/Event.hpp"
#include "cru/platform/gui/Keyboard.hpp"
-#include "cru/ui/UiEvent.hpp"
#include <cstddef>
#include <functional>
@@ -16,7 +15,7 @@
#include <unordered_map>
#include <vector>
-namespace cru::ui {
+namespace cru::ui::helper {
class ShortcutKeyBind {
public:
@@ -57,12 +56,12 @@ class ShortcutKeyBind {
platform::gui::KeyCode key_;
platform::gui::KeyModifier modifier_;
};
-} // namespace cru::ui
+} // namespace cru::ui::helper
namespace std {
template <>
-struct hash<cru::ui::ShortcutKeyBind> {
- std::size_t operator()(const cru::ui::ShortcutKeyBind& value) const {
+struct hash<cru::ui::helper::ShortcutKeyBind> {
+ std::size_t operator()(const cru::ui::helper::ShortcutKeyBind& value) const {
std::size_t result = 0;
cru::hash_combine(result, static_cast<int>(value.GetKey()));
cru::hash_combine(result, static_cast<int>(value.GetModifier()));
@@ -71,7 +70,7 @@ struct hash<cru::ui::ShortcutKeyBind> {
};
} // namespace std
-namespace cru::ui {
+namespace cru::ui::helper {
struct Shortcut {
// Just for debug.
std::u16string name;
@@ -112,7 +111,7 @@ class ShortcutHub : public Object {
const std::vector<ShortcutInfo>& GetShortcutByKeyBind(
const ShortcutKeyBind& key_bind) const;
- void Install(Control* control);
+ void Install(controls::Control* control);
void Uninstall();
private:
@@ -127,4 +126,4 @@ class ShortcutHub : public Object {
EventRevokerListGuard event_guard_;
};
-} // namespace cru::ui
+} // namespace cru::ui::helper
diff --git a/include/cru/ui/host/WindowHost.hpp b/include/cru/ui/host/WindowHost.hpp
index 81eabb52..56f37382 100644
--- a/include/cru/ui/host/WindowHost.hpp
+++ b/include/cru/ui/host/WindowHost.hpp
@@ -1,10 +1,10 @@
#pragma once
#include "../Base.hpp"
+#include "../render/Base.hpp"
#include "cru/common/Event.hpp"
#include "cru/platform/gui/UiApplication.hpp"
#include "cru/platform/gui/Window.hpp"
-#include "../render/Base.hpp"
#include <functional>
#include <memory>
@@ -19,7 +19,7 @@ class WindowHost : public Object {
CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::host::WindowHost")
public:
- WindowHost(Control* root_control);
+ WindowHost(controls::Control* root_control);
CRU_DELETE_COPY(WindowHost)
CRU_DELETE_MOVE(WindowHost)
@@ -61,13 +61,15 @@ class WindowHost : public Object {
// control. Even when mouse is captured by another control, this function
// return the control under cursor. You can use `GetMouseCaptureControl` to
// get more info.
- Control* GetMouseHoverControl() const { return mouse_hover_control_; }
+ controls::Control* GetMouseHoverControl() const {
+ return mouse_hover_control_;
+ }
//*************** region: focus ***************
- Control* GetFocusControl();
+ controls::Control* GetFocusControl();
- void SetFocusControl(Control* control);
+ void SetFocusControl(controls::Control* control);
//*************** region: focus ***************
@@ -81,12 +83,12 @@ class WindowHost : public Object {
// and capture is released, mouse enter event will be sent to the mouse-hover
// control. If mouse is not on the capturing control and capture is set, mouse
// leave event will be sent to the mouse-hover control.
- bool CaptureMouseFor(Control* control);
+ bool CaptureMouseFor(controls::Control* control);
// Return null if not captured.
- Control* GetMouseCaptureControl();
+ controls::Control* GetMouseCaptureControl();
- Control* HitTest(const Point& point);
+ controls::Control* HitTest(const Point& point);
void UpdateCursor();
@@ -94,23 +96,19 @@ class WindowHost : public Object {
//*************** region: native messages ***************
void OnNativeDestroy(platform::gui::INativeWindow* window, std::nullptr_t);
void OnNativePaint(platform::gui::INativeWindow* window, std::nullptr_t);
- void OnNativeResize(platform::gui::INativeWindow* window,
- const Size& size);
+ void OnNativeResize(platform::gui::INativeWindow* window, const Size& size);
void OnNativeFocus(platform::gui::INativeWindow* window,
cru::platform::gui::FocusChangeType focus);
- void OnNativeMouseEnterLeave(
- platform::gui::INativeWindow* window,
- cru::platform::gui::MouseEnterLeaveType enter);
+ void OnNativeMouseEnterLeave(platform::gui::INativeWindow* window,
+ cru::platform::gui::MouseEnterLeaveType enter);
void OnNativeMouseMove(platform::gui::INativeWindow* window,
const Point& point);
- void OnNativeMouseDown(
- platform::gui::INativeWindow* window,
- const platform::gui::NativeMouseButtonEventArgs& args);
- void OnNativeMouseUp(
- platform::gui::INativeWindow* window,
- const platform::gui::NativeMouseButtonEventArgs& args);
+ void OnNativeMouseDown(platform::gui::INativeWindow* window,
+ const platform::gui::NativeMouseButtonEventArgs& args);
+ void OnNativeMouseUp(platform::gui::INativeWindow* window,
+ const platform::gui::NativeMouseButtonEventArgs& args);
void OnNativeKeyDown(platform::gui::INativeWindow* window,
const platform::gui::NativeKeyEventArgs& args);
@@ -119,13 +117,13 @@ class WindowHost : public Object {
//*************** region: event dispatcher helper ***************
- void DispatchMouseHoverControlChangeEvent(Control* old_control,
- Control* new_control,
+ void DispatchMouseHoverControlChangeEvent(controls::Control* old_control,
+ controls::Control* new_control,
const Point& point, bool no_leave,
bool no_enter);
private:
- Control* root_control_ = nullptr;
+ controls::Control* root_control_ = nullptr;
render::RenderObject* root_render_object_ = nullptr;
platform::gui::INativeWindow* native_window_ = nullptr;
@@ -137,12 +135,12 @@ class WindowHost : public Object {
std::vector<EventRevokerGuard> event_revoker_guards_;
- Control* mouse_hover_control_ = nullptr;
+ controls::Control* mouse_hover_control_ = nullptr;
- Control* focus_control_;
+ controls::Control* focus_control_;
- Control* mouse_captured_control_ = nullptr;
+ controls::Control* mouse_captured_control_ = nullptr;
bool layout_prefer_to_fill_window_ = true;
};
-} // namespace cru::ui
+} // namespace cru::ui::host
diff --git a/include/cru/ui/render/RenderObject.hpp b/include/cru/ui/render/RenderObject.hpp
index 635a541e..2b166efc 100644
--- a/include/cru/ui/render/RenderObject.hpp
+++ b/include/cru/ui/render/RenderObject.hpp
@@ -62,8 +62,10 @@ class RenderObject : public Object {
RenderObject& operator=(RenderObject&& other) = delete;
~RenderObject() override = default;
- Control* GetAttachedControl() const { return control_; }
- void SetAttachedControl(Control* new_control) { control_ = new_control; }
+ controls::Control* GetAttachedControl() const { return control_; }
+ void SetAttachedControl(controls::Control* new_control) {
+ control_ = new_control;
+ }
host::WindowHost* GetWindowHost() const { return window_host_; }
@@ -135,7 +137,9 @@ class RenderObject : public Object {
// Add offset before pass point to children.
virtual RenderObject* HitTest(const Point& point) = 0;
- IEvent<host::WindowHost*>* AttachToHostEvent() { return &attach_to_host_event_; }
+ IEvent<host::WindowHost*>* AttachToHostEvent() {
+ return &attach_to_host_event_;
+ }
IEvent<std::nullptr_t>* DetachFromHostEvent() {
return &detach_from_host_event_;
}
@@ -208,7 +212,7 @@ class RenderObject : public Object {
void SetWindowHostRecursive(host::WindowHost* host);
private:
- Control* control_ = nullptr;
+ controls::Control* control_ = nullptr;
host::WindowHost* window_host_ = nullptr;
RenderObject* parent_ = nullptr;