mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 19:47:42 +00:00
LibGUI: Remove calculated_min_size() for ListViews
Originally implemented to handle resizable ComboBox windows, this "feature" no longer exists, so calculating min size is no longer necessary. The calculation was also failing to account for dynamic ListViews properly. This patch simplifies things by setting ComboBox ListView's minimum size explicitly and deferring to AbstractScrollableWidget's more flexible calculated implementation otherwise. Fixes FontPicker resizing incorrectly due to overly rigid ListViews.
This commit is contained in:
parent
bd46397e1f
commit
99f28cf4ac
3 changed files with 1 additions and 15 deletions
|
@ -257,6 +257,7 @@ void ComboBox::open()
|
||||||
}
|
}
|
||||||
rect.intersect(desktop);
|
rect.intersect(desktop);
|
||||||
m_list_window->set_rect(rect);
|
m_list_window->set_rect(rect);
|
||||||
|
m_list_view->set_min_size(rect.size());
|
||||||
|
|
||||||
if (m_selected_index.has_value())
|
if (m_selected_index.has_value())
|
||||||
m_list_view->set_cursor(m_selected_index.value(), AbstractView::SelectionUpdate::Set);
|
m_list_view->set_cursor(m_selected_index.value(), AbstractView::SelectionUpdate::Set);
|
||||||
|
|
|
@ -44,7 +44,6 @@ void ListView::update_content_size()
|
||||||
auto text = model()->index(row, m_model_column).data();
|
auto text = model()->index(row, m_model_column).data();
|
||||||
content_width = max(content_width, font().width(text.to_deprecated_string()) + horizontal_padding() * 2);
|
content_width = max(content_width, font().width(text.to_deprecated_string()) + horizontal_padding() * 2);
|
||||||
}
|
}
|
||||||
m_max_item_width = content_width;
|
|
||||||
content_width = max(content_width, widget_inner_rect().width());
|
content_width = max(content_width, widget_inner_rect().width());
|
||||||
|
|
||||||
int content_height = item_count() * item_height();
|
int content_height = item_count() * item_height();
|
||||||
|
@ -268,15 +267,4 @@ void ListView::scroll_into_view(ModelIndex const& index, bool scroll_horizontall
|
||||||
AbstractScrollableWidget::scroll_into_view(content_rect(index.row()), scroll_horizontally, scroll_vertically);
|
AbstractScrollableWidget::scroll_into_view(content_rect(index.row()), scroll_horizontally, scroll_vertically);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<UISize> ListView::calculated_min_size() const
|
|
||||||
{
|
|
||||||
auto min_width = horizontal_scrollbar().effective_min_size().width().as_int() + vertical_scrollbar().width() + frame_thickness() * 2;
|
|
||||||
auto min_height = vertical_scrollbar().effective_min_size().height().as_int() + horizontal_scrollbar().height() + frame_thickness() * 2;
|
|
||||||
auto content_exceeds_minimums = content_width() > min_width && content_height() > min_height;
|
|
||||||
auto scrollbars_are_visible = horizontal_scrollbar().is_visible() && vertical_scrollbar().is_visible();
|
|
||||||
if (content_exceeds_minimums || scrollbars_are_visible)
|
|
||||||
return AbstractScrollableWidget::calculated_min_size();
|
|
||||||
return { { m_max_item_width + frame_thickness() * 2, content_height() + frame_thickness() * 2 } };
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,15 +56,12 @@ private:
|
||||||
virtual void mousemove_event(MouseEvent&) override;
|
virtual void mousemove_event(MouseEvent&) override;
|
||||||
virtual void layout_relevant_change_occurred() override;
|
virtual void layout_relevant_change_occurred() override;
|
||||||
|
|
||||||
virtual Optional<UISize> calculated_min_size() const override;
|
|
||||||
|
|
||||||
Gfx::IntRect content_rect(int row) const;
|
Gfx::IntRect content_rect(int row) const;
|
||||||
void update_content_size();
|
void update_content_size();
|
||||||
|
|
||||||
int m_horizontal_padding { 2 };
|
int m_horizontal_padding { 2 };
|
||||||
int m_vertical_padding { 2 };
|
int m_vertical_padding { 2 };
|
||||||
int m_model_column { 0 };
|
int m_model_column { 0 };
|
||||||
int m_max_item_width { 0 };
|
|
||||||
bool m_alternating_row_colors { true };
|
bool m_alternating_row_colors { true };
|
||||||
bool m_hover_highlighting { false };
|
bool m_hover_highlighting { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue