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.cpp60
1 files changed, 19 insertions, 41 deletions
diff --git a/src/ui/controls/RootControl.cpp b/src/ui/controls/RootControl.cpp
index 007a0ac1..4ae41c80 100644
--- a/src/ui/controls/RootControl.cpp
+++ b/src/ui/controls/RootControl.cpp
@@ -11,57 +11,35 @@
#include <memory>
namespace cru::ui::controls {
-RootControl::RootControl(Control* attached_control)
+RootControl::RootControl(Control* attached_control,
+ host::CreateWindowParams params)
: attached_control_(attached_control) {
render_object_ = std::make_unique<render::StackLayoutRenderObject>();
render_object_->SetAttachedControl(this);
SetContainerRenderObject(render_object_.get());
- window_host_ = std::make_unique<host::WindowHost>(this);
-}
-
-RootControl::~RootControl() {}
-
-render::RenderObject* RootControl::GetRenderObject() const {
- return render_object_.get();
-}
-
-void RootControl::EnsureWindowCreated() { this->GetNativeWindow(true); }
+ window_host_ = std::make_unique<host::WindowHost>(this, params);
-Rect RootControl::GetRect() { return window_host_->GetWindowRect(); }
-
-void RootControl::SetRect(const Rect& rect) {
- window_host_->SetWindowRect(rect);
-}
-
-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();
+ auto native_window = window_host_->GetNativeWindow();
+ native_window->CreateEvent()->AddHandler(
+ [](platform::gui::INativeWindow* window) {
+ window->CreateEvent()->AddHandler(
+ [window](std::nullptr_t) { window->RequestFocus(); });
+ });
+
+ native_window->FocusEvent()->AddHandler(
+ [native_window](platform::gui::FocusChangeType type) {
+ if (type == platform::gui::FocusChangeType::Lost) {
+ native_window->Close();
+ }
+ });
}
}
-platform::gui::INativeWindow* RootControl::GetNativeWindow(bool create) {
- const auto host = GetWindowHost();
- platform::gui::INativeWindow* native_window = host->GetNativeWindow();
- if (!create) return native_window;
- if (!native_window) {
- native_window = this->CreateNativeWindow(
- host, attached_control_
- ? attached_control_->GetWindowHost()->GetNativeWindow()
- : nullptr);
+RootControl::~RootControl() {}
- 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;
+render::RenderObject* RootControl::GetRenderObject() const {
+ return render_object_.get();
}
void RootControl::SetGainFocusOnCreateAndDestroyWhenLoseFocus(bool value) {