improve boxlayout growing

This commit is contained in:
hippoz 2022-08-29 15:22:17 +03:00
parent 43eec85adc
commit e8f095bfc4
Signed by: hippoz
GPG key ID: 7C52899193467641
2 changed files with 14 additions and 6 deletions

View file

@ -24,15 +24,19 @@ void BoxLayout::run() {
if (i >= working_slots.size()) { if (i >= working_slots.size()) {
// widgets which are outside the pre-defined slot range // widgets which are outside the pre-defined slot range
if (child->rect().max_dimension_at(m_direction) != -1 || child->rect().min_dimension_at(m_direction) != -1) { bool widget_has_fixed_size = child->rect().max_dimension_at(m_direction) != -1 || child->rect().min_dimension_at(m_direction) != -1;
// if the widget has a minimum or maximum size, we'll make a slot for its preferred size bool widget_grows = child->grows();
bool is_widget_unslotted = !widget_has_fixed_size && widget_grows;
if (is_widget_unslotted) {
// we can consider non-growing widgets with no size perference "unslotted". these widgets will be evenly spaced amongst themselves.
unslotted_widgets++;
working_slots.push_back(Slot{ 0, 0, SlotType::Auto });
} else {
// if the widget has a size preference, we will use its dimensions instead
child->rect().update(); child->rect().update();
working_slots.push_back(Slot { 0, child->rect().dimension_at(m_direction), SlotType::Pixel }); working_slots.push_back(Slot { 0, child->rect().dimension_at(m_direction), SlotType::Pixel });
free_space -= child->rect().dimension_at(m_direction) + m_spacing; free_space -= child->rect().dimension_at(m_direction) + m_spacing;
} else {
// we can consider widgets with no size perference "unslotted". these widgets will be evenly spaced amongst themselves.
unslotted_widgets++;
working_slots.push_back(Slot{ 0, 0, SlotType::Auto });
} }
} else { } else {
// widgets which have a pre-defined slot // widgets which have a pre-defined slot

View file

@ -92,6 +92,9 @@ public:
bool absolute() { return m_absolute; } bool absolute() { return m_absolute; }
void set_absolute(bool absolute) { m_absolute = absolute; } void set_absolute(bool absolute) { m_absolute = absolute; }
bool grows() { return m_grows; }
void set_grows(bool grows) { m_grows = grows; }
void set_layout(std::shared_ptr<Layout> layout); void set_layout(std::shared_ptr<Layout> layout);
std::shared_ptr<Layout> layout() { return m_layout; } std::shared_ptr<Layout> layout() { return m_layout; }
@ -146,6 +149,7 @@ private:
bool m_consumes_hits { false }; bool m_consumes_hits { false };
bool m_accepts_events { true }; bool m_accepts_events { true };
bool m_absolute { false }; bool m_absolute { false };
bool m_grows { true };
ControlWidgetType m_control_type { ControlWidgetType::Widget }; ControlWidgetType m_control_type { ControlWidgetType::Widget };
}; };