LibGUI: Improve GBoxLayout so it can better support GToolBar.

Added spacing and margin concepts to GLayout. Support layout a sequence
of nothing but fixed-size objects in the desired orientation. :^)
This commit is contained in:
Andreas Kling 2019-02-20 09:04:28 +01:00
parent b704d3d295
commit dc753b58a5
Notes: sideshowbarker 2024-07-19 15:40:04 +09:00
5 changed files with 84 additions and 20 deletions

View file

@ -66,25 +66,22 @@ void GBoxLayout::run(GWidget& widget)
dbgprintf("GBoxLayout: automatic_size=%s\n", automatic_size.to_string().characters());
#endif
int current_x = 0;
int current_y = 0;
for (auto& entry : m_entries) {
// FIXME: We should also respect the bottom and right margins.
int current_x = margins().left();
int current_y = margins().top();
for (auto& entry : m_entries) {
Rect rect(current_x, current_y, 0, 0);
if (entry.layout) {
// FIXME: Implement recursive layout.
ASSERT_NOT_REACHED();
}
ASSERT(entry.widget);
if (entry.widget->size_policy(orientation()) == SizePolicy::Fixed) {
rect.set_size(automatic_size);
if (orientation() == Orientation::Vertical) {
rect.set_height(entry.widget->preferred_size().height());
} else {
rect.set_width(entry.widget->preferred_size().height());
}
} else {
rect.set_size(automatic_size);
}
rect.set_size(automatic_size);
if (entry.widget->size_policy(Orientation::Vertical) == SizePolicy::Fixed)
rect.set_height(entry.widget->preferred_size().height());
if (entry.widget->size_policy(Orientation::Horizontal) == SizePolicy::Fixed)
rect.set_width(entry.widget->preferred_size().height());
#ifdef GBOXLAYOUT_DEBUG
dbgprintf("GBoxLayout: apply, %s{%p} <- %s\n", entry.widget->class_name(), entry.widget.ptr(), rect.to_string().characters());
@ -92,8 +89,8 @@ void GBoxLayout::run(GWidget& widget)
entry.widget->set_relative_rect(rect);
if (orientation() == Orientation::Horizontal)
current_x += rect.width();
current_x += rect.width() + spacing();
else
current_y += rect.height();
current_y += rect.height() + spacing();
}
}