commit:2744fefc32dbe9b59a570f6515d51121b8fcfbe3
author:Chip Black
committer:Chip Black
date:Tue Sep 15 23:14:39 2009 -0500
parents:de68be10ae8d84f85431c704bb06d89e4d93cc98
Fix scrolling functionality

Added Scroll(x, y) and Bump(x, y) functions to WebThing.  Scroll moves
in pixels (or whatever unit measure Gtk uses), and Bump moves in default
scroll increments (like what you'd get if you used the arrow keys).
diff --git a/WebThing.cs b/WebThing.cs
line changes: +13/-0
index 8bc589a..ff51354
--- a/WebThing.cs
+++ b/WebThing.cs
@@ -225,5 +225,18 @@ namespace bytex64.WebThing {
             wtv.WebView.Open(uri);
             return true;
         }
+
+        public void Scroll(double x, double y) {
+            ScrolledWindow.Hadjustment.Value += x;
+            if (ScrolledWindow.Hadjustment.Value > ScrolledWindow.Hadjustment.Upper - ScrolledWindow.Hadjustment.PageSize)
+                ScrolledWindow.Hadjustment.Value = ScrolledWindow.Hadjustment.Upper - ScrolledWindow.Hadjustment.PageSize;
+            ScrolledWindow.Vadjustment.Value += y;
+            if (ScrolledWindow.Vadjustment.Value > ScrolledWindow.Vadjustment.Upper - ScrolledWindow.Vadjustment.PageSize)
+                ScrolledWindow.Vadjustment.Value = ScrolledWindow.Vadjustment.Upper - ScrolledWindow.Vadjustment.PageSize;
+        }
+
+        public void Bump(int x, int y) {
+            Scroll(x * ScrolledWindow.Hadjustment.StepIncrement, y * ScrolledWindow.Vadjustment.StepIncrement);
+        }
     }
 }

diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs
line changes: +4/-4
index 51c2cfc..22f2532
--- a/plugins/Vimish.cs
+++ b/plugins/Vimish.cs
@@ -66,16 +66,16 @@ public class Vimish : WebThingPlugin {
         if (e.Event.State == Gdk.ModifierType.None) {
             switch(e.Event.Key) {
             case Gdk.Key.j:
-                wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement;
+                wt.Bump(0, 1);
                 break;
             case Gdk.Key.k:
-                wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement;
+                wt.Bump(0, -1);
                 break;
             case Gdk.Key.l:
-                wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement;
+                wt.Bump(1, 0);
                 break;
             case Gdk.Key.h:
-                wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement;
+                wt.Bump(-1, 0);
                 break;
             case Gdk.Key.r:
                 wv.Reload();