Parcourir la source

LibGUI: More GInputBox refinements.

Fix some GBoxLayout bugs to make the buttons in GInputBox line up better.
There are still some imperfections due to rounding errors.
Andreas Kling il y a 6 ans
Parent
commit
e15cc4509f
3 fichiers modifiés avec 15 ajouts et 19 suppressions
  1. 5 18
      LibGUI/GBoxLayout.cpp
  2. 3 1
      LibGUI/GInputBox.cpp
  3. 7 0
      SharedGraphics/Size.h

+ 5 - 18
LibGUI/GBoxLayout.cpp

@@ -13,23 +13,6 @@ GBoxLayout::~GBoxLayout()
 {
 }
 
-#if 0
-Size GLayout::compute_preferred_size() const
-{
-
-}
-
-
-static Size compute_preferred_size(GLayout::Entry& entry)
-{
-    if (entry.layout)
-        return entry.layout->compute_preferred_size();
-    else {
-        return entry.widget->preferred_size();
-    }
-}
-#endif
-
 void GBoxLayout::run(GWidget& widget)
 {
     bool should_log = false;
@@ -59,14 +42,18 @@ void GBoxLayout::run(GWidget& widget)
                 printf("GBoxLayout:   Subtracting for fixed %s{%p}, size: %s\n", entry.widget->class_name(), entry.widget.ptr(), entry.widget->preferred_size().to_string().characters());
                 printf("GBoxLayout:     Available size before: %s\n", available_size.to_string().characters());
             }
-
             available_size -= entry.widget->preferred_size();
             if (should_log)
                 printf("GBoxLayout:     Available size  after: %s\n", available_size.to_string().characters());
             ++number_of_entries_with_fixed_size;
         }
+        available_size -= { spacing(), spacing() };
     }
 
+    available_size += { spacing(), spacing() };
+
+    available_size -= { margins().left() + margins().right(), margins().top() + margins().bottom() };
+
     if (should_log)
         printf("GBoxLayout:  Number of visible: %d/%d\n", number_of_visible_entries, m_entries.size());
 

+ 3 - 1
LibGUI/GInputBox.cpp

@@ -24,7 +24,7 @@ void GInputBox::build()
 
     int text_width = widget->font().width(m_prompt);
 
-    set_rect(x(), y(), text_width + 80, 120);
+    set_rect(x(), y(), text_width + 80, 80);
 
     widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
     widget->set_fill_with_background_color(true);
@@ -41,6 +41,8 @@ void GInputBox::build()
     m_text_editor->set_preferred_size({ 0, 16 });
 
     auto* button_container_outer = new GWidget(widget);
+    button_container_outer->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
+    button_container_outer->set_preferred_size({ 0, 16 });
     button_container_outer->set_layout(make<GBoxLayout>(Orientation::Vertical));
 
     auto* button_container_inner = new GWidget(button_container_outer);

+ 7 - 0
SharedGraphics/Size.h

@@ -39,6 +39,13 @@ public:
         return *this;
     }
 
+    Size& operator+=(const Size& other)
+    {
+        m_width += other.m_width;
+        m_height += other.m_height;
+        return *this;
+    }
+
     operator WSAPI_Size() const;
 
     String to_string() const { return String::format("[%d,%d]", m_width, m_height); }