Skip to content

Commit fba6f38

Browse files
committed
Fade scrollbars when they aren't in use
1 parent 67c6922 commit fba6f38

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

lib/Terminal/Widgets/ScrollBar.rakumod

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,28 @@ class Terminal::Widgets::HScrollBar
101101
$right += $layout.left-correction + $.show-end-arrows;
102102
$left += $layout.left-correction + $.show-end-arrows;
103103

104+
# Fade bar if unneeded (everything visible, scroll = 0)
105+
my $needed = $scroll || $end < $max;
106+
my $g-bar = $needed ?? %!glyphs<bar>
107+
!! $.grid.cell(%!glyphs<bar>, 'faint');
108+
my $g-handle = $needed ?? %!glyphs<handle>
109+
!! $.grid.cell(%!glyphs<handle>, 'faint');
110+
my $g-left = $needed ?? %!glyphs<left>
111+
!! $.grid.cell(%!glyphs<left>, 'faint');
112+
my $g-right = $needed ?? %!glyphs<right>
113+
!! $.grid.cell(%!glyphs<right>, 'faint');
114+
104115
# Actually draw updated bar and handle
105-
my $y = $layout.top-correction;
106-
my $x1 = $layout.left-correction + $.show-end-arrows;
107-
my $x2 = $.w - 1 - $layout.right-correction - $.show-end-arrows;
108-
$.grid.change-cell($_, $y, %!glyphs<bar>) for $x1 .. $x2;
109-
$.grid.change-cell($_, $y, %!glyphs<handle>) for $left .. $right;
116+
my $y = $layout.top-correction;
117+
my $x1 = $layout.left-correction + $.show-end-arrows;
118+
my $x2 = $.w - 1 - $layout.right-correction - $.show-end-arrows;
119+
$.grid.change-cell($_, $y, $g-bar) for $x1 .. $x2;
120+
$.grid.change-cell($_, $y, $g-handle) for $left .. $right;
110121

111122
# Draw optional end arrows
112123
if $.show-end-arrows {
113-
$.grid.change-cell($x1 - 1, $y, %!glyphs<left>);
114-
$.grid.change-cell($x2 + 1, $y, %!glyphs<right>);
124+
$.grid.change-cell($x1 - 1, $y, $g-left);
125+
$.grid.change-cell($x2 + 1, $y, $g-right);
115126
}
116127
}
117128

@@ -230,17 +241,28 @@ class Terminal::Widgets::VScrollBar
230241
$bottom += $layout.top-correction + $.show-end-arrows;
231242
$top += $layout.top-correction + $.show-end-arrows;
232243

244+
# Fade bar if unneeded (everything visible, scroll = 0)
245+
my $needed = $scroll || $end < $max;
246+
my $g-bar = $needed ?? %!glyphs<bar>
247+
!! $.grid.cell(%!glyphs<bar>, 'faint');
248+
my $g-handle = $needed ?? %!glyphs<handle>
249+
!! $.grid.cell(%!glyphs<handle>, 'faint');
250+
my $g-up = $needed ?? %!glyphs<up>
251+
!! $.grid.cell(%!glyphs<up>, 'faint');
252+
my $g-down = $needed ?? %!glyphs<down>
253+
!! $.grid.cell(%!glyphs<down>, 'faint');
254+
233255
# Actually draw updated bar and handle
234256
my $x = $layout.left-correction;
235257
my $y1 = $layout.top-correction + $.show-end-arrows;
236258
my $y2 = $.h - 1 - $layout.bottom-correction - $.show-end-arrows;
237-
$.grid.change-cell($x, $_, %!glyphs<bar>) for $y1 .. $y2;
238-
$.grid.change-cell($x, $_, %!glyphs<handle>) for $top .. $bottom;
259+
$.grid.change-cell($x, $_, $g-bar) for $y1 .. $y2;
260+
$.grid.change-cell($x, $_, $g-handle) for $top .. $bottom;
239261

240262
# Draw optional end arrows
241263
if $.show-end-arrows {
242-
$.grid.change-cell($x, $y1 - 1, %!glyphs<up>);
243-
$.grid.change-cell($x, $y2 + 1, %!glyphs<down>);
264+
$.grid.change-cell($x, $y1 - 1, $g-up);
265+
$.grid.change-cell($x, $y2 + 1, $g-down);
244266
}
245267
}
246268

0 commit comments

Comments
 (0)