aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-30 11:25:57 +0800
committercrupest <crupest@outlook.com>2020-10-30 11:25:57 +0800
commita176c40ba0f913f98e966f11bad557833ae6dc57 (patch)
tree717f43cb8d6c8c189840d00df68c3d0463d94bdd
parent624552fb112f29b91dd96f9543e813b5ee16e87b (diff)
downloadcru-a176c40ba0f913f98e966f11bad557833ae6dc57.tar.gz
cru-a176c40ba0f913f98e966f11bad557833ae6dc57.tar.bz2
cru-a176c40ba0f913f98e966f11bad557833ae6dc57.zip
...
-rw-r--r--demos/main/main.cpp2
-rw-r--r--include/cru/ui/Base.hpp3
-rw-r--r--include/cru/ui/Control.hpp10
-rw-r--r--include/cru/ui/Window.hpp2
-rw-r--r--include/cru/ui/host/WindowHost.hpp (renamed from include/cru/ui/WindowHost.hpp)8
-rw-r--r--include/cru/ui/render/RenderObject.hpp12
-rw-r--r--src/ui/CMakeLists.txt6
-rw-r--r--src/ui/Control.cpp9
-rw-r--r--src/ui/Window.cpp4
-rw-r--r--src/ui/controls/TextControlService.hpp4
-rw-r--r--src/ui/host/RoutedEventDispatch.hpp (renamed from src/ui/RoutedEventDispatch.hpp)0
-rw-r--r--src/ui/host/WindowHost.cpp (renamed from src/ui/WindowHost.cpp)4
-rw-r--r--src/ui/render/RenderObject.cpp4
13 files changed, 35 insertions, 33 deletions
diff --git a/demos/main/main.cpp b/demos/main/main.cpp
index 6bd7fb4e..5546f3dd 100644
--- a/demos/main/main.cpp
+++ b/demos/main/main.cpp
@@ -3,7 +3,7 @@
#include "cru/platform/gui/Window.hpp"
#include "cru/ui/Base.hpp"
#include "cru/ui/Window.hpp"
-#include "cru/ui/WindowHost.hpp"
+#include "cru/ui/host/WindowHost.hpp"
#include "cru/ui/controls/Button.hpp"
#include "cru/ui/controls/FlexLayout.hpp"
#include "cru/ui/controls/TextBlock.hpp"
diff --git a/include/cru/ui/Base.hpp b/include/cru/ui/Base.hpp
index 36d0eb78..39fbb035 100644
--- a/include/cru/ui/Base.hpp
+++ b/include/cru/ui/Base.hpp
@@ -29,7 +29,10 @@ namespace colors = cru::platform::colors;
class Window;
class Control;
class ClickDetector;
+
+namespace host {
class WindowHost;
+}
namespace render {
class RenderObject;
diff --git a/include/cru/ui/Control.hpp b/include/cru/ui/Control.hpp
index 5f381965..fe50624a 100644
--- a/include/cru/ui/Control.hpp
+++ b/include/cru/ui/Control.hpp
@@ -9,7 +9,7 @@
namespace cru::ui {
class Control : public Object {
- friend WindowHost;
+ friend host::WindowHost;
protected:
Control();
@@ -26,7 +26,7 @@ class Control : public Object {
//*************** region: tree ***************
public:
- WindowHost* GetWindowHost() const;
+ host::WindowHost* GetWindowHost() const;
Control* GetParent() const { return parent_; }
@@ -131,8 +131,8 @@ class Control : public Object {
virtual void OnAddChild(Control* child, Index position);
virtual void OnRemoveChild(Control* child, Index position);
virtual void OnParentChanged(Control* old_parent, Control* new_parent);
- virtual void OnAttachToHost(WindowHost* host);
- virtual void OnDetachFromHost(WindowHost* host);
+ virtual void OnAttachToHost(host::WindowHost* host);
+ virtual void OnDetachFromHost(host::WindowHost* host);
protected:
virtual void OnMouseHoverChange(bool newHover) { CRU_UNUSED(newHover) }
@@ -141,7 +141,7 @@ class Control : public Object {
Control* parent_ = nullptr;
std::vector<Control*> children_;
- WindowHost* window_host_ = nullptr;
+ host::WindowHost* window_host_ = nullptr;
private:
bool is_mouse_over_ = false;
diff --git a/include/cru/ui/Window.hpp b/include/cru/ui/Window.hpp
index 0739e3dc..70423a14 100644
--- a/include/cru/ui/Window.hpp
+++ b/include/cru/ui/Window.hpp
@@ -29,7 +29,7 @@ class Window final : public LayoutControl {
void OnRemoveChild(Control* child, Index position) override;
private:
- std::unique_ptr<WindowHost> window_host_;
+ std::unique_ptr<host::WindowHost> window_host_;
std::unique_ptr<render::StackLayoutRenderObject> render_object_;
};
diff --git a/include/cru/ui/WindowHost.hpp b/include/cru/ui/host/WindowHost.hpp
index 7f7d62f0..77ed937f 100644
--- a/include/cru/ui/WindowHost.hpp
+++ b/include/cru/ui/host/WindowHost.hpp
@@ -1,19 +1,19 @@
#pragma once
-#include "Base.hpp"
+#include "../Base.hpp"
#include "cru/common/Event.hpp"
#include "cru/platform/gui/UiApplication.hpp"
#include "cru/platform/gui/Window.hpp"
-#include "render/Base.hpp"
+#include "../render/Base.hpp"
#include <functional>
-namespace cru::ui {
+namespace cru::ui::host {
struct AfterLayoutEventArgs {};
// The bridge between control tree and native window.
class WindowHost : public Object {
- CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::WindowHost")
+ CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::host::WindowHost")
public:
WindowHost(Control* root_control);
diff --git a/include/cru/ui/render/RenderObject.hpp b/include/cru/ui/render/RenderObject.hpp
index 436cf6b2..635a541e 100644
--- a/include/cru/ui/render/RenderObject.hpp
+++ b/include/cru/ui/render/RenderObject.hpp
@@ -39,7 +39,7 @@ namespace cru::ui::render {
// Size OnMeasureContent(const MeasureRequirement& requirement) override;
// void OnLayoutContent(const Rect& content_rect) override;
class RenderObject : public Object {
- friend WindowHost;
+ friend host::WindowHost;
CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::render::RenderObject")
@@ -65,7 +65,7 @@ class RenderObject : public Object {
Control* GetAttachedControl() const { return control_; }
void SetAttachedControl(Control* new_control) { control_ = new_control; }
- WindowHost* GetWindowHost() const { return window_host_; }
+ host::WindowHost* GetWindowHost() const { return window_host_; }
RenderObject* GetParent() const { return parent_; }
@@ -135,7 +135,7 @@ class RenderObject : public Object {
// Add offset before pass point to children.
virtual RenderObject* HitTest(const Point& point) = 0;
- IEvent<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_;
}
@@ -205,11 +205,11 @@ class RenderObject : public Object {
private:
void SetParent(RenderObject* new_parent);
- void SetWindowHostRecursive(WindowHost* host);
+ void SetWindowHostRecursive(host::WindowHost* host);
private:
Control* control_ = nullptr;
- WindowHost* window_host_ = nullptr;
+ host::WindowHost* window_host_ = nullptr;
RenderObject* parent_ = nullptr;
std::vector<RenderObject*> children_{};
@@ -225,7 +225,7 @@ class RenderObject : public Object {
Thickness margin_{};
Thickness padding_{};
- Event<WindowHost*> attach_to_host_event_;
+ Event<host::WindowHost*> attach_to_host_event_;
Event<std::nullptr_t> detach_from_host_event_;
};
} // namespace cru::ui::render
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 45f64c88..d7b924cb 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -2,7 +2,7 @@ set(CRU_UI_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/ui)
add_library(cru_ui STATIC
Helper.hpp
- RoutedEventDispatch.hpp
+ host/RoutedEventDispatch.hpp
ClickDetector.cpp
ContentControl.cpp
@@ -14,7 +14,6 @@ add_library(cru_ui STATIC
UiEvent.cpp
UiManager.cpp
Window.cpp
- WindowHost.cpp
controls/Button.cpp
controls/Container.cpp
controls/FlexLayout.cpp
@@ -22,6 +21,7 @@ add_library(cru_ui STATIC
controls/TextBlock.cpp
controls/TextBox.cpp
controls/TextControlService.hpp
+ host/WindowHost.cpp
render/BorderRenderObject.cpp
render/CanvasRenderObject.cpp
render/FlexLayoutRenderObject.cpp
@@ -43,7 +43,6 @@ target_sources(cru_ui PUBLIC
${CRU_UI_INCLUDE_DIR}/UiEvent.hpp
${CRU_UI_INCLUDE_DIR}/UiManager.hpp
${CRU_UI_INCLUDE_DIR}/Window.hpp
- ${CRU_UI_INCLUDE_DIR}/WindowHost.hpp
${CRU_UI_INCLUDE_DIR}/controls/Base.hpp
${CRU_UI_INCLUDE_DIR}/controls/Button.hpp
${CRU_UI_INCLUDE_DIR}/controls/Container.hpp
@@ -51,6 +50,7 @@ target_sources(cru_ui PUBLIC
${CRU_UI_INCLUDE_DIR}/controls/StackLayout.hpp
${CRU_UI_INCLUDE_DIR}/controls/TextBox.hpp
${CRU_UI_INCLUDE_DIR}/controls/TextBlock.hpp
+ ${CRU_UI_INCLUDE_DIR}/host/WindowHost.hpp
${CRU_UI_INCLUDE_DIR}/render/Base.hpp
${CRU_UI_INCLUDE_DIR}/render/BorderRenderObject.hpp
${CRU_UI_INCLUDE_DIR}/render/CanvasRenderObject.hpp
diff --git a/src/ui/Control.cpp b/src/ui/Control.cpp
index cae48c66..23a3cef2 100644
--- a/src/ui/Control.cpp
+++ b/src/ui/Control.cpp
@@ -1,11 +1,10 @@
#include "cru/ui/Control.hpp"
-#include "RoutedEventDispatch.hpp"
#include "cru/common/Base.hpp"
#include "cru/platform/gui/Cursor.hpp"
#include "cru/platform/gui/UiApplication.hpp"
#include "cru/ui/Base.hpp"
-#include "cru/ui/WindowHost.hpp"
+#include "cru/ui/host/WindowHost.hpp"
#include "cru/ui/render/RenderObject.hpp"
#include <memory>
@@ -31,7 +30,7 @@ Control::~Control() {
for (const auto child : children_) delete child;
}
-WindowHost* Control::GetWindowHost() const { return window_host_; }
+host::WindowHost* Control::GetWindowHost() const { return window_host_; }
void Control::TraverseDescendants(
const std::function<void(Control*)>& predicate) {
@@ -152,7 +151,7 @@ void Control::OnParentChanged(Control* old_parent, Control* new_parent) {
CRU_UNUSED(new_parent)
}
-void Control::OnAttachToHost(WindowHost* host) { CRU_UNUSED(host) }
+void Control::OnAttachToHost(host::WindowHost* host) { CRU_UNUSED(host) }
-void Control::OnDetachFromHost(WindowHost* host) { CRU_UNUSED(host) }
+void Control::OnDetachFromHost(host::WindowHost* host) { CRU_UNUSED(host) }
} // namespace cru::ui
diff --git a/src/ui/Window.cpp b/src/ui/Window.cpp
index 051e67ef..c49140a4 100644
--- a/src/ui/Window.cpp
+++ b/src/ui/Window.cpp
@@ -1,7 +1,7 @@
#include "cru/ui/Window.hpp"
#include "cru/common/Base.hpp"
-#include "cru/ui/WindowHost.hpp"
+#include "cru/ui/host/WindowHost.hpp"
#include "cru/ui/render/Base.hpp"
#include "cru/ui/render/StackLayoutRenderObject.hpp"
@@ -10,7 +10,7 @@ Window* Window::CreateOverlapped() { return new Window(); }
Window::Window() : render_object_(new render::StackLayoutRenderObject()) {
render_object_->SetAttachedControl(this);
- window_host_ = std::make_unique<WindowHost>(this);
+ window_host_ = std::make_unique<host::WindowHost>(this);
}
Window::~Window() {}
diff --git a/src/ui/controls/TextControlService.hpp b/src/ui/controls/TextControlService.hpp
index 8ad87416..a7e4e440 100644
--- a/src/ui/controls/TextControlService.hpp
+++ b/src/ui/controls/TextControlService.hpp
@@ -12,7 +12,7 @@
#include "cru/ui/DebugFlags.hpp"
#include "cru/ui/ShortcutHub.hpp"
#include "cru/ui/UiEvent.hpp"
-#include "cru/ui/WindowHost.hpp"
+#include "cru/ui/host/WindowHost.hpp"
#include "cru/ui/render/CanvasRenderObject.hpp"
#include "cru/ui/render/ScrollRenderObject.hpp"
#include "cru/ui/render/TextRenderObject.hpp"
@@ -136,7 +136,7 @@ class TextControlService : public Object {
}
platform::gui::IInputMethodContext* GetInputMethodContext() {
- WindowHost* host = this->control_->GetWindowHost();
+ host::WindowHost* host = this->control_->GetWindowHost();
if (!host) return nullptr;
platform::gui::INativeWindow* native_window = host->GetNativeWindow();
if (!native_window) return nullptr;
diff --git a/src/ui/RoutedEventDispatch.hpp b/src/ui/host/RoutedEventDispatch.hpp
index de94a598..de94a598 100644
--- a/src/ui/RoutedEventDispatch.hpp
+++ b/src/ui/host/RoutedEventDispatch.hpp
diff --git a/src/ui/WindowHost.cpp b/src/ui/host/WindowHost.cpp
index b0908e4f..eac247c1 100644
--- a/src/ui/WindowHost.cpp
+++ b/src/ui/host/WindowHost.cpp
@@ -1,4 +1,4 @@
-#include "cru/ui/WindowHost.hpp"
+#include "cru/ui/host/WindowHost.hpp"
#include "RoutedEventDispatch.hpp"
#include "cru/common/Logger.hpp"
@@ -13,7 +13,7 @@
#include <cstddef>
-namespace cru::ui {
+namespace cru::ui::host {
using platform::gui::INativeWindow;
using platform::gui::IUiApplication;
diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp
index 09410113..a40ce9b8 100644
--- a/src/ui/render/RenderObject.cpp
+++ b/src/ui/render/RenderObject.cpp
@@ -3,7 +3,7 @@
#include "cru/common/Logger.hpp"
#include "cru/platform/graphics/util/Painter.hpp"
#include "cru/ui/DebugFlags.hpp"
-#include "cru/ui/WindowHost.hpp"
+#include "cru/ui/host/WindowHost.hpp"
#include <algorithm>
#include <string>
@@ -303,7 +303,7 @@ std::u16string RenderObject::GetDebugPathInTree() const {
return result;
}
-void RenderObject::SetWindowHostRecursive(WindowHost* host) {
+void RenderObject::SetWindowHostRecursive(host::WindowHost* host) {
if (window_host_ != nullptr) {
detach_from_host_event_.Raise(nullptr);
}