Commit be594439 authored by Petr Štětka's avatar Petr Štětka

graph-stack-switcher: Better change active button on scrolling

With this commit GraphStackSwitcher will switch active button
when subview will occupy more than half of displayed window.

This too solve problem when is last subview smaller then half of
window but window is scrolled to the end using bottom tolerance.

This is much more intuitive for users and gives it a sense of user
experience.
parent 519bf669
Pipeline #74284 failed with stage
in 2 minutes and 43 seconds
......@@ -26,6 +26,7 @@ namespace Usage
AnimatedScrolledWindow scrolled_window;
GraphSwitcherButton[] buttons;
private const int BOTTOM_TOLERANCE = 150;
class construct
{
......@@ -83,17 +84,29 @@ namespace Usage
private void on_scroll_changed(double y)
{
Gtk.Allocation alloc;
var button_number = 0;
for(int i = 1; i < buttons.length; i++)
{
this.sub_views[i].get_allocation(out alloc);
if(y < alloc.y)
Gtk.Allocation container_alloc;
sub_views[0].parent.parent.get_allocation(out container_alloc);
for(int i = 0; i < sub_views.length; i++) {
Gtk.Allocation sub_view_alloc;
sub_views[i].get_allocation(out sub_view_alloc);
if(y + container_alloc.height / 2 < sub_view_alloc.y + sub_view_alloc.height) {
button_number = i;
break;
button_number = i;
}
}
var last_subview_number = sub_views.length - 1;
Gtk.Allocation last_subview_alloc;
sub_views[last_subview_number].get_allocation(out last_subview_alloc);
if(y < BOTTOM_TOLERANCE)
button_number = 0;
else if(y + container_alloc.height > last_subview_alloc.y + last_subview_alloc.height - BOTTOM_TOLERANCE)
button_number = last_subview_number;
buttons[button_number].set_active(true);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment