فهرست منبع

LibGUI: Add Window::center_within(Window)

This allows you to easily center one window within another window.
Andreas Kling 4 سال پیش
والد
کامیت
04e3bcfa75
2فایلهای تغییر یافته به همراه10 افزوده شده و 0 حذف شده
  1. 9 0
      Libraries/LibGUI/Window.cpp
  2. 1 0
      Libraries/LibGUI/Window.h

+ 9 - 0
Libraries/LibGUI/Window.cpp

@@ -239,6 +239,15 @@ void Window::center_on_screen()
     set_rect(window_rect);
     set_rect(window_rect);
 }
 }
 
 
+void Window::center_within(const Window& other)
+{
+    if (this == &other)
+        return;
+    auto window_rect = rect();
+    window_rect.center_within(other.rect());
+    set_rect(window_rect);
+}
+
 void Window::set_window_type(WindowType window_type)
 void Window::set_window_type(WindowType window_type)
 {
 {
     m_window_type = window_type;
     m_window_type = window_type;

+ 1 - 0
Libraries/LibGUI/Window.h

@@ -108,6 +108,7 @@ public:
     void resize(const Gfx::IntSize& size) { set_rect({ position(), size }); }
     void resize(const Gfx::IntSize& size) { set_rect({ position(), size }); }
 
 
     void center_on_screen();
     void center_on_screen();
+    void center_within(const Window&);
 
 
     virtual void event(Core::Event&) override;
     virtual void event(Core::Event&) override;