somewhat limit scrolling extents

This commit is contained in:
hippoz 2022-10-28 02:35:42 +03:00
parent dfa13dc46d
commit a2120328f1
Signed by: hippoz
GPG key ID: 7C52899193467641
3 changed files with 11 additions and 4 deletions

View file

@ -43,9 +43,16 @@ void ListView::on_mouse_button(MouseButtonEvent &event) {
}
} else if (event.did_scroll_down()) {
m_scroll += m_scroll_step;
auto items_size = m_item_height * elements.size();
if (m_scroll > items_size) {
m_scroll = items_size;
}
repaint();
} else if (event.did_scroll_up()) {
m_scroll -= m_scroll_step;
if (m_scroll < 0) {
m_scroll = 0;
}
repaint();
}
}

View file

@ -26,9 +26,9 @@ std::shared_ptr<Widget> ScrollContainer::make_target() {
void ScrollContainer::on_mouse_button(MouseButtonEvent &event) {
if (event.did_scroll_down()) {
set_scroll(Point(m_scroll.x(), m_scroll.y() + m_scroll_step));
set_scroll(Point(m_scroll.x(), std::min(m_scroll.y() + m_scroll_step, m_target->rect().height())));
} else if (event.did_scroll_up()) {
set_scroll(Point(m_scroll.x(), m_scroll.y() - m_scroll_step));
set_scroll(Point(m_scroll.x(), std::max(0.0, m_scroll.y() - m_scroll_step)));
}
}

View file

@ -35,7 +35,7 @@ int main() {
test_layout->set_margin(69);
test_layout->set_spacing(10);
for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 50; i++) {
test_widget->add<Raven::Button>("Hello: " + std::to_string(i));
}
@ -104,7 +104,7 @@ int main() {
selected_label->set_text("Selected: " + item);
};
int i = 1000;
int i = 100;
while (i --> 0) {
list_view->elements.push_back("Item " + std::to_string(i));
}