diff options
| author | cirakg <cirakg@cirakg.xyz> | 2026-10-25 13:13:39 +0100 |
|---|---|---|
| committer | cirakg <cirakg@cirakg.xyz> | 2026-10-25 13:13:39 +0100 |
| commit | 404b505a41362f340e79374ee3ad4dbd468da3e4 (patch) | |
| tree | 883d4f1ecda6c30ce890b1aa4026c8ba1726804e /source/ui/InfoView.mc | |
| parent | 096b5a4d17c85fa5f87db3e72364e9c3506d1e64 (diff) | |
fix(ui): vertical swipes and drags scroll the list and text screens
The Forerunner 70 sends no page behaviour for a swipe on a custom view,
so the list and info screens only scrolled with the buttons. Swipes and
drags now scroll them directly; one gesture scrolls once even when the
device also sends the page behaviour, and a drag's release opens no row.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'source/ui/InfoView.mc')
| -rw-r--r-- | source/ui/InfoView.mc | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/source/ui/InfoView.mc b/source/ui/InfoView.mc index cab4b52..a965713 100644 --- a/source/ui/InfoView.mc +++ b/source/ui/InfoView.mc @@ -16,6 +16,7 @@ class InfoView extends WatchUi.View { private var _first as Number = 0; private var _visible as Number = 1; private var _shownLogged as Boolean = false; + private var _lineH as Number = 1; // screen names the view in "DIAG shown" lines for UI scripts. function initialize(title as String, text as Array<String>, screen as String) { @@ -38,6 +39,7 @@ class InfoView extends WatchUi.View { var max = lines.size() - _visible > 0 ? lines.size() - _visible : 0; var next = _first + delta; next = next < 0 ? 0 : (next > max ? max : next); + Diag.data("info_scroll", "first=" + next); if (next == _first) { return false; } @@ -46,12 +48,18 @@ class InfoView extends WatchUi.View { return true; } + // The height of a text line, as last drawn (for drags). + function lineHeight() as Number { + return _lineH; + } + function onUpdate(dc as Graphics.Dc) as Void { Ui.clear(dc); var w = dc.getWidth(); var h = dc.getHeight(); var font = Graphics.FONT_XTINY; var lineH = dc.getFontHeight(font); + _lineH = lineH; var y = Ui.isRound() ? h / 8 : 6; dc.setColor(Ui.accent(), Graphics.COLOR_TRANSPARENT); dc.drawText(w / 2, y, Graphics.FONT_SMALL, Ui.fit(dc, _title, Graphics.FONT_SMALL, 2 * Ui.halfWidthAt(dc, y)), @@ -114,20 +122,47 @@ class InfoDelegate extends WatchUi.BehaviorDelegate { } function onNextPage() as Boolean { - AppState.activity(); - var v = view(); - if (v != null) { - v.scroll(3); + if (!Gesture.recent()) { + scrollBy(3); } return true; } function onPreviousPage() as Boolean { + if (!Gesture.recent()) { + scrollBy(-3); + } + return true; + } + + private function scrollBy(lines as Number) as Void { AppState.activity(); var v = view(); if (v != null) { - v.scroll(-3); + v.scroll(lines); + } + } + + // A vertical swipe or drag scrolls too (the Forerunner 70 sends no page + // behaviour for them); Gesture makes a gesture count once. + function onSwipe(event as WatchUi.SwipeEvent) as Boolean { + if (!Gesture.isVertical(event)) { + return BehaviorDelegate.onSwipe(event); + } + var step = Gesture.swipeStep(event); + if (step != 0) { + scrollBy(3 * step); + } + return true; + } + + function onDrag(event as WatchUi.DragEvent) as Boolean { + var v = view(); + var step = Gesture.dragStep(event, v != null ? v.lineHeight() : 1); + if (step == 0) { + return false; } + scrollBy(step); return true; } |
