mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
LibGUI: Support GTableView navigation with Page Up and Page Down.
Also base the vertical scrollbar's gutter range on the visible content rect, making it very similar to a Page Up/Down. Maybe they should be exactly the same, I don't know.
This commit is contained in:
parent
c350cf7b95
commit
63cdc3d2d5
Notes:
sideshowbarker
2024-07-19 15:34:00 +09:00
Author: https://github.com/awesomekling
Commit: 63cdc3d2d5
1 changed files with 22 additions and 1 deletions
|
@ -11,7 +11,6 @@ GTableView::GTableView(GWidget* parent)
|
|||
|
||||
m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this);
|
||||
m_vertical_scrollbar->set_step(4);
|
||||
m_vertical_scrollbar->set_big_step(30);
|
||||
m_vertical_scrollbar->on_change = [this] (int) {
|
||||
update();
|
||||
};
|
||||
|
@ -55,6 +54,8 @@ void GTableView::update_scrollbar_ranges()
|
|||
int available_width = width() - m_vertical_scrollbar->width();
|
||||
int excess_width = max(0, content_width() - available_width);
|
||||
m_horizontal_scrollbar->set_range(0, excess_width);
|
||||
|
||||
m_vertical_scrollbar->set_big_step(visible_content_rect().height() - item_height());
|
||||
}
|
||||
|
||||
int GTableView::content_width() const
|
||||
|
@ -196,6 +197,26 @@ void GTableView::keydown_event(GKeyEvent& event)
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (event.key() == KeyCode::Key_PageUp) {
|
||||
int items_per_page = visible_content_rect().height() / item_height();
|
||||
GModelIndex new_index(max(0, model.selected_index().row() - items_per_page), model.selected_index().column());
|
||||
if (model.is_valid(new_index)) {
|
||||
model.set_selected_index(new_index);
|
||||
scroll_into_view(new_index, Orientation::Vertical);
|
||||
update();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.key() == KeyCode::Key_PageDown) {
|
||||
int items_per_page = visible_content_rect().height() / item_height();
|
||||
GModelIndex new_index(min(model.row_count() - 1, model.selected_index().row() + items_per_page), model.selected_index().column());
|
||||
if (model.is_valid(new_index)) {
|
||||
model.set_selected_index(new_index);
|
||||
scroll_into_view(new_index, Orientation::Vertical);
|
||||
update();
|
||||
}
|
||||
return;
|
||||
}
|
||||
return GWidget::keydown_event(event);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue