[meld] diffmap: Store the calculated y + height we want, not the base values



commit fff6ef47582f0592296060e706983650f16a5dd8
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Nov 18 05:27:59 2017 +1000

    diffmap: Store the calculated y + height we want, not the base values
    
    Not a big deal, but there just wasn't much point to this and the
    copy-pasted calculations ended up being weird. In particular, the click
    handling code was offset by one pixel at each end from the display,
    which was... probably fine? but also odd.

 meld/diffmap.py |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)
---
diff --git a/meld/diffmap.py b/meld/diffmap.py
index 7548cdf..16ae720 100644
--- a/meld/diffmap.py
+++ b/meld/diffmap.py
@@ -37,8 +37,8 @@ class DiffMap(Gtk.DrawingArea):
         self._handlers = []
         self._y_offset = 0
         self._h_offset = 0
-        self._scroll_y = 0
-        self._scroll_height = 0
+        self._y_start = 0
+        self._height = 0
         self._setup = False
         self._width = 10
         meldsettings.connect('changed', self.on_setting_changed)
@@ -104,8 +104,9 @@ class DiffMap(Gtk.DrawingArea):
 
     def on_scrollbar_size_allocate(self, scrollbar, allocation):
         translation = scrollbar.translate_coordinates(self, 0, 0)
-        self._scroll_y = translation[1] if translation else 0
-        self._scroll_height = allocation.height
+        _scroll_y = translation[1] if translation else 0
+        self._y_start = _scroll_y + self._y_offset + 1
+        self._height = allocation.height - self._h_offset - 1
         self._width = max(allocation.width, 10)
         self._cached_map = None
         self.queue_resize()
@@ -113,8 +114,7 @@ class DiffMap(Gtk.DrawingArea):
     def do_draw(self, context):
         if not self._setup:
             return
-        height = self._scroll_height - self._h_offset - 1
-        y_start = self._scroll_y + self._y_offset + 1
+        height = self._height
         width = self.get_allocated_width()
         xpad = 2.5
         x0 = xpad
@@ -123,7 +123,7 @@ class DiffMap(Gtk.DrawingArea):
         if not (width > 0 and height > 0):
             return
 
-        context.translate(0, y_start)
+        context.translate(0, self._y_start)
         context.set_line_width(1)
         context.rectangle(x0 - 3, -1, x1 + 6, height + 1)
         context.clip()
@@ -165,9 +165,7 @@ class DiffMap(Gtk.DrawingArea):
 
     def do_button_press_event(self, event):
         if event.button == 1:
-            y_start = self._scroll_y + self._y_offset
-            total_height = self._scroll_height - self._h_offset
-            fraction = (event.y - y_start) / total_height
+            fraction = (event.y - self._y_start) / self._height
 
             adj = self._scrolladj
             val = fraction * adj.get_upper() - adj.get_page_size() / 2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]