improve boxlayout growing
This commit is contained in:
parent
43eec85adc
commit
e8f095bfc4
2 changed files with 14 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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> layout);
|
||||
std::shared_ptr<Layout> 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 };
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue