diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2021-03-17 20:11:44 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-18 07:49:55 +0100 |
commit | 3cc7862487d7eefe7f89d4c446c2251497575e5f (patch) | |
tree | f374a94886e51f794fb10ab83210645ff391849e /Userland/Libraries/LibGUI/HeaderView.cpp | |
parent | 663fd9abb44d2181f5845f70e374e748d16b60cd (diff) | |
download | serenity-3cc7862487d7eefe7f89d4c446c2251497575e5f.zip |
LibGUI: Support double-click resizing column headers
Columns can now be best-fit resized by double-clicking their
grabbable edges. When a default width is set and all data is empty,
double-clicking will restore the column to its original state.
Diffstat (limited to 'Userland/Libraries/LibGUI/HeaderView.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/HeaderView.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/HeaderView.cpp b/Userland/Libraries/LibGUI/HeaderView.cpp index c60dbc9e55..8d1413bb86 100644 --- a/Userland/Libraries/LibGUI/HeaderView.cpp +++ b/Userland/Libraries/LibGUI/HeaderView.cpp @@ -117,6 +117,20 @@ int HeaderView::section_count() const return m_orientation == Gfx::Orientation::Horizontal ? model()->column_count() : model()->row_count(); } +void HeaderView::doubleclick_event(MouseEvent& event) +{ + if (!model()) + return; + + int section_count = this->section_count(); + for (int i = 0; i < section_count; ++i) { + if (section_resize_grabbable_rect(i).contains(event.position())) { + if (on_resize_doubleclick) + on_resize_doubleclick(i); + } + } +} + void HeaderView::mousedown_event(MouseEvent& event) { if (!model()) @@ -361,6 +375,28 @@ void HeaderView::set_section_alignment(int section, Gfx::TextAlignment alignment section_data(section).alignment = 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& data = section_data(section); + if (data.default_size == size) + return; + data.default_size = size; + data.has_initialized_default_size = true; +} + +int HeaderView::default_section_size(int section) const +{ + return section_data(section).default_size; +} + +bool HeaderView::is_default_section_size_initialized(int section) const +{ + return section_data(section).has_initialized_default_size; +} + bool HeaderView::is_section_visible(int section) const { return section_data(section).visibility; |