Skip to content

Commit

Permalink
feat: scroll to top on Home (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
toolstack authored Dec 10, 2024
1 parent 6e81553 commit 7f8c8d3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions data/gtk/help-overlay.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
<property name="action-name">app.scroll-page-down</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes">Scroll to Top</property>
<property name="action-name">app.scroll-page-to-top</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
6 changes: 6 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace Tuba {
{ "back-home", back_home_activated },
{ "scroll-page-down", scroll_view_page_down },
{ "scroll-page-up", scroll_view_page_up },
{ "scroll-page-to-top", scroll_view_page_to_top },
{ "goto-notifications", goto_notifications },
{ "open-status-url", open_status_url, "s" },
{ "answer-follow-request", answer_follow_request, "(ssb)" },
Expand Down Expand Up @@ -327,6 +328,7 @@ namespace Tuba {
set_accels_for_action ("app.back-home", {"<Alt>Home"});
set_accels_for_action ("app.scroll-page-down", {"Page_Down"});
set_accels_for_action ("app.scroll-page-up", {"Page_Up"});
set_accels_for_action ("app.scroll-page-to-top", {"Home"});
add_action_entries (APP_ENTRIES, this);

if (settings.monitor_network)
Expand Down Expand Up @@ -497,6 +499,10 @@ namespace Tuba {
main_window.go_back_to_start ();
}

void scroll_view_page_to_top () {
main_window.scroll_view_to_top ();
}

void scroll_view_page_down () {
main_window.scroll_view_page ();
}
Expand Down
7 changes: 7 additions & 0 deletions src/Dialogs/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
}
}

public void scroll_view_to_top () {
var c_view = navigation_view.visible_page.child as Views.Base;
if (c_view != null) {
c_view.on_scroll_to_top ();
}
}

// public override bool delete_event (Gdk.EventAny event) {
// window = null;
// return app.on_window_closed ();
Expand Down
2 changes: 1 addition & 1 deletion src/Views/Base.vala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class Tuba.Views.Base : Adw.BreakpointBin {
header.show_start_title_buttons = !header.show_start_title_buttons;
}

private void on_scroll_to_top () {
public virtual void on_scroll_to_top () {
scrolled.scroll_child (Gtk.ScrollType.START, false);
}

Expand Down
6 changes: 6 additions & 0 deletions src/Views/TabbedBase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ public class Tuba.Views.TabbedBase : Views.Base {
base_status = null;
}

public override void on_scroll_to_top () {
var c_scrolled = stack.visible_child as Views.Base;
if (c_scrolled != null)
c_scrolled.on_scroll_to_top ();
}

public override void scroll_page (bool up = false) {
var c_scrolled = stack.visible_child as Views.Base;
if (c_scrolled != null)
Expand Down

0 comments on commit 7f8c8d3

Please sign in to comment.