mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 04:20:28 +00:00
LibGUI: Let the table view tell HeaderView about the min. section size
Previously HeaderView would just assume that each column or row could have a minimum size of 2. This makes it so that AbstractTableView subclasses can provide a new minimum value for a specific column.
This commit is contained in:
parent
854e16797e
commit
ab2719fd53
Notes:
sideshowbarker
2024-07-18 07:14:51 +09:00
Author: https://github.com/sin-ack Commit: https://github.com/SerenityOS/serenity/commit/ab2719fd53f Pull-request: https://github.com/SerenityOS/serenity/pull/9282
3 changed files with 23 additions and 6 deletions
|
@ -179,6 +179,16 @@ void AbstractTableView::set_column_width(int column, int width)
|
|||
column_header().set_section_size(column, width);
|
||||
}
|
||||
|
||||
int AbstractTableView::minimum_column_width(int)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
int AbstractTableView::minimum_row_height(int)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
Gfx::TextAlignment AbstractTableView::column_header_alignment(int column_index) const
|
||||
{
|
||||
if (!model())
|
||||
|
|
|
@ -39,6 +39,8 @@ public:
|
|||
int column_width(int column) const;
|
||||
void set_column_width(int column, int width);
|
||||
void set_default_column_width(int column, int width);
|
||||
virtual int minimum_column_width(int column);
|
||||
virtual int minimum_row_height(int row);
|
||||
|
||||
Gfx::TextAlignment column_header_alignment(int column) const;
|
||||
void set_column_header_alignment(int column, Gfx::TextAlignment);
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static constexpr int minimum_column_size = 2;
|
||||
|
||||
HeaderView::HeaderView(AbstractTableView& table_view, Gfx::Orientation orientation)
|
||||
: m_table_view(table_view)
|
||||
, m_orientation(orientation)
|
||||
|
@ -179,8 +177,13 @@ void HeaderView::mousemove_event(MouseEvent& event)
|
|||
if (m_in_section_resize) {
|
||||
auto delta = event.position() - m_section_resize_origin;
|
||||
int new_size = m_section_resize_original_width + delta.primary_offset_for_orientation(m_orientation);
|
||||
if (new_size <= minimum_column_size)
|
||||
new_size = minimum_column_size;
|
||||
|
||||
auto minimum_size = orientation() == Orientation::Horizontal
|
||||
? m_table_view.minimum_column_width(m_resizing_section)
|
||||
: m_table_view.minimum_row_height(m_resizing_section);
|
||||
|
||||
if (new_size <= minimum_size)
|
||||
new_size = minimum_size;
|
||||
VERIFY(m_resizing_section >= 0 && m_resizing_section < model()->column_count());
|
||||
set_section_size(m_resizing_section, new_size);
|
||||
return;
|
||||
|
@ -393,8 +396,10 @@ void HeaderView::set_section_alignment(int section, Gfx::TextAlignment alignment
|
|||
|
||||
void HeaderView::set_default_section_size(int section, int size)
|
||||
{
|
||||
if (orientation() == Gfx::Orientation::Horizontal && size < minimum_column_size)
|
||||
size = minimum_column_size;
|
||||
auto minimum_column_width = m_table_view.minimum_column_width(section);
|
||||
|
||||
if (orientation() == Gfx::Orientation::Horizontal && size < minimum_column_width)
|
||||
size = minimum_column_width;
|
||||
|
||||
auto& data = section_data(section);
|
||||
if (data.default_size == size)
|
||||
|
|
Loading…
Reference in a new issue