aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/Window.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-12-06 20:06:10 +0800
committerYuqian Yang <crupest@crupest.life>2025-12-07 19:52:05 +0800
commit4a30bf58a48ed6f31f4c53473e8de70a8cd819da (patch)
tree32aab619013cbe2d0557a212832ba24833d2cc36 /src/ui/controls/Window.cpp
parent9a87e5cf786f3e8fddc933136d210edd4ef72c89 (diff)
downloadcru-4a30bf58a48ed6f31f4c53473e8de70a8cd819da.tar.gz
cru-4a30bf58a48ed6f31f4c53473e8de70a8cd819da.tar.bz2
cru-4a30bf58a48ed6f31f4c53473e8de70a8cd819da.zip
Fix SDL popup window.
Diffstat (limited to 'src/ui/controls/Window.cpp')
-rw-r--r--src/ui/controls/Window.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/ui/controls/Window.cpp b/src/ui/controls/Window.cpp
index 8f06013e..f4714efa 100644
--- a/src/ui/controls/Window.cpp
+++ b/src/ui/controls/Window.cpp
@@ -2,6 +2,7 @@
#include "cru/platform/gui/UiApplication.h"
#include "cru/platform/gui/Window.h"
#include "cru/ui/Base.h"
+#include "cru/ui/controls/Control.h"
#include "cru/ui/controls/ControlHost.h"
#include <cassert>
@@ -15,16 +16,33 @@ Window::Window()
GetContainerRenderObject()->SetDefaultVerticalAlignment(Alignment::Stretch);
}
-Window* Window::CreatePopup() {
+Window* Window::CreatePopup(Control* attached_control) {
auto window = new Window();
window->GetNativeWindow()->SetStyleFlag(
platform::gui::WindowStyleFlags::NoCaptionAndBorder);
+ window->SetAttachedControl(attached_control);
window->SetGainFocusOnCreateAndDestroyWhenLoseFocus(true);
return window;
}
+Control* Window::GetAttachedControl() { return attached_control_; }
+
void Window::SetAttachedControl(Control* control) {
attached_control_ = control;
+ if (control) {
+ if (auto control_host = control->GetControlHost()) {
+ control_host_->GetNativeWindow()->SetParent(
+ control_host->GetNativeWindow());
+ }
+ parent_window_guard_.Reset(control->ControlHostChangeEvent()->AddHandler(
+ [this](const ControlHostChangeEventArgs& args) {
+ control_host_->GetNativeWindow()->SetParent(
+ args.new_host ? args.new_host->GetNativeWindow() : nullptr);
+ }));
+ } else {
+ control_host_->GetNativeWindow()->SetParent(nullptr);
+ parent_window_guard_.Reset();
+ }
}
platform::gui::INativeWindow* Window::GetNativeWindow() {