diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-08-08 09:50:36 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-08 14:12:45 +0200 |
commit | ab2719fd53f35f899f7625799140e1af47aa4403 (patch) | |
tree | ad8b90911eaca1ff9a87b676362114a27ba34f75 /Userland/Libraries/LibGUI | |
parent | 854e16797ee9b7e5f60bc93cf2ee6cd39825ddab (diff) | |
download | serenity-ab2719fd53f35f899f7625799140e1af47aa4403.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractTableView.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractTableView.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/HeaderView.cpp | 17 |
3 files changed, 23 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGUI/AbstractTableView.cpp b/Userland/Libraries/LibGUI/AbstractTableView.cpp index 9e26067280..58856b21fe 100644 --- a/Userland/Libraries/LibGUI/AbstractTableView.cpp +++ b/Userland/Libraries/LibGUI/AbstractTableView.cpp @@ -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()) diff --git a/Userland/Libraries/LibGUI/AbstractTableView.h b/Userland/Libraries/LibGUI/AbstractTableView.h index cf5000be8d..4bfa470027 100644 --- a/Userland/Libraries/LibGUI/AbstractTableView.h +++ b/Userland/Libraries/LibGUI/AbstractTableView.h @@ -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); diff --git a/Userland/Libraries/LibGUI/HeaderView.cpp b/Userland/Libraries/LibGUI/HeaderView.cpp index 39401c02b1..29798d8d35 100644 --- a/Userland/Libraries/LibGUI/HeaderView.cpp +++ b/Userland/Libraries/LibGUI/HeaderView.cpp @@ -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) |