aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/controls')
-rw-r--r--src/ui/controls/Popup.cpp16
-rw-r--r--src/ui/controls/RootControl.cpp60
-rw-r--r--src/ui/controls/Window.cpp9
3 files changed, 26 insertions, 59 deletions
diff --git a/src/ui/controls/Popup.cpp b/src/ui/controls/Popup.cpp
index 515c7b31..ae6ac1d2 100644
--- a/src/ui/controls/Popup.cpp
+++ b/src/ui/controls/Popup.cpp
@@ -8,19 +8,13 @@
#include <memory>
namespace cru::ui::controls {
-Popup::Popup(Control* attached_control) : RootControl(attached_control) {
+Popup::Popup(Control* attached_control)
+ : RootControl(
+ attached_control,
+ host::CreateWindowParams{
+ nullptr, platform::gui::CreateWindowFlags::NoCaptionAndBorder}) {
SetGainFocusOnCreateAndDestroyWhenLoseFocus(true);
}
Popup::~Popup() = default;
-
-gsl::not_null<platform::gui::INativeWindow*> Popup::CreateNativeWindow(
- gsl::not_null<host::WindowHost*> host,
- platform::gui::INativeWindow* parent) {
- auto window = host->CreateNativeWindow(
- {parent, platform::gui::CreateWindowFlags::NoCaptionAndBorder});
-
- return window;
-}
-
} // namespace cru::ui::controls
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) {
diff --git a/src/ui/controls/Window.cpp b/src/ui/controls/Window.cpp
index ba66f42e..00fab8e9 100644
--- a/src/ui/controls/Window.cpp
+++ b/src/ui/controls/Window.cpp
@@ -12,13 +12,8 @@ Window* Window::Create(Control* attached_control) {
return new Window(attached_control);
}
-Window::Window(Control* attached_control) : RootControl(attached_control) {}
+Window::Window(Control* attached_control)
+ : RootControl(attached_control, host::CreateWindowParams{}) {}
Window::~Window() {}
-
-gsl::not_null<platform::gui::INativeWindow*> Window::CreateNativeWindow(
- gsl::not_null<host::WindowHost*> host,
- platform::gui::INativeWindow* parent) {
- return host->CreateNativeWindow({parent});
-}
} // namespace cru::ui::controls