[meld/ui-next] chunkmap: Scale textview chunk maps using paired textviews



commit 0ad3e7edbf40c4ba5861e67cbd1808507480cf45
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Apr 13 08:25:12 2019 +1000

    chunkmap: Scale textview chunk maps using paired textviews
    
    With this patch we now scale the total height of chunk maps for
    textviews according to the maximum adjustment height of the views next
    to them.
    
    The idea behind this change is that it's misleading to show maps that
    are next to each other as being the same size. Comparing files of
    different sizes should indicate that this is the case, and insertions
    will offset the diffs.

 meld/chunkmap.py              | 43 +++++++++++++++++++++++++++++++++++++++----
 meld/resources/ui/filediff.ui |  6 ++++++
 2 files changed, 45 insertions(+), 4 deletions(-)
---
diff --git a/meld/chunkmap.py b/meld/chunkmap.py
index 0239a529..5c4d032b 100644
--- a/meld/chunkmap.py
+++ b/meld/chunkmap.py
@@ -104,6 +104,9 @@ class ChunkMap(Gtk.DrawingArea):
             self.fill_colors, self.line_colors = get_common_theme()
             self._cached_map = None
 
+    def get_height_scale(self) -> float:
+        return 1.0
+
     def chunk_coords_by_tag(self) -> Mapping[str, List[Tuple[float, float]]]:
         """Map chunks to buffer offsets for drawing, ordered by tag"""
         raise NotImplementedError()
@@ -120,6 +123,7 @@ class ChunkMap(Gtk.DrawingArea):
 
         x0 = self.overdraw_padding + 0.5
         x1 = width - 2 * x0
+        height_scale = height * self.get_height_scale()
 
         if self._cached_map is None:
             surface = cairo.Surface.create_similar(
@@ -134,7 +138,7 @@ class ChunkMap(Gtk.DrawingArea):
             for tag, diffs in tagged_diffs.items():
                 cache_ctx.set_source_rgba(*self.fill_colors[tag])
                 for y0, y1 in diffs:
-                    y0, y1 = round(y0 * height) + 0.5, round(y1 * height) - 0.5
+                    y0, y1 = round(y0 * height_scale) + 0.5, round(y1 * height_scale) - 0.5
                     cache_ctx.rectangle(x0, y0, x1, y1 - y0)
                 cache_ctx.fill_preserve()
                 cache_ctx.set_source_rgba(*self.line_colors[tag])
@@ -151,8 +155,8 @@ class ChunkMap(Gtk.DrawingArea):
         adj_y = self.adjustment.get_value() / self.adjustment.get_upper()
         adj_h = self.adjustment.get_page_size() / self.adjustment.get_upper()
         context.rectangle(
-            x0 - self.overdraw_padding, round(height * adj_y) + 0.5,
-            x1 + 2 * self.overdraw_padding, round(height * adj_h) - 1,
+            x0 - self.overdraw_padding, round(height_scale * adj_y) + 0.5,
+            x1 + 2 * self.overdraw_padding, round(height_scale * adj_h) - 1,
         )
         context.fill_preserve()
         Gdk.cairo_set_source_rgba(context, self.handle_outline)
@@ -174,7 +178,8 @@ class ChunkMap(Gtk.DrawingArea):
         if not self.adjustment:
             return
 
-        fraction = position / self.get_allocated_height()
+        height = self.get_height_scale() * self.get_allocated_height()
+        fraction = position / height
         adj = self.adjustment
         location = fraction * (adj.get_upper() - adj.get_lower())
 
@@ -217,6 +222,36 @@ class TextViewChunkMap(ChunkMap):
         ),
     )
 
+    paired_adjustment_1 = GObject.Property(
+        type=Gtk.Adjustment,
+        nick='Paired adjustment used for scaling the map',
+        flags=(
+            GObject.ParamFlags.READWRITE |
+            GObject.ParamFlags.CONSTRUCT_ONLY
+        ),
+    )
+
+    paired_adjustment_2 = GObject.Property(
+        type=Gtk.Adjustment,
+        nick='Paired adjustment used for scaling the map',
+        flags=(
+            GObject.ParamFlags.READWRITE |
+            GObject.ParamFlags.CONSTRUCT_ONLY
+        ),
+    )
+
+    def get_height_scale(self):
+        adjustments = [
+            self.props.adjustment,
+            self.props.paired_adjustment_1,
+            self.props.paired_adjustment_2,
+        ]
+        heights = [
+            adj.get_upper() for adj in adjustments
+            if adj.get_upper() > 0
+        ]
+        return self.props.adjustment.get_upper() / max(heights)
+
     def chunk_coords_by_tag(self):
 
         buf = self.textview.get_buffer()
diff --git a/meld/resources/ui/filediff.ui b/meld/resources/ui/filediff.ui
index 00687c95..aa0ad38d 100644
--- a/meld/resources/ui/filediff.ui
+++ b/meld/resources/ui/filediff.ui
@@ -653,6 +653,8 @@
                         <property name="visible">True</property>
                         <property name="width_request">15</property>
                         <property name="adjustment">pane_adjustment0</property>
+                        <property name="paired_adjustment_1">pane_adjustment1</property>
+                        <property name="paired_adjustment_2">pane_adjustment2</property>
                         <property name="textview">textview0</property>
                       </object>
                     </child>
@@ -661,6 +663,8 @@
                         <property name="visible">True</property>
                         <property name="width_request">15</property>
                         <property name="adjustment">pane_adjustment1</property>
+                        <property name="paired_adjustment_1">pane_adjustment0</property>
+                        <property name="paired_adjustment_2">pane_adjustment2</property>
                         <property name="textview">textview1</property>
                       </object>
                     </child>
@@ -669,6 +673,8 @@
                         <property name="visible">True</property>
                         <property name="width_request">15</property>
                         <property name="adjustment">pane_adjustment2</property>
+                        <property name="paired_adjustment_1">pane_adjustment0</property>
+                        <property name="paired_adjustment_2">pane_adjustment1</property>
                         <property name="textview">textview2</property>
                       </object>
                     </child>


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