aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-01-03 00:43:46 +0800
committercrupest <crupest@outlook.com>2020-01-03 00:43:46 +0800
commit8fc4e33b97372d93b1bcc4b598e5c8e2f15652d8 (patch)
tree8508a9e9f54f9ff871f53f5628894cefec440d05 /src/ui
parentd5ff69096a3f56052b30d8ef827845473d4aa5ea (diff)
downloadcru-8fc4e33b97372d93b1bcc4b598e5c8e2f15652d8.tar.gz
cru-8fc4e33b97372d93b1bcc4b598e5c8e2f15652d8.tar.bz2
cru-8fc4e33b97372d93b1bcc4b598e5c8e2f15652d8.zip
...
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/render/window_render_object.cpp9
-rw-r--r--src/ui/window.cpp19
2 files changed, 19 insertions, 9 deletions
diff --git a/src/ui/render/window_render_object.cpp b/src/ui/render/window_render_object.cpp
index 1001be87..43269d09 100644
--- a/src/ui/render/window_render_object.cpp
+++ b/src/ui/render/window_render_object.cpp
@@ -21,7 +21,9 @@ class WindowRenderHost : public IRenderHost,
void InvalidateLayout() override;
void InvalidatePaint() override {
- render_object_->GetWindow()->GetNativeWindow()->RequestRepaint();
+ if (const auto native_window =
+ render_object_->GetWindow()->ResolveNativeWindow())
+ native_window->RequestRepaint();
}
IEvent<AfterLayoutEventArgs>* AfterLayoutEvent() override {
@@ -61,7 +63,10 @@ WindowRenderObject::WindowRenderObject(Window* window)
}
void WindowRenderObject::Relayout() {
- const auto client_size = window_->GetNativeWindow()->GetClientSize();
+ const auto native_window = window_->ResolveNativeWindow();
+ const auto client_size = native_window
+ ? native_window->GetClientSize()
+ : Size{100, 100}; // a reasonable assumed size
Measure(client_size);
Layout(Rect{Point{}, client_size});
}
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index 35463778..7579786a 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -145,7 +145,7 @@ render::RenderObject* Window::GetRenderObject() const {
return render_object_.get();
}
-platform::native::INativeWindow* Window::GetNativeWindow() {
+platform::native::INativeWindow* Window::ResolveNativeWindow() {
return native_window_resolver_->Resolve();
}
@@ -169,6 +169,9 @@ bool Window::RequestFocusFor(Control* control) {
Control* Window::GetFocusControl() { return focus_control_; }
bool Window::CaptureMouseFor(Control* control) {
+ const auto native_window = ResolveNativeWindow();
+ if (!native_window) return false;
+
if (control == mouse_captured_control_) return true;
if (control == nullptr) {
@@ -178,7 +181,7 @@ bool Window::CaptureMouseFor(Control* control) {
if (old_capture_control != mouse_hover_control_) {
DispatchMouseHoverControlChangeEvent(
old_capture_control, mouse_hover_control_,
- GetNativeWindow()->GetMousePosition(), true, false);
+ native_window->GetMousePosition(), true, false);
}
UpdateCursor();
return true;
@@ -189,7 +192,7 @@ bool Window::CaptureMouseFor(Control* control) {
mouse_captured_control_ = control;
DispatchMouseHoverControlChangeEvent(
mouse_hover_control_, mouse_captured_control_,
- GetNativeWindow()->GetMousePosition(), false, true);
+ native_window->GetMousePosition(), false, true);
UpdateCursor();
return true;
}
@@ -207,7 +210,7 @@ Control* Window::HitTest(const Point& point) {
void Window::OnNativeDestroy(INativeWindow* window, std::nullptr_t) {
CRU_UNUSED(window)
- delete this;
+ delete this; // TODO: Finally change this.
}
void Window::OnNativePaint(INativeWindow* window, std::nullptr_t) {
@@ -335,8 +338,10 @@ void Window::DispatchMouseHoverControlChangeEvent(Control* old_control,
}
void Window::UpdateCursor() {
- const auto capture = GetMouseCaptureControl();
- GetNativeWindow()->SetCursor(
- (capture ? capture : GetMouseHoverControl())->GetInheritedCursor());
+ if (const auto native_window = ResolveNativeWindow()) {
+ const auto capture = GetMouseCaptureControl();
+ native_window->SetCursor(
+ (capture ? capture : GetMouseHoverControl())->GetInheritedCursor());
+ }
}
} // namespace cru::ui