einsatzprotokoll/source/MenuDelegate.mc
EiSiMo a45f1b5215 Tap-to-rotate: tap icon to select, tap selected to open
Tapping an unselected icon in the menu ring rotates to it with
animation. Tapping the already-selected icon opens it. Icon
positions are tracked from last render for hit detection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 19:35:35 +02:00

64 lines
1.8 KiB
MonkeyC

import Toybox.Lang;
import Toybox.WatchUi;
// Routes menu input. UP/DOWN rotate the ring. START/STOP opens
// the selected item. Tap on an icon rotates to it; tap on the
// already-selected icon opens it.
class MenuDelegate extends WatchUi.BehaviorDelegate {
private var _view as MenuView;
function initialize(view as MenuView) {
BehaviorDelegate.initialize();
_view = view;
}
function onNextPage() as Boolean {
_view.rotateNext();
return true;
}
function onPreviousPage() as Boolean {
_view.rotatePrev();
return true;
}
function onTap(evt as WatchUi.ClickEvent) as Boolean {
var coords = evt.getCoordinates();
var tapX = coords[0] as Number;
var tapY = coords[1] as Number;
var idx = _view.itemIndexAt(tapX, tapY);
if (idx < 0) { return false; }
if (idx == _view.selectedIndex()) {
// Tap on already-selected item → open it.
return _openSelected();
}
// Tap on another item → rotate to it.
_view.rotateTo(idx);
return true;
}
function onSelect() as Boolean {
return _openSelected();
}
private function _openSelected() as Boolean {
var item = _view.selectedItem();
var key = item[:key] as String;
if (key.equals(Config.ACTION_HISTORY)) {
var view = new HistoryView();
WatchUi.pushView(view, new HistoryDelegate(view), WatchUi.SLIDE_LEFT);
return true;
}
if (key.equals(Config.ACTION_DELETE)) {
var view = new DeleteView();
WatchUi.pushView(view, new DeleteDelegate(view), WatchUi.SLIDE_LEFT);
return true;
}
WatchUi.pushView(new LoadingView(key), null, WatchUi.SLIDE_IMMEDIATE);
return true;
}
}