diff --git a/src/BoxLayout.cpp b/src/BoxLayout.cpp index 0c0412c..45850bf 100644 --- a/src/BoxLayout.cpp +++ b/src/BoxLayout.cpp @@ -24,15 +24,19 @@ void BoxLayout::run() { if (i >= working_slots.size()) { // 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) { - // if the widget has a minimum or maximum size, we'll make a slot for its preferred size + bool widget_has_fixed_size = child->rect().max_dimension_at(m_direction) != -1 || child->rect().min_dimension_at(m_direction) != -1; + 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(); working_slots.push_back(Slot { 0, child->rect().dimension_at(m_direction), SlotType::Pixel }); 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 { // widgets which have a pre-defined slot diff --git a/src/Widget.hpp b/src/Widget.hpp index 2707d7f..eb00c59 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -92,6 +92,9 @@ public: bool absolute() { return m_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); std::shared_ptr layout() { return m_layout; } @@ -146,6 +149,7 @@ private: bool m_consumes_hits { false }; bool m_accepts_events { true }; bool m_absolute { false }; + bool m_grows { true }; ControlWidgetType m_control_type { ControlWidgetType::Widget }; };