gui/views/week-view: Add shortcuts for zooming in/out

It's possible to change the density of the week view, but only through
pinch-zooming or Ctrl+scroll wheel. This means it can't be done with
only the keyboard, and since neither of these methods are documented,
it's not discoverable either.

This adds shortcuts for zooming the view in and out, and documents them
in the shortcuts dialog to make them discoverable.

Helps #1556

Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/859>
This commit is contained in:
ARAKHNID
2026-10-02 21:33:57 +00:00
committed by Marge Bot
parent f6bbd38023
commit a635ca51ed
3 changed files with 61 additions and 0 deletions
+10
View File
@@ -78,6 +78,16 @@ Adw.ShortcutsDialog shortcuts_dialog {
title: C_("shortcut dialog", "Previous View");
accelerator: "<Primary>Page_Up";
}
Adw.ShortcutsItem {
title: C_("shortcut dialog", "Zoom In");
accelerator: "<Primary>plus";
}
Adw.ShortcutsItem {
title: C_("shortcut dialog", "Zoom Out");
accelerator: "<Primary>minus";
}
}
Adw.ShortcutsSection {
+22
View File
@@ -3,6 +3,28 @@ using Gtk 4.0;
template $GcalWeekView: Box {
orientation: vertical;
ShortcutController {
Shortcut {
trigger: "<Primary>plus";
action: "action(week-view.zoom-in)";
}
Shortcut {
trigger: "<Primary>minus";
action: "action(week-view.zoom-out)";
}
Shortcut {
trigger: "<Primary>KP_Add";
action: "action(week-view.zoom-in)";
}
Shortcut {
trigger: "<Primary>KP_Subtract";
action: "action(week-view.zoom-out)";
}
}
styles [
"week-view",
]
+29
View File
@@ -388,6 +388,32 @@ stack_visible_child_changed_cb (AdwViewStack *stack,
g_clear_signal_handler (&self->stack_page_changed_id, stack);
}
static void
zoom_in_activated_cb (GtkWidget *widget,
const char *action_name,
GVariant *param)
{
GcalWeekView *self = GCAL_WEEK_VIEW (widget);
gdouble view_center_y = gtk_widget_get_height (self->scrolled_window) / 2.0;
begin_zoom (self, view_center_y);
apply_zoom (self, view_center_y, 1.1);
save_zoom_level (self);
}
static void
zoom_out_activated_cb (GtkWidget *widget,
const char *action_name,
GVariant *param)
{
GcalWeekView *self = GCAL_WEEK_VIEW (widget);
gdouble view_center_y = gtk_widget_get_height (self->scrolled_window) / 2.0;
begin_zoom (self, view_center_y);
apply_zoom (self, view_center_y, 0.9);
save_zoom_level (self);
}
/* GcalView implementation */
static GDateTime*
@@ -624,6 +650,9 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_zoom_gesture_end_cb);
gtk_widget_class_set_css_name (widget_class, "calendar-view");
gtk_widget_class_install_action (widget_class, "week-view.zoom-in", NULL, zoom_in_activated_cb);
gtk_widget_class_install_action (widget_class, "week-view.zoom-out", NULL, zoom_out_activated_cb);
}
static void