aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/CMakeLists.txt4
-rw-r--r--src/ui/ContentControl.cpp6
-rw-r--r--src/ui/Control.cpp20
-rw-r--r--src/ui/LayoutControl.cpp4
-rw-r--r--src/ui/Window.cpp4
-rw-r--r--src/ui/WindowHost.cpp (renamed from src/ui/UiHost.cpp)92
-rw-r--r--src/ui/controls/TextControlService.hpp6
-rw-r--r--src/ui/render/RenderObject.cpp6
-rw-r--r--src/ui/render/WindowRenderObject.cpp4
9 files changed, 74 insertions, 72 deletions
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(