mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
LibGUI: Implement calculated_min_size() for ListView
This commit is contained in:
parent
d495405e53
commit
f0a5ce6d11
2 changed files with 15 additions and 1 deletions
|
@ -44,7 +44,7 @@ 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_string()) + horizontal_padding() * 2);
|
content_width = max(content_width, font().width(text.to_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,4 +268,15 @@ 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,12 +56,15 @@ private:
|
||||||
virtual void mousemove_event(MouseEvent&) override;
|
virtual void mousemove_event(MouseEvent&) override;
|
||||||
virtual void layout_relevant_change_occured() override;
|
virtual void layout_relevant_change_occured() 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