aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-11-16 17:14:20 +0800
committerYuqian Yang <crupest@crupest.life>2025-11-16 17:14:20 +0800
commit1ce8866e5b88da6cc4b7cd4d3440f7d70c7be5db (patch)
treec43f76eb308ed59570e61ed647371cce5e68d32e /src
parent1ef4651c4002eb3a155bcd36fed1e5b6b63b1c80 (diff)
downloadcru-1ce8866e5b88da6cc4b7cd4d3440f7d70c7be5db.tar.gz
cru-1ce8866e5b88da6cc4b7cd4d3440f7d70c7be5db.tar.bz2
cru-1ce8866e5b88da6cc4b7cd4d3440f7d70c7be5db.zip
Remove SelfResolvable.
Diffstat (limited to 'src')
-rw-r--r--src/platform/gui/win/Window.cpp5
-rw-r--r--src/ui/components/Menu.cpp5
-rw-r--r--src/ui/controls/Control.cpp4
-rw-r--r--src/ui/helper/ClickDetector.cpp4
-rw-r--r--src/ui/host/RoutedEventDispatch.h20
5 files changed, 11 insertions, 27 deletions
diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp
index 95c840c3..5046868e 100644
--- a/src/platform/gui/win/Window.cpp
+++ b/src/platform/gui/win/Window.cpp
@@ -210,9 +210,8 @@ Point WinNativeWindow::GetMousePosition() {
POINT p;
if (!::GetCursorPos(&p))
throw Win32Error(::GetLastError(), "Failed to get cursor position.");
- if (!::ScreenToClient(hwnd_, &p))
- throw Win32Error(::GetLastError(), "Failed to call ScreenToClient.");
- return PixelToDip(p);
+ auto point = PixelToDip(p);
+ return point - client_rect_.GetLeftTop();
}
bool WinNativeWindow::CaptureMouse() {
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp
index fa594399..65c1e810 100644
--- a/src/ui/components/Menu.cpp
+++ b/src/ui/components/Menu.cpp
@@ -79,10 +79,7 @@ void Menu::AddTextItemAt(std::string text, Index index,
PopupMenu::PopupMenu(controls::Control* attached_control)
: attached_control_(attached_control), popup_(attached_control) {
- menu_.SetOnItemClick([resolver = CreateResolver()](Index) {
- auto t = static_cast<PopupMenu*>(resolver.Resolve());
- if (t) t->popup_.GetNativeWindow()->Close();
- });
+ menu_.SetOnItemClick([this](Index) { popup_.GetNativeWindow()->Close(); });
popup_.AddChildAt(menu_.GetRootControl(), 0);
}
diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp
index 14397fa7..cf0cc11f 100644
--- a/src/ui/controls/Control.cpp
+++ b/src/ui/controls/Control.cpp
@@ -27,10 +27,6 @@ Control::Control() {
}
Control::~Control() {
- if (host::WindowHost::IsInEventHandling()) {
- std::terminate();
- }
-
in_destruction_ = true;
RemoveFromParent();
}
diff --git a/src/ui/helper/ClickDetector.cpp b/src/ui/helper/ClickDetector.cpp
index cf219db0..796c3ad4 100644
--- a/src/ui/helper/ClickDetector.cpp
+++ b/src/ui/helper/ClickDetector.cpp
@@ -77,12 +77,10 @@ ClickDetector::ClickDetector(controls::Control* control) {
button == button_) {
if (this->state_ == ClickState::Press) {
this->SetState(ClickState::Hover);
- auto resolver = this->control_->CreateResolver();
this->event_.Raise(ClickEventArgs{this->control_,
this->down_point_,
args.GetPoint(), button});
- auto c = resolver.Resolve();
- if (c) c->ReleaseMouse();
+ this->control_->ReleaseMouse();
} else if (this->state_ == ClickState::PressInactive) {
this->SetState(ClickState::None);
this->control_->ReleaseMouse();
diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h
index 0729d176..6e8b4af1 100644
--- a/src/ui/host/RoutedEventDispatch.h
+++ b/src/ui/host/RoutedEventDispatch.h
@@ -1,5 +1,4 @@
#pragma once
-#include "cru/base/SelfResolvable.h"
#include "cru/base/log/Logger.h"
#include "cru/ui/DebugFlags.h"
#include "cru/ui/controls/Control.h"
@@ -43,11 +42,11 @@ void DispatchEvent(
WindowHost::EnterEventHandling();
- std::vector<ObjectResolver<controls::Control>> receive_list;
+ std::vector<controls::Control*> receive_list;
auto parent = original_sender;
while (parent != last_receiver) {
- receive_list.push_back(parent->CreateResolver());
+ receive_list.push_back(parent);
auto p = parent->GetParent();
assert(!(p == nullptr && last_receiver != nullptr));
parent = p;
@@ -60,10 +59,10 @@ void DispatchEvent(
auto i = receive_list.crbegin();
const auto end = --receive_list.crend();
for (; i != end; ++i) {
- log += i->Resolve()->GetControlType();
+ log += (*i)->GetControlType();
log += " -> ";
}
- log += i->Resolve()->GetControlType();
+ log += (*i)->GetControlType();
CRU_LOG_TAG_DEBUG("{}", log);
}
@@ -74,8 +73,7 @@ void DispatchEvent(
// tunnel
for (auto i = receive_list.crbegin(); i != receive_list.crend(); ++i) {
count++;
- auto control = i->Resolve();
- if (!control) continue;
+ auto control = *i;
EventArgs event_args(control, original_sender, std::forward<Args>(args)...);
static_cast<Event<EventArgs&>*>((control->*event_ptr)()->Tunnel())
->Raise(event_args);
@@ -92,10 +90,8 @@ void DispatchEvent(
// bubble
if (!handled) {
- for (const auto& resolver : receive_list) {
+ for (auto control : receive_list) {
count--;
- auto control = resolver.Resolve();
- if (!control) continue;
EventArgs event_args(control, original_sender,
std::forward<Args>(args)...);
static_cast<Event<EventArgs&>*>((control->*event_ptr)()->Bubble())
@@ -112,9 +108,7 @@ void DispatchEvent(
}
// direct
- for (auto resolver : receive_list) {
- auto control = resolver.Resolve();
- if (!control) continue;
+ for (auto control : receive_list) {
EventArgs event_args(control, original_sender, std::forward<Args>(args)...);
static_cast<Event<EventArgs&>*>((control->*event_ptr)()->Direct())
->Raise(event_args);