mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
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.
This commit is contained in:
parent
663fd9abb4
commit
3cc7862487
Notes:
sideshowbarker
2024-07-18 21:15:12 +09:00
Author: https://github.com/thankyouverycool
Commit: 3cc7862487
Pull-request: https://github.com/SerenityOS/serenity/pull/5853
4 changed files with 93 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue