[meld: 2/5] sourceview: Draw a slightly off-base-colour background in the overscroll



commit 6f544c1d1fa65738a29f80337b16ca717a28f06d
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Nov 2 10:36:39 2019 +1000

    sourceview: Draw a slightly off-base-colour background in the overscroll
    
    This helps distinguish the overscroll area, particularly for users who
    don't have line numbers turned on.

 data/styles/meld-base.style-scheme.xml.in |  1 +
 data/styles/meld-dark.style-scheme.xml.in |  1 +
 meld/sourceview.py                        | 13 ++++++++++++-
 meld/style.py                             |  3 ++-
 4 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/data/styles/meld-base.style-scheme.xml.in b/data/styles/meld-base.style-scheme.xml.in
index d110c93d..e0181b35 100644
--- a/data/styles/meld-base.style-scheme.xml.in
+++ b/data/styles/meld-base.style-scheme.xml.in
@@ -13,6 +13,7 @@
   <style name="meld:unknown-text" foreground="#888888"/>
   <style name="meld:syncpoint-outline" foreground="#555555"/>
   <style name="meld:current-chunk-highlight" background="#rgba(255, 255, 255, 0.5)"/>
+  <style name="meld:overscroll" background="#rgba(50, 50, 50, 0.1)"/>
   <style name="meld:dimmed" foreground="#999999"/>
   <style name="map-overlay" background="#rgba(100, 100, 100, 0.4)"/>
 </style-scheme>
diff --git a/data/styles/meld-dark.style-scheme.xml.in b/data/styles/meld-dark.style-scheme.xml.in
index 3805ebb9..8e9a2ade 100644
--- a/data/styles/meld-dark.style-scheme.xml.in
+++ b/data/styles/meld-dark.style-scheme.xml.in
@@ -15,5 +15,6 @@
   <style name="meld:syncpoint-outline" foreground="#bbbbbb"/>
   <style name="meld:current-chunk-highlight" background="#rgba(255, 255, 255, 0.06)"/>
   <style name="meld:dimmed" foreground="#999999"/>
+  <style name="meld:overscroll" background="#rgba(255, 255, 255, 0.1)"/>
   <style name="map-overlay" background="#rgba(200, 200, 200, 0.4)"/>
 </style-scheme>
diff --git a/meld/sourceview.py b/meld/sourceview.py
index a762018a..0c93ed87 100644
--- a/meld/sourceview.py
+++ b/meld/sourceview.py
@@ -324,9 +324,10 @@ class MeldSourceView(GtkSource.View, SourceViewHelperMixin):
         context.set_line_width(1.0)
 
         _, clip = Gdk.cairo_get_clip_rectangle(context)
+        clip_end = clip.y + clip.height
         bounds = (
             self.get_line_num_for_y(clip.y),
-            self.get_line_num_for_y(clip.y + clip.height),
+            self.get_line_num_for_y(clip_end),
         )
 
         x = clip.x - 0.5
@@ -352,6 +353,16 @@ class MeldSourceView(GtkSource.View, SourceViewHelperMixin):
 
         textbuffer = self.get_buffer()
 
+        # Check whether we're drawing past the last line in the buffer
+        # (i.e., the overscroll) and draw a custom background if so.
+        end_y, end_height = self.get_line_yrange(textbuffer.get_end_iter())
+        end_y += end_height
+        visible_bottom_margin = clip_end - end_y
+        if visible_bottom_margin > 0:
+            context.rectangle(x + 1, end_y, width - 1, visible_bottom_margin)
+            context.set_source_rgba(*self.fill_colors['overscroll'])
+            context.fill()
+
         # Paint current line highlight
         if self.props.highlight_current_line_local and self.is_focus():
             it = textbuffer.get_iter_at_mark(textbuffer.get_insert())
diff --git a/meld/style.py b/meld/style.py
index 0da89645..b45cffc4 100644
--- a/meld/style.py
+++ b/meld/style.py
@@ -109,7 +109,8 @@ def get_common_theme() -> Tuple[ColourMap, ColourMap]:
         "error": lookup("meld:error", "background"),
         "focus-highlight": lookup("meld:current-line-highlight", "foreground"),
         "current-chunk-highlight": lookup(
-            "meld:current-chunk-highlight", "background")
+            "meld:current-chunk-highlight", "background"),
+        "overscroll": lookup("meld:overscroll", "background"),
     }
     line_colours = {
         "insert": lookup("meld:insert", "line-background"),


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