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.
This commit is contained in:
Andreas Kling 2019-03-19 03:00:42 +01:00
parent 46577a6948
commit e15cc4509f
Notes: sideshowbarker 2024-07-19 15:00:21 +09:00
3 changed files with 15 additions and 19 deletions

View File

@ -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());

View File

@ -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);

View File

@ -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); }