// Author: cirakg & claude ai // Summary: Scrollable text screen showing the spike's measurements. // // Lines come from SpikeReport. The first visible line moves with // SpikeDelegate (UP/DOWN buttons or swipes); text stays in the middle band of // round screens so nothing is cut off at the top or bottom. import Toybox.Graphics; import Toybox.Lang; import Toybox.WatchUi; class SpikeView extends WatchUi.View { // Share of the screen height left free at the top and at the bottom. private const MARGIN_FRACTION = 0.14; private var _report as SpikeReport; private var _firstLine as Number = 0; function initialize(report as SpikeReport) { View.initialize(); _report = report; } // Move the first visible line by delta lines, staying within the text. function scroll(delta as Number) as Void { var last = _report.lines.size() - 1; _firstLine += delta; if (_firstLine > last) { _firstLine = last; } if (_firstLine < 0) { _firstLine = 0; } WatchUi.requestUpdate(); } function onUpdate(dc as Graphics.Dc) as Void { dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK); dc.clear(); var font = Graphics.FONT_XTINY; var lineHeight = dc.getFontHeight(font); var top = (dc.getHeight() * MARGIN_FRACTION).toNumber(); var bottom = dc.getHeight() - top; var x = dc.getWidth() / 2; var y = top; var lines = _report.lines; for (var i = _firstLine; i < lines.size() && y + lineHeight <= bottom; i++) { dc.drawText(x, y, font, lines[i], Graphics.TEXT_JUSTIFY_CENTER); y += lineHeight; } } }