[gnome-text-editor] sourceview: implement ctrl+scroll for zoom
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] sourceview: implement ctrl+scroll for zoom
- Date: Wed, 8 Dec 2021 22:19:02 +0000 (UTC)
commit 72ea0784ec63d1d92559ac99eaecd640fe15af09
Author: Christian Hergert <chergert redhat com>
Date: Wed Dec 8 14:18:55 2021 -0800
sourceview: implement ctrl+scroll for zoom
I attempted to keep the top-line pinned but given how background line
sizing and validation works in GtkTextView, it just looked more jittery
than this.
Fixes #248
src/editor-source-view.c | 51 +++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 46 insertions(+), 5 deletions(-)
---
diff --git a/src/editor-source-view.c b/src/editor-source-view.c
index 537729f..87ac627 100644
--- a/src/editor-source-view.c
+++ b/src/editor-source-view.c
@@ -228,6 +228,42 @@ cleanup:
(const char * const *)corrections);
}
+static void
+editor_source_view_zoom (EditorSourceView *self,
+ int amount)
+{
+ g_assert (EDITOR_IS_SOURCE_VIEW (self));
+
+ if (amount == 0)
+ self->font_scale = 0;
+ else
+ self->font_scale += amount;
+
+ editor_source_view_update_css (self);
+}
+
+static gboolean
+on_scroll_scrolled_cb (GtkEventControllerScroll *scroll,
+ double dx,
+ double dy,
+ EditorSourceView *self)
+{
+ GdkModifierType mods;
+
+ g_assert (GTK_IS_EVENT_CONTROLLER_SCROLL (scroll));
+ g_assert (EDITOR_IS_SOURCE_VIEW (self));
+
+ mods = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (scroll));
+
+ if ((mods & GDK_CONTROL_MASK) != 0)
+ {
+ editor_source_view_zoom (self, dy < 0 ? 1 : -1);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
on_notify_buffer_cb (EditorSourceView *self,
GParamSpec *pspec,
@@ -336,15 +372,13 @@ editor_source_view_action_zoom (GtkWidget *widget,
g_assert (EDITOR_IS_SOURCE_VIEW (self));
if (g_strcmp0 (action_name, "page.zoom-in") == 0)
- self->font_scale++;
+ editor_source_view_zoom (self, 1);
else if (g_strcmp0 (action_name, "page.zoom-out") == 0)
- self->font_scale--;
+ editor_source_view_zoom (self, -1);
else if (g_strcmp0 (action_name, "page.zoom-one") == 0)
- self->font_scale = 0;
+ editor_source_view_zoom (self, 0);
else
g_assert_not_reached ();
-
- editor_source_view_update_css (self);
}
static void
@@ -591,6 +625,13 @@ editor_source_view_init (EditorSourceView *self)
self);
gtk_widget_add_controller (GTK_WIDGET (self), controller);
+ controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
+ g_signal_connect (controller,
+ "scroll",
+ G_CALLBACK (on_scroll_scrolled_cb),
+ self);
+ gtk_widget_add_controller (GTK_WIDGET (self), controller);
+
tweak_gutter_spacing (GTK_SOURCE_VIEW (self));
joined = editor_joined_menu_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]