Skip to content

Commit 179bf2e

Browse files
committed
CAN HAZ SKROL INVERZUN? Can haz.
1 parent ffa4cb6 commit 179bf2e

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

docs/preferences.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ currently recognized by Terminal::Widgets:
8383
* `Bool input-activation-flash` - If `True`, flash Input widgets when
8484
activated, such as when a Button is clicked. Defaults to `False`.
8585

86+
* `UInt mouse-wheel-horizontal-speed` - Sets number of scrolled cells per mouse
87+
wheel horizontal event, defaulting to twice `mouse-wheel-vertical-speed`.
88+
8689
* `UInt mouse-wheel-vertical-speed` - Sets number of scrolled lines per mouse
8790
wheel vertical event, defaulting to 4 lines per event.
8891

89-
* `UInt mouse-wheel-horizontal-speed` - Sets number of scrolled cells per mouse
90-
wheel horizontal event, defaulting to twice `mouse-wheel-vertical-speed`.
92+
* `Bool scroll-invert-horizontal` - If `True`, invert the direction of
93+
horizontal scroll events. Defaults to `False`.
94+
95+
* `Bool scroll-invert-vertical` - If `True`, invert the direction of vertical
96+
scroll events. Defaults to `False`.

lib/Terminal/Widgets/ScrollBar.rakumod

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,18 @@ class Terminal::Widgets::HScrollBar
6363
does Terminal::Widgets::Scrollbar {
6464
method h-arrow-scroll-inc() {
6565
my $ui-prefs = self.terminal.ui-prefs;
66+
my $h-invert = $ui-prefs<scroll-invert-horizontal> ?? -1 !! +1;
67+
my $h-speed = $ui-prefs<mouse-wheel-horizontal-speed>
68+
|| 2 * ($ui-prefs<mouse-wheel-vertical-speed> || 4);
6669

67-
$ui-prefs<mouse-wheel-horizontal-speed>
68-
|| 2 * ($ui-prefs<mouse-wheel-vertical-speed> || 4)
70+
$h-speed * $h-invert
6971
}
7072

7173
method h-bar-scroll-inc() {
72-
$.scroll-target.content-width
74+
my $ui-prefs = self.terminal.ui-prefs;
75+
my $h-invert = $ui-prefs<scroll-invert-horizontal> ?? -1 !! +1;
76+
77+
$.scroll-target.content-width * $h-invert
7378
}
7479

7580
method arrow-left-scroll() {
@@ -235,11 +240,18 @@ class Terminal::Widgets::VScrollBar
235240
is Terminal::Widgets::Widget
236241
does Terminal::Widgets::Scrollbar {
237242
method v-arrow-scroll-inc() {
238-
self.terminal.ui-prefs<mouse-wheel-vertical-speed> || 4
243+
my $ui-prefs = self.terminal.ui-prefs;
244+
my $v-invert = $ui-prefs<scroll-invert-vertical> ?? -1 !! +1;
245+
my $v-speed = $ui-prefs<mouse-wheel-vertical-speed> || 4;
246+
247+
$v-speed * $v-invert
239248
}
240249

241250
method v-bar-scroll-inc() {
242-
$.scroll-target.content-height
251+
my $ui-prefs = self.terminal.ui-prefs;
252+
my $v-invert = $ui-prefs<scroll-invert-vertical> ?? -1 !! +1;
253+
254+
$.scroll-target.content-height * $v-invert
243255
}
244256

245257
method arrow-up-scroll() {

lib/Terminal/Widgets/Scrollable.rakumod

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ role Terminal::Widgets::Scrollable {
101101
my $ui-prefs = self.terminal.ui-prefs;
102102
my $v-speed = $ui-prefs<mouse-wheel-vertical-speed> || 4;
103103
my $h-speed = $ui-prefs<mouse-wheel-horizontal-speed> || 2 * $v-speed;
104+
my $v-invert = $ui-prefs<scroll-invert-vertical> ?? -1 !! +1;
105+
my $h-invert = $ui-prefs<scroll-invert-horizontal> ?? -1 !! +1;
104106

105107
# Process wheel up/down/left/right
106108
given $event.mouse.button {
107-
when 4 { self.change-y-scroll: -$v-speed }
108-
when 5 { self.change-y-scroll: +$v-speed }
109-
when 6 { self.change-x-scroll: -$h-speed }
110-
when 7 { self.change-x-scroll: +$h-speed }
109+
when 4 { self.change-y-scroll: -$v-speed * $v-invert }
110+
when 5 { self.change-y-scroll: +$v-speed * $v-invert }
111+
when 6 { self.change-x-scroll: -$h-speed * $h-invert }
112+
when 7 { self.change-x-scroll: +$h-speed * $h-invert }
111113
}
112114

113115
self.refresh-for-scroll;

0 commit comments

Comments
 (0)