Skip to content

Commit 75ae6a7

Browse files
committed
Scrollbars should be Focusable and Themable
1 parent fba6f38 commit 75ae6a7

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

lib/Terminal/Widgets/ScrollBar.rakumod

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
use Terminal::Widgets::Events;
44
use Terminal::Widgets::Widget;
5+
use Terminal::Widgets::Focusable;
6+
use Terminal::Widgets::Themable;
57
use Terminal::Widgets::Scrollable;
68

79
subset ScrollTarget where Str | Terminal::Widgets::Scrollable;
810

911

1012
#| Role for scrollbars of any orientation
11-
role Terminal::Widgets::Scrollbar {
13+
role Terminal::Widgets::Scrollbar
14+
does Terminal::Widgets::Themable
15+
does Terminal::Widgets::Focusable {
1216
has ScrollTarget:D $.scroll-target is required;
1317

1418
has Bool:D $.show-end-arrows = True;
@@ -101,16 +105,15 @@ class Terminal::Widgets::HScrollBar
101105
$right += $layout.left-correction + $.show-end-arrows;
102106
$left += $layout.left-correction + $.show-end-arrows;
103107

104-
# Fade bar if unneeded (everything visible, scroll = 0)
108+
# Get current color according to theme states, fading the
109+
# scrollbar if it's unneeded (everything visible, scroll = 0)
105110
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');
111+
my $color = self.current-color;
112+
$color ~= ' faint' unless $needed;
113+
my $g-bar = $.grid.cell(%!glyphs<bar>, $color);
114+
my $g-handle = $.grid.cell(%!glyphs<handle>, $color);
115+
my $g-left = $.grid.cell(%!glyphs<left>, $color);
116+
my $g-right = $.grid.cell(%!glyphs<right>, $color);
114117

115118
# Actually draw updated bar and handle
116119
my $y = $layout.top-correction;
@@ -241,16 +244,15 @@ class Terminal::Widgets::VScrollBar
241244
$bottom += $layout.top-correction + $.show-end-arrows;
242245
$top += $layout.top-correction + $.show-end-arrows;
243246

244-
# Fade bar if unneeded (everything visible, scroll = 0)
247+
# Get current color according to theme states, fading the
248+
# scrollbar if it's unneeded (everything visible, scroll = 0)
245249
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');
250+
my $color = self.current-color;
251+
$color ~= ' faint' unless $needed;
252+
my $g-bar = $.grid.cell(%!glyphs<bar>, $color);
253+
my $g-handle = $.grid.cell(%!glyphs<handle>, $color);
254+
my $g-up = $.grid.cell(%!glyphs<up>, $color);
255+
my $g-down = $.grid.cell(%!glyphs<down>, $color);
254256

255257
# Actually draw updated bar and handle
256258
my $x = $layout.left-correction;

0 commit comments

Comments
 (0)