aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/RootControl.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-11-20 19:47:53 +0800
committercrupest <crupest@outlook.com>2021-11-20 19:47:53 +0800
commitb0b86b6b9d6798d04a320060e90bd8497a7f50f9 (patch)
treea6e3f3315a538791e1cbd4e799bc6268262feedb /src/ui/controls/RootControl.cpp
parent2ad748a0fcb66398299886970cc9c40cc50b3cd0 (diff)
downloadcru-b0b86b6b9d6798d04a320060e90bd8497a7f50f9.tar.gz
cru-b0b86b6b9d6798d04a320060e90bd8497a7f50f9.tar.bz2
cru-b0b86b6b9d6798d04a320060e90bd8497a7f50f9.zip
...
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