diff options
author | crupest <crupest@outlook.com> | 2020-10-28 20:51:55 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-28 20:51:55 +0800 |
commit | 6ce70ed4b08c7db20b6b384be26c7fc4e11c98de (patch) | |
tree | 208ca80036c186d18e0ec25491881a760075ae83 | |
parent | 8f27c928c2ce4f3617c9113582a93da10721114c (diff) | |
download | cru-6ce70ed4b08c7db20b6b384be26c7fc4e11c98de.tar.gz cru-6ce70ed4b08c7db20b6b384be26c7fc4e11c98de.tar.bz2 cru-6ce70ed4b08c7db20b6b384be26c7fc4e11c98de.zip |
...
-rw-r--r-- | demos/main/main.cpp | 4 | ||||
-rw-r--r-- | include/cru/ui/Base.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/Control.hpp | 12 | ||||
-rw-r--r-- | include/cru/ui/Window.hpp | 6 | ||||
-rw-r--r-- | include/cru/ui/WindowHost.hpp (renamed from include/cru/ui/UiHost.hpp) | 26 | ||||
-rw-r--r-- | include/cru/ui/render/RenderObject.hpp | 6 | ||||
-rw-r--r-- | include/cru/ui/render/WindowRenderObject.hpp | 2 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/ui/ContentControl.cpp | 6 | ||||
-rw-r--r-- | src/ui/Control.cpp | 20 | ||||
-rw-r--r-- | src/ui/LayoutControl.cpp | 4 | ||||
-rw-r--r-- | src/ui/Window.cpp | 4 | ||||
-rw-r--r-- | src/ui/WindowHost.cpp (renamed from src/ui/UiHost.cpp) | 92 | ||||
-rw-r--r-- | src/ui/controls/TextControlService.hpp | 6 | ||||
-rw-r--r-- | src/ui/render/RenderObject.cpp | 6 | ||||
-rw-r--r-- | src/ui/render/WindowRenderObject.cpp | 4 |
16 files changed, 103 insertions, 101 deletions
diff --git a/demos/main/main.cpp b/demos/main/main.cpp index 10b43b0f..f7635231 100644 --- a/demos/main/main.cpp +++ b/demos/main/main.cpp @@ -2,7 +2,7 @@ #include "cru/platform/native/UiApplication.hpp" #include "cru/platform/native/Window.hpp" #include "cru/ui/Base.hpp" -#include "cru/ui/UiHost.hpp" +#include "cru/ui/WindowHost.hpp" #include "cru/ui/Window.hpp" #include "cru/ui/controls/Button.hpp" #include "cru/ui/controls/FlexLayout.hpp" @@ -45,7 +45,7 @@ int main() { const auto text_box = TextBox::Create(); flex_layout->AddChild(text_box, 2); - window->GetUiHost()->GetNativeWindowResolver()->Resolve()->SetVisible(true); + window->GetWindowHost()->GetNativeWindowResolver()->Resolve()->SetVisible(true); return application->Run(); } diff --git a/include/cru/ui/Base.hpp b/include/cru/ui/Base.hpp index 6be359ab..dd93f187 100644 --- a/include/cru/ui/Base.hpp +++ b/include/cru/ui/Base.hpp @@ -29,7 +29,7 @@ namespace colors = cru::platform::colors; class Window; class Control; class ClickDetector; -class UiHost; +class WindowHost; namespace render { class RenderObject; diff --git a/include/cru/ui/Control.hpp b/include/cru/ui/Control.hpp index bd86bc2f..692dcc9b 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 UiHost; + friend WindowHost; protected: Control(); @@ -27,7 +27,7 @@ class Control : public Object { //*************** region: tree *************** public: // Get the ui host if attached, otherwise, return nullptr. - UiHost* GetUiHost() const { return ui_host_; } + WindowHost* GetWindowHost() const { return ui_host_; } Control* GetParent() const { return parent_; } @@ -37,7 +37,7 @@ class Control : public Object { void TraverseDescendants(const std::function<void(Control*)>& predicate); void _SetParent(Control* parent); - void _SetDescendantUiHost(UiHost* host); + void _SetDescendantWindowHost(WindowHost* host); private: static void _TraverseDescendants( @@ -135,13 +135,13 @@ class Control : public Object { //*************** region: tree *************** protected: virtual void OnParentChanged(Control* old_parent, Control* new_parent); - virtual void OnAttachToHost(UiHost* host); - virtual void OnDetachFromHost(UiHost* host); + virtual void OnAttachToHost(WindowHost* host); + virtual void OnDetachFromHost(WindowHost* host); virtual void OnMouseHoverChange(bool newHover) { CRU_UNUSED(newHover) } private: - UiHost* ui_host_ = nullptr; + WindowHost* ui_host_ = nullptr; Control* parent_ = nullptr; private: diff --git a/include/cru/ui/Window.hpp b/include/cru/ui/Window.hpp index 450ea97b..5ea24855 100644 --- a/include/cru/ui/Window.hpp +++ b/include/cru/ui/Window.hpp @@ -3,7 +3,7 @@ namespace cru::ui { class Window final : public ContentControl { - friend UiHost; + friend WindowHost; public: static constexpr std::u16string_view control_type = u"Window"; @@ -32,9 +32,9 @@ class Window final : public ContentControl { void OnChildChanged(Control* old_child, Control* new_child) override; private: - std::unique_ptr<UiHost> managed_ui_host_; + std::unique_ptr<WindowHost> managed_ui_host_; - // UiHost is responsible to take care of lifetime of this. + // WindowHost is responsible to take care of lifetime of this. render::WindowRenderObject* render_object_; }; } // namespace cru::ui diff --git a/include/cru/ui/UiHost.hpp b/include/cru/ui/WindowHost.hpp index 2437b967..64116590 100644 --- a/include/cru/ui/UiHost.hpp +++ b/include/cru/ui/WindowHost.hpp @@ -15,35 +15,35 @@ struct AfterLayoutEventArgs {}; // 1. Native window destroyed, IsRetainAfterDestroy: false: // OnNativeDestroy(set native_window_destroyed_ to true, call ~Window due to // deleting_ is false and IsRetainAfterDestroy is false) -> ~Window -> -// ~UiHost(not destroy native window repeatedly due to native_window_destroyed_ +// ~WindowHost(not destroy native window repeatedly due to native_window_destroyed_ // is true) // 2. Native window destroyed, IsRetainAfterDestroy: true: // OnNativeDestroy(set native_window_destroyed_ to true, not call ~Window // because deleting_ is false and IsRetainAfterDestroy is true) -// then, ~Window -> ~UiHost(not destroy native window repeatedly due to +// then, ~Window -> ~WindowHost(not destroy native window repeatedly due to // native_window_destroyed_ is true) // 3. Native window not destroyed, ~Window is called: -// ~Window -> ~UiHost(set deleting_ to true, destroy native window +// ~Window -> ~WindowHost(set deleting_ to true, destroy native window // due to native_window_destroyed is false) -> OnNativeDestroy(not call ~Window // due to deleting_ is true and IsRetainAfterDestroy is whatever) // In conclusion: // 1. Set native_window_destroyed_ to true at the beginning of OnNativeDestroy. -// 2. Set deleting_ to true at the beginning of ~UiHost. +// 2. Set deleting_ to true at the beginning of ~WindowHost. // 3. Destroy native window when native_window_destroy_ is false in ~Window. // 4. Delete Window when deleting_ is false and IsRetainAfterDestroy is false in // OnNativeDestroy. -class UiHost : public Object, public SelfResolvable<UiHost> { - CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::UiHost") +class WindowHost : public Object, public SelfResolvable<WindowHost> { + CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::WindowHost") public: // This will create root window render object and attach it to window. // It will also create and manage a native window. - UiHost(Window* window); + WindowHost(Window* window); - CRU_DELETE_COPY(UiHost) - CRU_DELETE_MOVE(UiHost) + CRU_DELETE_COPY(WindowHost) + CRU_DELETE_MOVE(WindowHost) - ~UiHost() override; + ~WindowHost() override; public: // Mark the layout as invalid, and arrange a re-layout later. @@ -158,15 +158,15 @@ class UiHost : public Object, public SelfResolvable<UiHost> { std::shared_ptr<platform::native::INativeWindowResolver> native_window_resolver_; - // See remarks of UiHost. + // See remarks of WindowHost. bool retain_after_destroy_ = false; - // See remarks of UiHost. + // See remarks of WindowHost. bool deleting_ = false; // We need this because calling Resolve on resolver in handler of destroy // event is bad and will always get the dying window. But we need to label the // window as destroyed so the destructor will not destroy native window - // repeatedly. See remarks of UiHost. + // repeatedly. See remarks of WindowHost. bool native_window_destroyed_ = false; std::vector<EventRevokerGuard> event_revoker_guards_; diff --git a/include/cru/ui/render/RenderObject.hpp b/include/cru/ui/render/RenderObject.hpp index 57251e3a..f052221e 100644 --- a/include/cru/ui/render/RenderObject.hpp +++ b/include/cru/ui/render/RenderObject.hpp @@ -64,7 +64,7 @@ class RenderObject : public Object { Control* GetAttachedControl() const { return control_; } void SetAttachedControl(Control* new_control) { control_ = new_control; } - UiHost* GetUiHost() const { return ui_host_; } + WindowHost* GetWindowHost() const { return ui_host_; } RenderObject* GetParent() const { return parent_; } @@ -198,11 +198,11 @@ class RenderObject : public Object { private: void SetParent(RenderObject* new_parent); - void SetRenderHostRecursive(UiHost* host); + void SetRenderHostRecursive(WindowHost* host); private: Control* control_ = nullptr; - UiHost* ui_host_ = nullptr; + WindowHost* ui_host_ = nullptr; RenderObject* parent_ = nullptr; std::vector<RenderObject*> children_{}; diff --git a/include/cru/ui/render/WindowRenderObject.hpp b/include/cru/ui/render/WindowRenderObject.hpp index d2ca5526..23fd8748 100644 --- a/include/cru/ui/render/WindowRenderObject.hpp +++ b/include/cru/ui/render/WindowRenderObject.hpp @@ -6,7 +6,7 @@ namespace cru::ui::render { class WindowRenderObject : public RenderObject { public: - WindowRenderObject(UiHost* host); + WindowRenderObject(WindowHost* host); WindowRenderObject(const WindowRenderObject& other) = delete; WindowRenderObject(WindowRenderObject&& other) = delete; WindowRenderObject& operator=(const WindowRenderObject& other) = delete; diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index a83ab1d7..d59fd7da 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -12,9 +12,9 @@ add_library(cru_ui STATIC NoChildControl.cpp ShortcutHub.cpp UiEvent.cpp - UiHost.cpp UiManager.cpp Window.cpp + WindowHost.cpp controls/Button.cpp controls/Container.cpp controls/FlexLayout.cpp @@ -42,9 +42,9 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/NoChildControl.hpp ${CRU_UI_INCLUDE_DIR}/ShortcutHub.hpp ${CRU_UI_INCLUDE_DIR}/UiEvent.hpp - ${CRU_UI_INCLUDE_DIR}/UiHost.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 diff --git a/src/ui/ContentControl.cpp b/src/ui/ContentControl.cpp index 8d1a17d2..60d944d6 100644 --- a/src/ui/ContentControl.cpp +++ b/src/ui/ContentControl.cpp @@ -12,16 +12,16 @@ void ContentControl::SetChild(Control* child) { Expects(!dynamic_cast<Window*>(child)); // Can't add a window as child. if (child == child_) return; - const auto host = GetUiHost(); + const auto host = GetWindowHost(); const auto old_child = child_; child_ = child; if (old_child) { old_child->_SetParent(nullptr); - old_child->_SetDescendantUiHost(nullptr); + old_child->_SetDescendantWindowHost(nullptr); } if (child) { child->_SetParent(this); - child->_SetDescendantUiHost(host); + child->_SetDescendantWindowHost(host); } OnChildChanged(old_child, child); } diff --git a/src/ui/Control.cpp b/src/ui/Control.cpp index cd1367fe..cd7ed0dc 100644 --- a/src/ui/Control.cpp +++ b/src/ui/Control.cpp @@ -3,7 +3,7 @@ #include "cru/platform/native/Cursor.hpp" #include "cru/platform/native/UiApplication.hpp" #include "cru/ui/Base.hpp" -#include "cru/ui/UiHost.hpp" +#include "cru/ui/WindowHost.hpp" #include "RoutedEventDispatch.hpp" #include <memory> @@ -32,7 +32,7 @@ void Control::_SetParent(Control* parent) { if (old_parent != new_parent) OnParentChanged(old_parent, new_parent); } -void Control::_SetDescendantUiHost(UiHost* host) { +void Control::_SetDescendantWindowHost(WindowHost* host) { if (host == nullptr && ui_host_ == nullptr) return; // You can only attach or detach window. @@ -64,35 +64,35 @@ void Control::_TraverseDescendants( } bool Control::RequestFocus() { - auto host = GetUiHost(); + auto host = GetWindowHost(); if (host == nullptr) return false; return host->RequestFocusFor(this); } bool Control::HasFocus() { - auto host = GetUiHost(); + auto host = GetWindowHost(); if (host == nullptr) return false; return host->GetFocusControl() == this; } bool Control::CaptureMouse() { - auto host = GetUiHost(); + auto host = GetWindowHost(); if (host == nullptr) return false; return host->CaptureMouseFor(this); } bool Control::ReleaseMouse() { - auto host = GetUiHost(); + auto host = GetWindowHost(); if (host == nullptr) return false; return host->CaptureMouseFor(nullptr); } bool Control::IsMouseCaptured() { - auto host = GetUiHost(); + auto host = GetWindowHost(); if (host == nullptr) return false; return host->GetMouseCaptureControl() == this; @@ -113,7 +113,7 @@ std::shared_ptr<ICursor> Control::GetInheritedCursor() { void Control::SetCursor(std::shared_ptr<ICursor> cursor) { cursor_ = std::move(cursor); - const auto host = GetUiHost(); + const auto host = GetWindowHost(); if (host != nullptr) { host->UpdateCursor(); } @@ -124,7 +124,7 @@ void Control::OnParentChanged(Control* old_parent, Control* new_parent) { CRU_UNUSED(new_parent) } -void Control::OnAttachToHost(UiHost* host) { CRU_UNUSED(host) } +void Control::OnAttachToHost(WindowHost* host) { CRU_UNUSED(host) } -void Control::OnDetachFromHost(UiHost* host) { CRU_UNUSED(host) } +void Control::OnDetachFromHost(WindowHost* host) { CRU_UNUSED(host) } } // namespace cru::ui diff --git a/src/ui/LayoutControl.cpp b/src/ui/LayoutControl.cpp index 4813566b..05fcdc4a 100644 --- a/src/ui/LayoutControl.cpp +++ b/src/ui/LayoutControl.cpp @@ -19,7 +19,7 @@ void LayoutControl::AddChild(Control* control, const Index position) { children_.insert(this->children_.cbegin() + position, control); control->_SetParent(this); - control->_SetDescendantUiHost(GetUiHost()); + control->_SetDescendantWindowHost(GetWindowHost()); OnAddChild(control, position); } @@ -36,7 +36,7 @@ void LayoutControl::RemoveChild(const Index position) { children_.erase(i); child->_SetParent(nullptr); - child->_SetDescendantUiHost(nullptr); + child->_SetDescendantWindowHost(nullptr); OnRemoveChild(child, position); } diff --git a/src/ui/Window.cpp b/src/ui/Window.cpp index dca95ebb..a8cb315b 100644 --- a/src/ui/Window.cpp +++ b/src/ui/Window.cpp @@ -1,7 +1,7 @@ #include "cru/ui/Window.hpp" #include "cru/ui/render/WindowRenderObject.hpp" -#include "cru/ui/UiHost.hpp" +#include "cru/ui/WindowHost.hpp" namespace cru::ui { Window* Window::CreateOverlapped() { @@ -9,7 +9,7 @@ Window* Window::CreateOverlapped() { } Window::Window(tag_overlapped_constructor) { - managed_ui_host_ = std::make_unique<UiHost>(this); + managed_ui_host_ = std::make_unique<WindowHost>(this); } Window::~Window() { diff --git a/src/ui/UiHost.cpp b/src/ui/WindowHost.cpp index a881c16d..d3dec422 100644 --- a/src/ui/UiHost.cpp +++ b/src/ui/WindowHost.cpp @@ -1,4 +1,4 @@ -#include "cru/ui/UiHost.hpp" +#include "cru/ui/WindowHost.hpp" #include "RoutedEventDispatch.hpp" #include "cru/common/Logger.hpp" @@ -89,15 +89,15 @@ Control* FindLowestCommonAncestor(Control* left, Control* right) { namespace { template <typename T> inline void BindNativeEvent( - UiHost* host, INativeWindow* native_window, IEvent<T>* event, - void (UiHost::*handler)(INativeWindow*, typename IEvent<T>::EventArgs), + WindowHost* host, INativeWindow* native_window, IEvent<T>* event, + void (WindowHost::*handler)(INativeWindow*, typename IEvent<T>::EventArgs), std::vector<EventRevokerGuard>& guard_pool) { guard_pool.push_back(EventRevokerGuard(event->AddHandler( std::bind(handler, host, native_window, std::placeholders::_1)))); } } // namespace -UiHost::UiHost(Window* window) +WindowHost::WindowHost(Window* window) : window_control_(window), mouse_hover_control_(nullptr), focus_control_(window), @@ -118,28 +118,28 @@ UiHost::UiHost(Window* window) window->render_object_ = root_render_object_.get(); BindNativeEvent(this, native_window, native_window->DestroyEvent(), - &UiHost::OnNativeDestroy, event_revoker_guards_); + &WindowHost::OnNativeDestroy, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->PaintEvent(), - &UiHost::OnNativePaint, event_revoker_guards_); + &WindowHost::OnNativePaint, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->ResizeEvent(), - &UiHost::OnNativeResize, event_revoker_guards_); + &WindowHost::OnNativeResize, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->FocusEvent(), - &UiHost::OnNativeFocus, event_revoker_guards_); + &WindowHost::OnNativeFocus, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->MouseEnterLeaveEvent(), - &UiHost::OnNativeMouseEnterLeave, event_revoker_guards_); + &WindowHost::OnNativeMouseEnterLeave, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->MouseMoveEvent(), - &UiHost::OnNativeMouseMove, event_revoker_guards_); + &WindowHost::OnNativeMouseMove, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->MouseDownEvent(), - &UiHost::OnNativeMouseDown, event_revoker_guards_); + &WindowHost::OnNativeMouseDown, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->MouseUpEvent(), - &UiHost::OnNativeMouseUp, event_revoker_guards_); + &WindowHost::OnNativeMouseUp, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->KeyDownEvent(), - &UiHost::OnNativeKeyDown, event_revoker_guards_); + &WindowHost::OnNativeKeyDown, event_revoker_guards_); BindNativeEvent(this, native_window, native_window->KeyUpEvent(), - &UiHost::OnNativeKeyUp, event_revoker_guards_); + &WindowHost::OnNativeKeyUp, event_revoker_guards_); } -UiHost::~UiHost() { +WindowHost::~WindowHost() { deleting_ = true; window_control_->TraverseDescendants( [this](Control* control) { control->OnDetachFromHost(this); }); @@ -151,12 +151,12 @@ UiHost::~UiHost() { } } -void UiHost::InvalidatePaint() { +void WindowHost::InvalidatePaint() { if (const auto native_window = native_window_resolver_->Resolve()) native_window->RequestRepaint(); } -void UiHost::InvalidateLayout() { +void WindowHost::InvalidateLayout() { if constexpr (debug_flags::layout) log::TagDebug(log_tag, u"A relayout is requested."); if (!need_layout_) { @@ -172,17 +172,17 @@ void UiHost::InvalidateLayout() { } } -bool UiHost::IsLayoutPreferToFillWindow() const { +bool WindowHost::IsLayoutPreferToFillWindow() const { return layout_prefer_to_fill_window_; } -void UiHost::SetLayoutPreferToFillWindow(bool value) { +void WindowHost::SetLayoutPreferToFillWindow(bool value) { if (value == layout_prefer_to_fill_window_) return; layout_prefer_to_fill_window_ = value; InvalidateLayout(); } -void UiHost::Relayout() { +void WindowHost::Relayout() { const auto native_window = native_window_resolver_->Resolve(); const auto client_size = native_window ? native_window->GetClientSize() @@ -202,7 +202,7 @@ void UiHost::Relayout() { log::TagDebug(log_tag, u"A relayout is finished."); } -bool UiHost::RequestFocusFor(Control* control) { +bool WindowHost::RequestFocusFor(Control* control) { Expects(control != nullptr); // The control to request focus can't be null. // You can set it as the window. @@ -221,9 +221,9 @@ bool UiHost::RequestFocusFor(Control* control) { return true; } -Control* UiHost::GetFocusControl() { return focus_control_; } +Control* WindowHost::GetFocusControl() { return focus_control_; } -bool UiHost::CaptureMouseFor(Control* control) { +bool WindowHost::CaptureMouseFor(Control* control) { const auto native_window = native_window_resolver_->Resolve(); if (!native_window) return false; @@ -252,9 +252,11 @@ bool UiHost::CaptureMouseFor(Control* control) { return true; } -Control* UiHost::GetMouseCaptureControl() { return mouse_captured_control_; } +Control* WindowHost::GetMouseCaptureControl() { + return mouse_captured_control_; +} -void UiHost::RunAfterLayoutStable(std::function<void()> action) { +void WindowHost::RunAfterLayoutStable(std::function<void()> action) { if (need_layout_) { after_layout_stable_action_.push_back(std::move(action)); } else { @@ -262,28 +264,28 @@ void UiHost::RunAfterLayoutStable(std::function<void()> action) { } } -void UiHost::OnNativeDestroy(INativeWindow* window, std::nullptr_t) { +void WindowHost::OnNativeDestroy(INativeWindow* window, std::nullptr_t) { CRU_UNUSED(window) native_window_destroyed_ = true; if (!deleting_ && !retain_after_destroy_) delete window_control_; } -void UiHost::OnNativePaint(INativeWindow* window, std::nullptr_t) { +void WindowHost::OnNativePaint(INativeWindow* window, std::nullptr_t) { auto painter = window->BeginPaint(); painter->Clear(colors::white); root_render_object_->Draw(painter.get()); painter->EndDraw(); } -void UiHost::OnNativeResize(INativeWindow* window, const Size& size) { +void WindowHost::OnNativeResize(INativeWindow* window, const Size& size) { CRU_UNUSED(window) CRU_UNUSED(size) InvalidateLayout(); } -void UiHost::OnNativeFocus(INativeWindow* window, - platform::native::FocusChangeType focus) { +void WindowHost::OnNativeFocus(INativeWindow* window, + platform::native::FocusChangeType focus) { CRU_UNUSED(window) focus == platform::native::FocusChangeType::Gain @@ -293,7 +295,7 @@ void UiHost::OnNativeFocus(INativeWindow* window, &Control::LoseFocusEvent, nullptr, true); } -void UiHost::OnNativeMouseEnterLeave( +void WindowHost::OnNativeMouseEnterLeave( INativeWindow* window, platform::native::MouseEnterLeaveType type) { CRU_UNUSED(window) @@ -304,7 +306,7 @@ void UiHost::OnNativeMouseEnterLeave( } } -void UiHost::OnNativeMouseMove(INativeWindow* window, const Point& point) { +void WindowHost::OnNativeMouseMove(INativeWindow* window, const Point& point) { CRU_UNUSED(window) // Find the first control that hit test succeed. @@ -337,7 +339,7 @@ void UiHost::OnNativeMouseMove(INativeWindow* window, const Point& point) { UpdateCursor(); } -void UiHost::OnNativeMouseDown( +void WindowHost::OnNativeMouseDown( INativeWindow* window, const platform::native::NativeMouseButtonEventArgs& args) { CRU_UNUSED(window) @@ -348,7 +350,7 @@ void UiHost::OnNativeMouseDown( nullptr, args.point, args.button, args.modifier); } -void UiHost::OnNativeMouseUp( +void WindowHost::OnNativeMouseUp( INativeWindow* window, const platform::native::NativeMouseButtonEventArgs& args) { CRU_UNUSED(window) @@ -359,27 +361,27 @@ void UiHost::OnNativeMouseUp( args.point, args.button, args.modifier); } -void UiHost::OnNativeKeyDown(INativeWindow* window, - const platform::native::NativeKeyEventArgs& args) { +void WindowHost::OnNativeKeyDown( + INativeWindow* window, const platform::native::NativeKeyEventArgs& args) { CRU_UNUSED(window) DispatchEvent(event_names::KeyDown, focus_control_, &Control::KeyDownEvent, nullptr, args.key, args.modifier); } -void UiHost::OnNativeKeyUp(INativeWindow* window, - const platform::native::NativeKeyEventArgs& args) { +void WindowHost::OnNativeKeyUp( + INativeWindow* window, const platform::native::NativeKeyEventArgs& args) { CRU_UNUSED(window) DispatchEvent(event_names::KeyUp, focus_control_, &Control::KeyUpEvent, nullptr, args.key, args.modifier); } -void UiHost::DispatchMouseHoverControlChangeEvent(Control* old_control, - Control* new_control, - const Point& point, - bool no_leave, - bool no_enter) { +void WindowHost::DispatchMouseHoverControlChangeEvent(Control* old_control, + Control* new_control, + const Point& point, + bool no_leave, + bool no_enter) { if (new_control != old_control) // if the mouse-hover-on control changed { const auto lowest_common_ancestor = @@ -396,7 +398,7 @@ void UiHost::DispatchMouseHoverControlChangeEvent(Control* old_control, } } -void UiHost::UpdateCursor() { +void WindowHost::UpdateCursor() { if (const auto native_window = native_window_resolver_->Resolve()) { const auto capture = GetMouseCaptureControl(); native_window->SetCursor( @@ -404,7 +406,7 @@ void UiHost::UpdateCursor() { } } -Control* UiHost::HitTest(const Point& point) { +Control* WindowHost::HitTest(const Point& point) { const auto render_object = root_render_object_->HitTest(point); if (render_object) { const auto control = render_object->GetAttachedControl(); diff --git a/src/ui/controls/TextControlService.hpp b/src/ui/controls/TextControlService.hpp index 8419f35c..8c1bd32f 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/UiHost.hpp" +#include "cru/ui/WindowHost.hpp" #include "cru/ui/render/CanvasRenderObject.hpp" #include "cru/ui/render/ScrollRenderObject.hpp" #include "cru/ui/render/TextRenderObject.hpp" @@ -208,7 +208,7 @@ class TextControlService : public Object { } void ScrollToCaret() { - this->control_->GetUiHost()->RunAfterLayoutStable([this]() { + this->control_->GetWindowHost()->RunAfterLayoutStable([this]() { const auto caret_rect = this->GetTextRenderObject()->GetCaretRect(); this->GetScrollRenderObject()->ScrollToContain(caret_rect, Thickness{5.f}); @@ -408,7 +408,7 @@ class TextControlService : public Object { void GainFocusHandler(event::FocusChangeEventArgs& args) { CRU_UNUSED(args); if (editable_) { - UiHost* ui_host = this->control_->GetUiHost(); + WindowHost* ui_host = this->control_->GetWindowHost(); auto window = ui_host->GetNativeWindowResolver()->Resolve(); if (window == nullptr) return; input_method_context_ = diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index c85f8080..5266daaf 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/graph/util/Painter.hpp" #include "cru/ui/DebugFlags.hpp" -#include "cru/ui/UiHost.hpp" +#include "cru/ui/WindowHost.hpp" #include <algorithm> #include <string> @@ -24,7 +24,7 @@ void RenderObject::AddChild(RenderObject* render_object, const Index position) { children_.insert(children_.cbegin() + position, render_object); render_object->SetParent(this); - render_object->SetRenderHostRecursive(GetUiHost()); + render_object->SetRenderHostRecursive(GetWindowHost()); OnAddChild(render_object, position); } @@ -304,7 +304,7 @@ void RenderObject::NotifyAfterLayoutRecursive(RenderObject* render_object) { } } -void RenderObject::SetRenderHostRecursive(UiHost* host) { +void RenderObject::SetRenderHostRecursive(WindowHost* host) { ui_host_ = host; for (const auto child : GetChildren()) { child->SetRenderHostRecursive(host); diff --git a/src/ui/render/WindowRenderObject.cpp b/src/ui/render/WindowRenderObject.cpp index a136c1e9..23cca12e 100644 --- a/src/ui/render/WindowRenderObject.cpp +++ b/src/ui/render/WindowRenderObject.cpp @@ -2,10 +2,10 @@ #include "../Helper.hpp" #include "cru/platform/graph/util/Painter.hpp" -#include "cru/ui/UiHost.hpp" +#include "cru/ui/WindowHost.hpp" namespace cru::ui::render { -WindowRenderObject::WindowRenderObject(UiHost* host) { +WindowRenderObject::WindowRenderObject(WindowHost* host) { SetChildMode(ChildMode::Single); ui_host_ = host; after_layout_event_guard_.Reset(host->AfterLayoutEvent()->AddHandler( |