aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/RootControl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/controls/RootControl.cpp')
-rw-r--r--src/ui/controls/RootControl.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/ui/controls/RootControl.cpp b/src/ui/controls/RootControl.cpp
index 015703c3..007a0ac1 100644
--- a/src/ui/controls/RootControl.cpp
+++ b/src/ui/controls/RootControl.cpp
@@ -2,6 +2,7 @@
#include "cru/common/Base.hpp"
#include "cru/platform/gui/Base.hpp"
+#include "cru/platform/gui/Window.hpp"
#include "cru/ui/host/WindowHost.hpp"
#include "cru/ui/render/Base.hpp"
#include "cru/ui/render/StackLayoutRenderObject.hpp"
@@ -36,6 +37,9 @@ void RootControl::Show(bool create) {
platform::gui::INativeWindow* native_window = GetNativeWindow(create);
if (!native_window) return;
native_window->SetVisible(true);
+ if (gain_focus_on_create_and_destroy_when_lose_focus_) {
+ native_window->RequestFocus();
+ }
}
platform::gui::INativeWindow* RootControl::GetNativeWindow(bool create) {
@@ -47,7 +51,20 @@ platform::gui::INativeWindow* RootControl::GetNativeWindow(bool create) {
host, attached_control_
? attached_control_->GetWindowHost()->GetNativeWindow()
: nullptr);
+
+ if (gain_focus_on_create_and_destroy_when_lose_focus_) {
+ native_window->FocusEvent()->AddHandler(
+ [native_window](platform::gui::FocusChangeType type) {
+ if (type == platform::gui::FocusChangeType::Lost) {
+ native_window->Close();
+ }
+ });
+ }
}
return native_window;
}
+
+void RootControl::SetGainFocusOnCreateAndDestroyWhenLoseFocus(bool value) {
+ gain_focus_on_create_and_destroy_when_lose_focus_ = value;
+}
} // namespace cru::ui::controls