Compare commits

..
Author SHA1 Message Date
MasterControl 5790e98d27 [verified] merge upstream c162c8e6 into all-features 2026-11-14 23:24:08 +00:00
Blendman974 10648aec4a Merge pull request 'fix(ble): fall back to direct connect when autoConnect can't reach an arm' (#19) from MasterControl/faceclaw:fix/ble-direct-connect-fallback into build/all-features
Reviewed-on: Blendman974/faceclaw#19
2026-11-14 22:20:32 +00:00
MasterControl 52ead474e2 fix(ble): fall back to direct connect when autoConnect can't reach an arm
autoConnect only connects on a fresh advertisement, so an arm stuck in a
half-open state (stopped advertising after a dropped link) is never reached.
Retry with a direct connect: its aggressive scan catches a briefly-advertising
arm and the cached bond can recover the half-open link. Adds a
g2.connect-fallback-direct counter for diagnostics.
2026-11-14 21:46:58 +00:00
Blendman974 e4d3286b3d Merge pull request 'fix(ble): connect G2 arms with autoConnect=true' (#18) from MasterControl/faceclaw:fix/ble-autoconnect-arms into build/all-features
Reviewed-on: Blendman974/faceclaw#18
2026-11-14 20:06:31 +00:00
MasterControl a9df3de59b fix(ble): connect G2 arms with autoConnect=true
Direct connect (autoConnect=false) is supervised less patiently by Android's
BLE stack; the ring already requires autoConnect=true for this reason, and the
glasses arms showed the same short-lived direct-connect drops. Switch both
arms' beginConnect and connect to autoConnect=true.
2026-11-14 20:05:15 +00:00
Blendman974 3eb9b09e3d Hide phone UI action in EvenAnchor menu 2026-11-14 20:55:08 +01:00
James Babcock c162c8e633 Merge branch 'main' of https://github.com/jimrandomh/faceclaw 2026-11-12 12:20:29 -08:00
James Babcock cd61fefb21 Phone UI: Settings are a page instead of a tab, watch vs ring style input is a setting rather than a tab, EvenHub webview is a button with the main buttons rather than in the top bar 2026-11-12 12:16:33 -08:00
James Babcock 30de2c4dd7 Move recording setting from Developer menu to Transcribe app; add prominent indicator 2026-11-11 15:55:52 -08:00
James Babcock a02b849200 Borderless modes have different padding inside the builtin apps
Most of the builtin apps had some padding between the window edge and
their content, because they expect to be displayed with a line border on
their edge. We added a customization option to remove the border, so,
that padding is not always necessary. Make the layouts dynamically
adjust, to omit the padding when it isn't needed.
2026-11-11 15:19:29 -08:00
Blendman974 3dd307483d Merge pull request 'feat(notifications): suivre le mode Ne pas déranger du téléphone' (#17) from MasterControl/faceclaw:feat/follow-phone-dnd into build/all-features
Reviewed-on: Blendman974/faceclaw#17
2026-11-11 18:03:07 +00:00
MasterControl 9ca3574ae7 [verified] feat: follow phone Do Not Disturb for notification wake 2026-11-11 17:43:35 +00:00
James Babcock e158452ba4 Adjust styling/position of app-switcher when there's no rounded-corner border 2026-11-10 18:15:08 -08:00
Blendman974 54ba6b4f10 Merge dedicated offline French Whisper model 2026-11-10 23:22:24 +01:00
Blendman974 b4b073412f feat(voice): add dedicated offline French Whisper model 2026-11-10 23:20:31 +01:00
Blendman974 ceeadea9bf Merge pull request 'fix: masquer le fond des notifications uniquement après un réveil écran' (#16) from MasterControl/faceclaw:fix/notification-wake-backdrop into build/all-features
Reviewed-on: Blendman974/faceclaw#16
2026-11-10 20:42:42 +00:00
MasterControl a263a055d7 Merge wake-only notification backdrop correction 2026-11-10 20:33:25 +00:00
MasterControl 9ddc864b0d [verified] fix: hide notification background only on screen wake 2026-11-10 20:33:16 +00:00
Blendman974 35b02aef52 Merge pull request 'build: intégrer upstream et la lisibilité des notifications/menus' (#15) from MasterControl/faceclaw:sync/upstream-main-all-features into build/all-features
Reviewed-on: Blendman974/faceclaw#15
2026-11-10 17:36:23 +00:00
MasterControl c3d1b5f3d3 docs: record notification readability integration and validation 2026-11-10 17:34:44 +00:00
MasterControl 309f05547b Merge notification focus and selected menu-label scrolling 2026-11-10 17:31:25 +00:00
MasterControl 22df4d76d9 feat: isolate notification popups and scroll selected menu labels 2026-11-10 17:31:13 +00:00
MasterControl 6150a1ac57 Merge upstream main preserving custom feature integrations 2026-11-10 17:08:15 +00:00
James Babcock eae6cccea9 Fix a spurious unit test failure by removing unnecessary brittle tests 2026-11-09 18:56:29 -08:00
James Babcock c6ce79ab70 Add Border option to Settings>Customization 2026-11-09 18:54:23 -08:00
James Babcock 8b70585da8 Metadata updates for Play Store distribution 2026-11-09 12:08:37 -08:00
Blendman974 b4a2b2931b Merge pull request 'chore: synchroniser main avec jimrandomh/faceclaw' (#13) from MasterControl/faceclaw:sync/upstream-main into main
Reviewed-on: Blendman974/faceclaw#13
2026-11-09 06:13:40 +00:00
Blendman974 16fe517b34 docs: record detailed heart-rate integration validation 2026-11-08 01:15:40 +01:00
Blendman974 d2f846e2ba Merge detailed heart-rate collection and export
# Conflicts:
#	docs/validation-health-export.md
2026-11-08 01:14:35 +01:00
Blendman974 a575db8e27 feat: retain and export latest heart-rate measurements 2026-11-08 01:13:55 +01:00
Blendman974 86b78d45a5 Merge selectable translation output language 2026-11-08 00:56:37 +01:00
Blendman974 26e570f0e1 feat: choose translation output language independently 2026-11-08 00:56:36 +01:00
Blendman974 dbcdb1e3f6 Merge independent translation model setting 2026-11-08 00:49:11 +01:00
Blendman974 69bb92da7b feat: configure an independent OpenAI translation model 2026-11-08 00:48:54 +01:00
Blendman974 2a607b32d0 Merge configurable OpenAI transcription model 2026-11-08 00:37:07 +01:00
Blendman974 a80d6697b5 Allow choosing an OpenAI transcription model available to the project 2026-11-08 00:35:51 +01:00
Blendman974 ca05030857 Merge health API repository documentation 2026-11-07 23:43:33 +01:00
Blendman974 8d57b7c1d0 Document the separate health API repository 2026-11-07 23:43:32 +01:00
Blendman974 d01fe585bc Keep feature proposal links in one branch table 2026-11-07 23:18:40 +01:00
Blendman974 693c442faf Record health export proposals and combined validation 2026-11-07 23:18:03 +01:00
Blendman974 f0bb727a80 Add opt-in authenticated HTTPS export of R1 health history 2026-11-07 23:15:29 +01:00
Blendman974 3677a77a52 Merge optional R1 health export 2026-11-07 23:15:29 +01:00
Blendman974 1eee926cbe Merge notification display filtering 2026-11-07 21:13:02 +01:00
Blendman974 0f62573b1c Filter notification lists and status icons by source preferences 2026-11-07 21:12:40 +01:00
Blendman974 f9d3edf58c Merge silent-exit display recovery
# Conflicts:
#	docs/validation-silent-mode.md
2026-11-06 22:28:09 +01:00
Blendman974 799bdc153f fix: restore the display before silent-exit confirmation 2026-11-06 22:23:26 +01:00
Blendman974 1997258b25 Remove tilt-down hide and experimental angle measurement
# Conflicts:
#	app/g2/dashboard-controller.ts
#	app/g2/ios-preview-controller.ts
#	docs/validation-head-up.md
2026-11-06 22:21:13 +01:00
Blendman974 fe87e75fc2 Revert "feat: add shared tilt-down hide and current-angle measurement"
This reverts commit f029e3ce91.
2026-11-06 22:20:24 +01:00
Blendman974 fe0cf5b777 Merge shared tilt-down hide and angle measurement
# Conflicts:
#	app/g2/dashboard-controller.ts
#	app/g2/ios-preview-controller.ts
2026-11-06 22:10:41 +01:00
Blendman974 f029e3ce91 feat: add shared tilt-down hide and current-angle measurement 2026-11-06 22:01:21 +01:00
Blendman974 3aeed72f5d Merge silent-mode feedback
# Conflicts:
#	tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlassesSessionCoreTest.kt
2026-11-06 21:48:38 +01:00
Blendman974 02dba88131 fix: show silent-mode feedback and promptly detect exit 2026-11-06 21:48:08 +01:00
Blendman974 19944c7855 Merge temporary switcher window guard
# Conflicts:
#	app/ui/shell/shell.ts
2026-11-06 06:34:51 +01:00
Blendman974 8be15d890c fix: hide switcher move action for temporary windows 2026-11-06 06:33:47 +01:00
Blendman974 428142aef7 Merge open app switcher ordering
# Conflicts:
#	app/ui/shell/shell.ts
#	docs/validation-launcher-layout.md
2026-11-06 06:32:58 +01:00
Blendman974 c22f2e5f13 feat: reorder open app windows from the system menu 2026-11-06 06:31:29 +01:00
Blendman974 53391a310e Merge default close-app selection 2026-11-06 06:05:32 +01:00
Blendman974 cfda10d47f fix: select close current app by default in system menu 2026-11-06 06:05:31 +01:00
Blendman974 46cc5c5e5b test: validate launcher alongside all feature branches 2026-11-06 06:02:17 +01:00
Blendman974 c9151710dc Merge launcher folders and custom layout 2026-11-06 06:00:42 +01:00
Blendman974 dded80a850 feat: manage launcher folders and custom icon positions 2026-11-06 06:00:25 +01:00
Blendman974 5ae06c1818 Merge configurable menu gestures
# Conflicts:
#	app/ui/shell/shell.ts
#	tests/ai-chat.test.cjs
#	tests/brightness-picker.test.cjs
2026-11-06 04:46:29 +01:00
Blendman974 bac1c8a239 feat: allow swapping app and system menu hold gestures 2026-11-06 04:44:39 +01:00
Blendman974 883fe6bee9 docs: document independent feature PRs and combined builds 2026-11-06 04:35:20 +01:00
Blendman974 cb4635d959 Merge multilingual Whisper transcription
# Conflicts:
#	app/g2/dashboard-controller.ts
2026-11-06 04:31:25 +01:00
Blendman974 3f392712ec Merge app system menu controls 2026-11-06 04:30:15 +01:00
Blendman974 ec6fc8d40e Merge head-up wake controls 2026-11-06 04:30:15 +01:00
Blendman974 675c051461 Merge shared calendar selection 2026-11-06 04:30:15 +01:00
Blendman974 f060deaf6f Merge notification preferences and bulk actions 2026-11-06 04:30:15 +01:00
Blendman974 6f80ca75bd Merge Android 16 KiB page compatibility 2026-11-06 04:30:14 +01:00
Blendman974 acd114370b Merge Nix Android and Wear OS build environment 2026-11-06 04:30:14 +01:00
Blendman974 5929259d84 feat: configure and synchronize head-up wake and angle 2026-11-06 04:30:07 +01:00
Blendman974 55bd5f891c feat: add application close, full-screen and keep-awake controls 2026-11-06 04:26:16 +01:00
Blendman974 0b9e4cb367 feat: select languages for cloud and local Whisper transcription 2026-11-06 04:22:48 +01:00
Blendman974 1959e57d02 feat: configure notification filtering and dismiss all notifications 2026-11-06 04:21:43 +01:00
Blendman974 9e6bb8473a feat: share calendar selection across Android readers 2026-11-06 04:21:43 +01:00
Blendman974 75bceb3b92 fix: support Android 16 KiB pages in native llama library 2026-11-06 04:21:43 +01:00
Blendman974 1b2095aa5b build: add reproducible Nix Android and Wear OS environment 2026-11-06 04:21:21 +01:00
284 changed files with 11629 additions and 2600 deletions

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
watch_file devenv.nix devenv.yaml devenv.lock
eval "$(devenv direnvrc)"
use devenv
+5
View File
@@ -49,6 +49,11 @@ faceclaw_settings.xml
faceclaw_settings*.json faceclaw_settings*.json
# Developer configs # Developer configs
.devenv*
.direnv/
.android/
devenv.local.nix
local.properties
build_paths.sh build_paths.sh
**/xcuserdata/ **/xcuserdata/
+18 -4
View File
@@ -165,6 +165,14 @@ tasks.register("prepareFaceclawNativeLibs") {
def faceclawLlamaCppTag = "b10333" def faceclawLlamaCppTag = "b10333"
def faceclawFindSdkCmakeDir = { def faceclawFindSdkCmakeDir = {
// NixOS and other managed environments can provide patched host tools.
def explicitCmake = System.getenv("ANDROID_CMAKE_HOME")
if (explicitCmake != null) {
def explicitDir = file(explicitCmake)
if (faceclawHostExecutable(file("$explicitDir/bin"), "cmake").exists()
&& faceclawHostExecutable(file("$explicitDir/bin"), "ninja").exists()) return explicitDir
throw new GradleException("ANDROID_CMAKE_HOME must contain bin/cmake and bin/ninja: $explicitDir")
}
def sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT") def sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
if (sdkRoot == null) return null if (sdkRoot == null) return null
def cmakeRoot = file("$sdkRoot/cmake") def cmakeRoot = file("$sdkRoot/cmake")
@@ -264,15 +272,21 @@ if (faceclawVersionFile.exists()) {
faceclawVersionName = faceclawVersionMatch.group(1) faceclawVersionName = faceclawVersionMatch.group(1)
} }
} }
def faceclawBuildRevision = System.getenv("FACECLAW_ANDROID_BUILD_REVISION") ?: "0"
if (!(faceclawBuildRevision ==~ /[0-4]/)) {
throw new GradleException("FACECLAW_ANDROID_BUILD_REVISION must be an integer from 0 to 4")
}
def faceclawVersionCode = { def faceclawVersionCode = {
// Prerelease labels belong in versionName, not the numeric versionCode. // Prerelease labels belong in versionName, not the numeric versionCode.
def parts = (faceclawVersionName.split('-')[0].tokenize('.') + ["0", "0"]).take(3)*.toInteger() def parts = (faceclawVersionName.split('-')[0].tokenize('.') + ["0", "0"]).take(3)*.toInteger()
return parts[0] * 10000 + parts[1] * 100 + parts[2] // Last digit: build revision * 2, plus form factor (phone 0, Wear OS 1).
// Play requires distinct version codes even on separate form-factor tracks.
return (parts[0] * 10000 + parts[1] * 100 + parts[2]) * 10 + faceclawBuildRevision.toInteger() * 2
}() }()
android { android {
compileSdkVersion 35 compileSdkVersion 36
buildToolsVersion "35" buildToolsVersion "36.0.0"
// ndkVersion "" // ndkVersion ""
sourceSets.main { sourceSets.main {
@@ -282,7 +296,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 24 minSdkVersion 24
targetSdkVersion 35 targetSdkVersion 36
ndk { ndk {
// The NativeScript platform build.gradle has already added all four // The NativeScript platform build.gradle has already added all four
// ABIs by the time app.gradle is applied, and abiFilters is additive, // ABIs by the time app.gradle is applied, and abiFilters is additive,
@@ -25,18 +25,21 @@ internal object AndroidSpeechEngines {
private const val FEATURE_DIM = 80 private const val FEATURE_DIM = 80
/** Sherpa-onnx configuration for the on-device model files in [modelDir]. */ /** Sherpa-onnx configuration for the on-device model files in [modelDir]. */
fun recognizerConfig(modelDir: File, kind: VoiceModelKind): OfflineRecognizerConfig { fun recognizerConfig(
modelDir: File, kind: VoiceModelKind,
whisper: WhisperModelFiles = WhisperModelFiles.forLanguage(null),
): OfflineRecognizerConfig {
val modelConfig = OfflineModelConfig.builder() val modelConfig = OfflineModelConfig.builder()
.setNumThreads(1) .setNumThreads(1)
if (kind == VoiceModelKind.WHISPER) { if (kind == VoiceModelKind.WHISPER) {
modelConfig modelConfig
.setWhisper(OfflineWhisperModelConfig.builder() .setWhisper(OfflineWhisperModelConfig.builder()
.setEncoder(File(modelDir, "base.en-encoder.int8.onnx").absolutePath) .setEncoder(File(modelDir, whisper.encoder).absolutePath)
.setDecoder(File(modelDir, "base.en-decoder.int8.onnx").absolutePath) .setDecoder(File(modelDir, whisper.decoder).absolutePath)
.setLanguage("en") .setLanguage(whisper.language)
.setTask("transcribe") .setTask("transcribe")
.build()) .build())
.setTokens(File(modelDir, "base.en-tokens.txt").absolutePath) .setTokens(File(modelDir, whisper.tokens).absolutePath)
} else { } else {
modelConfig modelConfig
.setMoonshine(OfflineMoonshineModelConfig.builder() .setMoonshine(OfflineMoonshineModelConfig.builder()
@@ -274,6 +274,8 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState() fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState()
fun configureHeadUpWake(enabled: Int, angle: Int) = core.configureHeadUpWake(enabled, angle)
fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean = fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean =
core.startBandwidthBenchmark(messageSize, windowSize, durationMs) core.startBandwidthBenchmark(messageSize, windowSize, durationMs)
@@ -231,17 +231,16 @@ class FaceclawBleManager(context: Context) {
fun connect(address: String?, timeoutMs: Int): Boolean = connect(address, timeoutMs, false) fun connect(address: String?, timeoutMs: Int): Boolean = connect(address, timeoutMs, false)
/** /**
* EXPERIMENTAL (2026-09-11): the ring specifically needs autoConnect=true. * autoConnect=true is used for the ring and both glasses arms. The ring specifically
* Even's own vendor app connects the ring with Android's autoConnect flag * needs it (Even's own vendor app connects the ring with Android's autoConnect flag
* set (confirmed via its own BLE debug log, "connect() - device: ..., * set, confirmed via its own BLE debug log, "connect() - device: ...,
* auto: true"), while every other faceclaw connection (both glasses arms) * auto: true"). A live test showed a ring-only direct connection dying almost
* uses autoConnect=false. Direct connect (false) is faster to establish * exactly 5 seconds in, repeatedly, with nothing else competing for it, and the
* but Android supervises it less patiently; a live test showed the * glasses arms showed the same "less patiently supervised" direct-connect drop.
* ring-only direct connection dying almost exactly 5 seconds in, * Direct connect (false) is faster to establish but Android supervises it less
* repeatedly, with nothing else competing for it. autoConnect=true can * patiently. autoConnect=true can take much longer to actually complete (Android
* take much longer to actually complete (Android manages it as a * manages it as a background reconnect, not an immediate attempt), so it needs its
* background reconnect, not an immediate attempt), so this needs its own * own longer timeout. Like [connect], waits on an attempt already pending.
* longer timeout. Like [connect], waits on an attempt already pending.
*/ */
fun connect(address: String?, timeoutMs: Int, autoConnect: Boolean): Boolean { fun connect(address: String?, timeoutMs: Int, autoConnect: Boolean): Boolean {
val key = requireAddress(address) val key = requireAddress(address)
@@ -54,7 +54,8 @@ class FaceclawCalendarProvider private constructor() {
* boundaries the provider stores them as. * boundaries the provider stores them as.
*/ */
@JvmStatic @JvmStatic
fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long): String { @JvmOverloads
fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long, selectedCalendarIdsJson: String = "null"): String {
if (context == null || maxEvents <= 0) { if (context == null || maxEvents <= 0) {
return "[]" return "[]"
} }
@@ -73,11 +74,21 @@ class FaceclawCalendarProvider private constructor() {
val events = ArrayList<Event>() val events = ArrayList<Event>()
var cursor: Cursor? = null var cursor: Cursor? = null
try { try {
// Filter instances before the cutoff/limit so excluded calendars
// cannot crowd out selected calendars, including recurrences.
val ids = if (selectedCalendarIdsJson == "null") null else JSONArray(selectedCalendarIdsJson)
if (ids != null && ids.length() == 0) return "[]"
val args = ids?.let { values -> Array(values.length()) { index ->
values.getString(index).also { require(it.matches(Regex("[0-9]+"))) }
} }
val selection = args?.let {
CalendarContract.Instances.CALENDAR_ID + " IN (" + it.joinToString(",") { "?" } + ")"
}
cursor = context.contentResolver.query( cursor = context.contentResolver.query(
uri, uri,
PROJECTION, PROJECTION,
null, selection,
null, args,
CalendarContract.Instances.BEGIN + " ASC") CalendarContract.Instances.BEGIN + " ASC")
if (cursor != null) { if (cursor != null) {
val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC")) val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
@@ -118,6 +129,33 @@ class FaceclawCalendarProvider private constructor() {
return out.toString() return out.toString()
} }
@JvmStatic
fun getCalendarsJson(context: Context?): String {
if (context == null) return "[]"
val out = JSONArray()
try {
context.contentResolver.query(
CalendarContract.Calendars.CONTENT_URI,
arrayOf(CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
CalendarContract.Calendars.ACCOUNT_NAME, CalendarContract.Calendars.ACCOUNT_TYPE),
null, null, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME + " ASC",
)?.use { cursor ->
while (cursor.moveToNext()) {
out.put(JSONObject().apply {
put("id", cursor.getLong(0).toString())
put("name", cursor.getString(1) ?: "")
put("accountName", cursor.getString(2) ?: "")
put("accountType", cursor.getString(3) ?: "")
})
}
}
} catch (t: Throwable) {
Log.w(TAG, "failed to read calendars", t)
return "[]"
}
return out.toString()
}
private fun readEvent(cursor: Cursor, utc: Calendar, local: Calendar): Event { private fun readEvent(cursor: Cursor, utc: Calendar, local: Calendar): Event {
val allDay = cursor.getInt(4) != 0 val allDay = cursor.getInt(4) != 0
var startMs = cursor.getLong(2) var startMs = cursor.getLong(2)
@@ -0,0 +1,47 @@
package com.faceclaw.app
import android.content.Context
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import android.util.AtomicFile
import java.io.File
import java.security.KeyStore
import javax.crypto.Cipher
import javax.crypto.KeyGenerator
import javax.crypto.SecretKey
import javax.crypto.spec.GCMParameterSpec
/** This credential cannot be restored onto a device lacking its Keystore key. */
object FaceclawHealthExportSecret {
private const val ALIAS = "faceclaw.health.export"
private fun file(context: Context) = AtomicFile(File(context.noBackupFilesDir, "health-export-key"))
private fun key(): SecretKey {
val store = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }
(store.getKey(ALIAS, null) as? SecretKey)?.let { return it }
return KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore").apply {
init(KeyGenParameterSpec.Builder(ALIAS, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE).build())
}.generateKey()
}
@JvmStatic @Synchronized fun read(context: Context): String {
val held = file(context)
if (!held.baseFile.exists()) return ""
return try {
val bytes = held.readFully()
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.DECRYPT_MODE, key(), GCMParameterSpec(128, bytes.copyOfRange(0, 12)))
String(cipher.doFinal(bytes.copyOfRange(12, bytes.size)), Charsets.UTF_8)
} catch (_: Exception) { "" } // Require re-entry after key loss; never log the credential.
}
@JvmStatic @Synchronized fun write(context: Context, value: String) {
val held = file(context)
if (value.isEmpty()) { held.delete(); return }
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.ENCRYPT_MODE, key())
val bytes = cipher.iv + cipher.doFinal(value.toByteArray(Charsets.UTF_8))
val stream = held.startWrite()
try { stream.write(bytes); held.finishWrite(stream) }
catch (error: Exception) { held.failWrite(stream); throw error }
}
}
@@ -125,6 +125,27 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
return "connecting" return "connecting"
} }
/** Fresh, read-only phone DND state; unavailable filters retain normal wake behavior. */
@JvmStatic
fun isPhoneDoNotDisturbEnabled(context: Context?): Boolean {
val filter = try {
val manager = context?.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
manager?.currentInterruptionFilter
} catch (t: Throwable) {
null
} ?: try {
activeService?.currentInterruptionFilter
} catch (t: Throwable) {
null
}
return when (filter) {
NotificationManager.INTERRUPTION_FILTER_PRIORITY,
NotificationManager.INTERRUPTION_FILTER_NONE,
NotificationManager.INTERRUPTION_FILTER_ALARMS -> true
else -> false
}
}
/** Run on the main thread whenever getListenerState may have changed. */ /** Run on the main thread whenever getListenerState may have changed. */
@JvmStatic @JvmStatic
fun addListenerStateObserver(observer: Runnable?) { fun addListenerStateObserver(observer: Runnable?) {
@@ -504,8 +525,22 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
} }
} }
@JvmStatic
fun dismissAllNotifications(): Boolean {
val service = activeService ?: return false
return try {
service.cancelAllNotifications()
true
} catch (t: Throwable) {
Log.w(TAG, "failed to dismiss all notifications", t)
false
}
}
private fun emitNotificationPosted(key: String?) { private fun emitNotificationPosted(key: String?) {
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey) } // Capture before mainHandler posting: a later DND change must not alter this arrival.
val canWakeScreen = !isPhoneDoNotDisturbEnabled(activeService)
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey, canWakeScreen) }
} }
private fun emitNotificationRemoved(key: String?) { private fun emitNotificationRemoved(key: String?) {
@@ -32,17 +32,6 @@ class FaceclawVoiceController(context: Context) {
"decoder_model_merged.ort", "decoder_model_merged.ort",
"tokens.txt" "tokens.txt"
) )
// Second on-device model: sherpa-onnx's offline Whisper backend (base.en,
// int8-quantized -- see the model-choice note in asr-model.ts). Directory
// shared with the TS-side download flow, same convention as ASR_MODEL_DIR.
// Whisper re-encodes the whole buffer on every call, so the shared session
// skips live partials for it; see VoiceCaptureSession.processRecognizer.
private const val ASR_WHISPER_MODEL_DIR = "sherpa-onnx-whisper-base-en-int8"
private val ASR_WHISPER_MODEL_FILES = arrayOf(
"base.en-encoder.int8.onnx",
"base.en-decoder.int8.onnx",
"base.en-tokens.txt"
)
// 50 ms chunks match the G2 packet cadence the rest of the pipeline // 50 ms chunks match the G2 packet cadence the rest of the pipeline
// (endpointing, transcript pacing) is tuned for. // (endpointing, transcript pacing) is tuned for.
private const val PHONE_MIC_CHUNK_SAMPLES = SAMPLE_RATE / 20 private const val PHONE_MIC_CHUNK_SAMPLES = SAMPLE_RATE / 20
@@ -84,6 +73,8 @@ class FaceclawVoiceController(context: Context) {
private val mainHandler = Handler(Looper.getMainLooper()) private val mainHandler = Handler(Looper.getMainLooper())
@Volatile @Volatile
private var communicator: FaceclawBleCommunicator? = null private var communicator: FaceclawBleCommunicator? = null
private var whisperModel = WhisperModelFiles.forLanguage(null)
private var frenchWhisper = false
private val host = object : VoiceCaptureHost { private val host = object : VoiceCaptureHost {
override val dispatcher = CallbackDispatcher { action -> mainHandler.post { action() } } override val dispatcher = CallbackDispatcher { action -> mainHandler.post { action() } }
@@ -124,7 +115,7 @@ class FaceclawVoiceController(context: Context) {
override fun loadTranscriber(kind: VoiceModelKind): OfflineTranscriber { override fun loadTranscriber(kind: VoiceModelKind): OfflineTranscriber {
val modelDir = findAsrModelDir(kind) ?: throw IllegalStateException("voice model missing") val modelDir = findAsrModelDir(kind) ?: throw IllegalStateException("voice model missing")
return AndroidSpeechEngines.SherpaTranscriber(AndroidSpeechEngines.recognizerConfig(modelDir, kind)) return AndroidSpeechEngines.SherpaTranscriber(AndroidSpeechEngines.recognizerConfig(modelDir, kind, whisperModel))
} }
override fun speakerEmbedder(modelPath: String): SpeakerEmbedder { override fun speakerEmbedder(modelPath: String): SpeakerEmbedder {
@@ -136,8 +127,6 @@ class FaceclawVoiceController(context: Context) {
override fun release() {} override fun release() {}
} }
} }
override fun recordingSink(): RecordingSink = RecordingSink { pcmBytes, sampleRate -> saveRecording(pcmBytes, sampleRate) }
} }
private val session = VoiceCaptureSession(host) private val session = VoiceCaptureSession(host)
@@ -155,11 +144,6 @@ class FaceclawVoiceController(context: Context) {
session.setUsePhoneMic(usePhoneMic) session.setUsePhoneMic(usePhoneMic)
} }
/** When true, the decoded mic PCM for each session is saved as a WAV. */
fun setSaveRecordings(saveRecordings: Boolean) {
session.setSaveRecordings(saveRecordings)
}
/** /**
* Which on-device model {@link #start}("onboard") should load: "whisper" * Which on-device model {@link #start}("onboard") should load: "whisper"
* selects the second on-device model (sherpa-onnx offline Whisper); any * selects the second on-device model (sherpa-onnx offline Whisper); any
@@ -170,6 +154,17 @@ class FaceclawVoiceController(context: Context) {
session.setOnboardModelKind(kind) session.setOnboardModelKind(kind)
} }
/** Select the dedicated French fine-tune before setting the capture language. */
fun setFrenchWhisper(enabled: Boolean) {
frenchWhisper = enabled
whisperModel = WhisperModelFiles.forSelection(whisperModel.language, enabled)
}
/** Language for the next on-device Whisper capture; empty enables auto-detection. */
fun setOnboardLanguage(language: String?) {
whisperModel = WhisperModelFiles.forSelection(language, frenchWhisper)
}
/** /**
* When true, watch the decoded PCM and fire {@code onSpeechEnd} once the * When true, watch the decoded PCM and fire {@code onSpeechEnd} once the
* speaker stops. Used by hands-free ("Hey Even") capture, which has no * speaker stops. Used by hands-free ("Hey Even") capture, which has no
@@ -233,29 +228,6 @@ class FaceclawVoiceController(context: Context) {
stop() stop()
} }
/** Save the session's decoded mic PCM as a 16 kHz mono 16-bit WAV. */
private fun saveRecording(pcmBytes: ByteArray, sampleRate: Int) {
try {
val dir = File(appContext.getExternalFilesDir(null), "voice-recordings")
if (!dir.exists() && !dir.mkdirs()) {
Log.w(TAG, "could not create voice-recordings dir")
return
}
val stamp = java.text.SimpleDateFormat("yyyyMMdd-HHmmss-SSS", java.util.Locale.US)
.format(java.util.Date())
val file = File(dir, "voice-$stamp.wav")
java.io.FileOutputStream(file).use { fos ->
fos.write(BinaryEncoding.wavHeader(pcmBytes.size, sampleRate, 1))
fos.write(pcmBytes)
}
Log.i(TAG, "saved voice recording " + file.absolutePath
+ " samples=" + (pcmBytes.size / 2)
+ " sec=" + String.format(java.util.Locale.US, "%.2f", pcmBytes.size / 2.0 / sampleRate))
} catch (t: Throwable) {
Log.w(TAG, "failed to save voice recording", t)
}
}
/** /**
* The on-device model directory for the given kind, populated by the * The on-device model directory for the given kind, populated by the
* download flow in asr-model.ts (releases before 0.5.0 copied the * download flow in asr-model.ts (releases before 0.5.0 copied the
@@ -265,8 +237,8 @@ class FaceclawVoiceController(context: Context) {
*/ */
private fun findAsrModelDir(kind: VoiceModelKind): File? { private fun findAsrModelDir(kind: VoiceModelKind): File? {
val whisper = kind == VoiceModelKind.WHISPER val whisper = kind == VoiceModelKind.WHISPER
val dirName = if (whisper) ASR_WHISPER_MODEL_DIR else ASR_MODEL_DIR val dirName = if (whisper) whisperModel.dirName else ASR_MODEL_DIR
val fileNames = if (whisper) ASR_WHISPER_MODEL_FILES else ASR_MODEL_FILES val fileNames = if (whisper) whisperModel.files else ASR_MODEL_FILES.toList()
val modelDir = File(appContext.filesDir, ASR_ROOT + File.separator + dirName) val modelDir = File(appContext.filesDir, ASR_ROOT + File.separator + dirName)
for (fileName in fileNames) { for (fileName in fileNames) {
val file = File(modelDir, fileName) val file = File(modelDir, fileName)
@@ -62,7 +62,7 @@ class PreviewBitmapUtil private constructor() {
/** /**
* A white-on-transparent bitmap of an 8bpp glasses icon (gray becomes * A white-on-transparent bitmap of an 8bpp glasses icon (gray becomes
* alpha; black, which the glasses show as unlit, is transparent), for * alpha; black, which the glasses show as unlit, is transparent), for
* showing glasses artwork on the phone's dark action bar. * showing glasses artwork in the phone UI, which tints it to suit.
*/ */
@JvmStatic @JvmStatic
fun whiteIconFromGray(gray: ByteBuffer?, width: Int, height: Int): Bitmap { fun whiteIconFromGray(gray: ByteBuffer?, width: Int, height: Int): Bitmap {
@@ -29,3 +29,8 @@ add_subdirectory(${LLAMA_CPP_SOURCE_DIR} llama.cpp-build EXCLUDE_FROM_ALL)
add_library(faceclaw_llama SHARED faceclaw_llama.cpp) add_library(faceclaw_llama SHARED faceclaw_llama.cpp)
target_link_libraries(faceclaw_llama PRIVATE llama android log) target_link_libraries(faceclaw_llama PRIVATE llama android log)
# NDK r27 defaults to 4 KiB. Align both LOAD segments and RELRO boundaries
# for Android devices using 16 KiB pages, including debug APKs.
target_link_options(faceclaw_llama PRIVATE
"-Wl,-z,max-page-size=16384"
"-Wl,-z,common-page-size=16384")
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Keyboard icon for the main page's tab-bar keyboard-dialog button (beside <!-- Keyboard icon for the main page's keyboard-dialog button (beside the mic
the mic button). Material Design "keyboard" glyph (Apache 2.0); base fill button). Material Design "keyboard" glyph (Apache 2.0); base fill is
is overridden by tint-color in app.css. --> overridden by tint-color in remote-controls.css. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Microphone icon for the main page's tab-bar wakeword button. <!-- Microphone icon for the main page's voice-input (wakeword) button.
Converted from ~/Downloads/noun-microphone-1368757.svg (Noun Project Converted from ~/Downloads/noun-microphone-1368757.svg (Noun Project
icon #1368757); base fill is overridden by tint-color in app.css. --> icon #1368757); base fill is overridden by tint-color in remote-controls.css. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Gear icon for the main page's Settings button (beside the mic and keyboard
buttons). Material Design "settings" glyph (Apache 2.0); base fill is
overridden by tint-color in remote-controls.css. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF333333"
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z" />
</vector>
@@ -2,7 +2,7 @@
"images": [ "images": [
{ {
"idiom": "universal", "idiom": "universal",
"filename": "ic_tab_keyboard@3x.png", "filename": "ic_control_keyboard@3x.png",
"scale": "3x" "scale": "3x"
} }
], ],
File renamed without changes.

Before

Width:  |  Height:  |  Size: 590 B

After

Width:  |  Height:  |  Size: 590 B

@@ -2,7 +2,7 @@
"images": [ "images": [
{ {
"idiom": "universal", "idiom": "universal",
"filename": "ic_tab_mic@3x.png", "filename": "ic_control_mic@3x.png",
"scale": "3x" "scale": "3x"
} }
], ],
File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -0,0 +1,13 @@
{
"images": [
{
"idiom": "universal",
"filename": "ic_control_settings@3x.png",
"scale": "3x"
}
],
"info": {
"author": "xcode",
"version": 1
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

+25 -1
View File
@@ -5,6 +5,8 @@ collects and shares information when you use an iOS TestFlight build, even
when Faceclaw statistics are set to None. Information you voluntarily send when Faceclaw statistics are set to None. Information you voluntarily send
us, such as feedback, may also identify you. This policy describes these us, such as feedback, may also identify you. This policy describes these
separate channels and the third-party services you can choose to use. separate channels and the third-party services you can choose to use.
On Android, Google ML Kit also collects SDK diagnostics separately from
Faceclaw statistics, as described below.
## Usage Statistics ## Usage Statistics
@@ -16,7 +18,8 @@ your choice at any time in Settings > Privacy > Faceclaw statistics. Until
you choose, it is None. This setting controls only Faceclaw's own statistics. you choose, it is None. This setting controls only Faceclaw's own statistics.
With None, Faceclaw sends and stores none of its own usage statistics. This With None, Faceclaw sends and stores none of its own usage statistics. This
does not disable Apple's TestFlight reports or services you choose to use. does not disable Apple's TestFlight reports, Google ML Kit diagnostics, or
services you choose to use.
With Minimal, Faceclaw keeps counts on your phone and sends them about once a With Minimal, Faceclaw keeps counts on your phone and sends them about once a
day to stats.faceclaw.org, a server run by Faceclaw's developers: day to stats.faceclaw.org, a server run by Faceclaw's developers:
@@ -48,6 +51,27 @@ phone, and stops all reports; turning them back on starts a new identifier.
The statistics server doesn't record the IP addresses reports come from. The statistics server doesn't record the IP addresses reports come from.
## Android and Google ML Kit
Android translation and language identification use Google ML Kit. The
developer QR-code scanner uses Google's code scanner. Text and scanner
images are processed on-device, but the SDKs send Google diagnostic and
usage metrics over HTTPS: device/app details, installation identifiers,
timings, errors, feature events, input/output sizes, and detected or
configured languages. Translation also uses Firebase installation and
remote-configuration services. This reporting is separate from the
Faceclaw statistics setting; selecting None does not turn it off. Faceclaw
does not provide a switch to disable these SDK diagnostics.
These metrics do not include the text being translated or scanned images.
Cloud transcription and assistant providers are separate, as described below.
For Google's handling of SDK metrics, see:
https://developers.google.com/ml-kit/android-data-disclosure
https://developers.google.com/ml-kit/terms
https://policies.google.com/privacy
## iOS and TestFlight ## iOS and TestFlight
For TestFlight builds, Apple automatically collects crash reports and beta For TestFlight builds, Apple automatically collects crash reports and beta
+1 -1
View File
@@ -39,7 +39,7 @@ The instructions below build the Android app.
If you want to customize faceclaw, the best way to do it is to download the If you want to customize faceclaw, the best way to do it is to download the
source code and using a coding agent such as Codex or Claude Code. source code and using a coding agent such as Codex or Claude Code.
To compile, you will need an Android SDK environment with SDK version 35 To compile, you will need an Android SDK environment with SDK version 36
installed and licenses accepted, and the ANDROID_HOME pointing to the install. installed and licenses accepted, and the ANDROID_HOME pointing to the install.
You will need Nativescript installed, and a JDK environment (v21), with the You will need Nativescript installed, and a JDK environment (v21), with the
JAVA_HOME environment variable pointed at it. You will also need a reasonably JAVA_HOME environment variable pointed at it. You will also need a reasonably
+3
View File
@@ -4,3 +4,6 @@
*/ */
export const IOS_PRIVACY_SUMMARY = export const IOS_PRIVACY_SUMMARY =
"With TestFlight, crash/usage reports continue even with None. See Privacy policy for details."; "With TestFlight, crash/usage reports continue even with None. See Privacy policy for details.";
export const ANDROID_PRIVACY_SUMMARY =
"Google ML Kit diagnostics for translation and QR scanning are separate from this setting. See Privacy policy for details.";
+3 -13
View File
@@ -1,6 +1,7 @@
@import '@nativescript/theme/css/core.css'; @import '@nativescript/theme/css/core.css';
@import '@nativescript/theme/css/default.css'; @import '@nativescript/theme/css/default.css';
@import './phone-ui/remote-controls.css'; @import './phone-ui/remote-controls.css';
@import './phone-ui/settings-page.css';
@import './phone-ui/pairing.css'; @import './phone-ui/pairing.css';
Page { Page {
@@ -17,9 +18,8 @@ ActionItem {
color: #ffffff; color: #ffffff;
} }
/* The main page's custom titleView: title left; the EvenHub app icon, /* The main page's custom titleView: title left; connection status and the
* connection status and the warning triangle right-aligned beside the * warning triangle right-aligned beside the overflow menu. */
* overflow menu. */
.action-bar-title { .action-bar-title {
color: #ffffff; color: #ffffff;
font-size: 18; font-size: 18;
@@ -34,16 +34,6 @@ ActionItem {
vertical-align: center; vertical-align: center;
} }
/* The foreground EvenHub app's icon (opens its phone UI); the padding widens
* the tap target. */
.action-bar-app-icon {
width: 32;
height: 32;
padding: 5.5;
margin-right: 8;
vertical-align: center;
}
/* The emoji brings its own yellow; the padding widens the tap target. */ /* The emoji brings its own yellow; the padding widens the tap target. */
.action-bar-warning { .action-bar-warning {
font-size: 18; font-size: 18;
+1 -5
View File
@@ -1,5 +1,6 @@
@import '@nativescript/theme/css/core.css'; @import '@nativescript/theme/css/core.css';
@import './phone-ui/remote-controls.css'; @import './phone-ui/remote-controls.css';
@import './phone-ui/settings-page.css';
@import './phone-ui/pairing.css'; @import './phone-ui/pairing.css';
.body-text { font-size: 18; } .body-text { font-size: 18; }
@@ -36,8 +37,6 @@ Page.main-page {
.main-page .action-bar-title { font-size: 18; font-weight: bold; color: #ffffff; } .main-page .action-bar-title { font-size: 18; font-weight: bold; color: #ffffff; }
.main-page .action-bar-status { font-size: 14; color: #ffffff; margin-right: 12; } .main-page .action-bar-status { font-size: 14; color: #ffffff; margin-right: 12; }
.main-page .action-bar-warning { font-size: 18; padding: 4 6; } .main-page .action-bar-warning { font-size: 18; padding: 4 6; }
/* Matches Android's 32x32 padded icon; the Image inside is 21x21. */
.main-page .action-bar-app-icon { width: 32; height: 32; margin-right: 8; }
.main-page .overflow-button { .main-page .overflow-button {
background-color: transparent; background-color: transparent;
color: #ffffff; color: #ffffff;
@@ -47,9 +46,6 @@ Page.main-page {
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
/* Match Android's button layout boxes, including the inset around each tile. */
.main-page Button.tab-button { height: 48; margin-top: 6; margin-bottom: 6; }
.main-page .mode-button { background-color: #e2e2e2; color: #333333; border-radius: 6; }
.main-page .ble-bandwidth-indicator { color: #777777; font-size: 12; padding: 2 8; } .main-page .ble-bandwidth-indicator { color: #777777; font-size: 12; padding: 2 8; }
.main-page .system-name-modal { .main-page .system-name-modal {
+16 -6
View File
@@ -13,6 +13,10 @@ import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow }
import { shell } from "../../ui/shell/shell"; import { shell } from "../../ui/shell/shell";
import { VoiceDraft } from "./voice-draft"; import { VoiceDraft } from "./voice-draft";
/** The transcript's scrollbar, hugging the window's right padding, and the gap the text keeps from it. */
const SCROLLBAR_WIDTH = 2;
const SCROLLBAR_GAP = 11;
class AiChatLayer implements Layer { class AiChatLayer implements Layer {
readonly acceptsDirectional = true; readonly acceptsDirectional = true;
private firstLine: number | null = null; // null follows the streaming tail private firstLine: number | null = null; // null follows the streaming tail
@@ -38,24 +42,30 @@ class AiChatLayer implements Layer {
} }
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const size = ctx.stack.getBaseSize(); const size = ctx.stack.getBaseSize();
const { padding } = size;
const image = new GrayImage(size.width, size.height); const image = new GrayImage(size.width, size.height);
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const step = font.lineHeight + 3; const step = font.lineHeight + 3;
const left = 12; // The title, and the footer under the transcript, stay put inside the
const width = size.width - 28; // padding suggested for the window's edges; the transcript scrolls
// between them. Text runs from the left padding to the gutter kept for
// the scrollbar.
const left = padding.left;
const scrollbarX = size.width - padding.right - SCROLLBAR_WIDTH;
const width = Math.max(0, scrollbarX - SCROLLBAR_GAP - left);
const record = this.conversations.current(); const record = this.conversations.current();
if (this.selectedId !== record.id) { this.selectedId = record.id; this.firstLine = null; } if (this.selectedId !== record.id) { this.selectedId = record.id; this.firstLine = null; }
const transcript = record.session?.transcript ?? record.history?.transcript ?? []; const transcript = record.session?.transcript ?? record.history?.transcript ?? [];
const title = this.conversations.title(); const title = this.conversations.title();
image.drawText(font, left, 6, truncateText(font, title, width), 180); image.drawText(font, left, padding.top, truncateText(font, title, width), 180);
const label = assistantBackendSetting.get() === "external" ? "External agent" : const label = assistantBackendSetting.get() === "external" ? "External agent" :
`${assistantModelLabel(record.model)} · ${record.reasoning === "default" ? "default reasoning" : record.reasoning}`; `${assistantModelLabel(record.model)} · ${record.reasoning === "default" ? "default reasoning" : record.reasoning}`;
const footer = wrapText(font, `${label} ${gestureHints([ const footer = wrapText(font, `${label} ${gestureHints([
[GESTURE_CLICK, "menu"], [GESTURE_DOUBLE_CLICK, "back"], [GESTURE_LONG_PRESS, "hold to talk"], [GESTURE_CLICK, "menu"], [GESTURE_DOUBLE_CLICK, "back"], [GESTURE_LONG_PRESS, "hold to talk"],
])}`, width); ])}`, width);
const footerY = size.height - step * footer.length; const footerY = size.height - padding.bottom - font.lineHeight - step * (footer.length - 1);
const footerTop = footerY - step * 3 - 12; const footerTop = footerY - step * 3 - 12;
const historyTop = step + 16; const historyTop = padding.top + step + 10;
const visible = Math.max(1, Math.floor((footerTop - historyTop - 8) / step)); const visible = Math.max(1, Math.floor((footerTop - historyTop - 8) / step));
const lines: { text: string; color: number }[] = []; const lines: { text: string; color: number }[] = [];
for (const entry of transcript) { for (const entry of transcript) {
@@ -82,7 +92,7 @@ class AiChatLayer implements Layer {
if (this.maxFirstLine > 0) { if (this.maxFirstLine > 0) {
const track = visible * step; const track = visible * step;
const thumb = Math.max(8, Math.floor(track * visible / lines.length)); const thumb = Math.max(8, Math.floor(track * visible / lines.length));
image.fillRect(size.width - 5, historyTop + Math.floor((track - thumb) * first / this.maxFirstLine), 2, thumb, 110); image.fillRect(scrollbarX, historyTop + Math.floor((track - thumb) * first / this.maxFirstLine), SCROLLBAR_WIDTH, thumb, 110);
} }
image.fillRect(left, footerTop, width, 1, 65); image.fillRect(left, footerTop, width, 1, 65);
const state = this.draft.active ? this.draft.status : record.session?.status || this.draft.status; const state = this.draft.active ? this.draft.status : record.session?.status || this.draft.status;
+12 -2
View File
@@ -25,6 +25,7 @@ import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting";
import { type MenuItem } from "../../ui/menu"; import { type MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { Viewport } from "../../ui/viewport";
import { import {
directionalFallback, directionalFallback,
GESTURE_CLICK, GESTURE_CLICK,
@@ -155,6 +156,13 @@ type BlocksWindow = {
title: string; title: string;
viewportWidth: number; viewportWidth: number;
viewportHeight: number; viewportHeight: number;
/**
* The viewport as the shell last sent it: besides the size above, what each
* edge touches and the padding suggested there. The window menu's layers
* lay out by it; the game's own layout is fixed art that keeps its place
* (see LAYOUT_HEIGHT).
*/
viewport: Viewport;
foreground: boolean; foreground: boolean;
/** Whether this window is the shell's input target (pushed with each message). */ /** Whether this window is the shell's input target (pushed with each message). */
focused: boolean; focused: boolean;
@@ -207,6 +215,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
title: message.title, title: message.title,
viewportWidth: message.viewport.width, viewportWidth: message.viewport.width,
viewportHeight: message.viewport.height, viewportHeight: message.viewport.height,
viewport: message.viewport,
foreground: false, foreground: false,
focused: false, focused: false,
menu: null, menu: null,
@@ -295,7 +304,8 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
if (!window) break; if (!window) break;
window.viewportWidth = message.viewport.width; window.viewportWidth = message.viewport.width;
window.viewportHeight = message.viewport.height; window.viewportHeight = message.viewport.height;
window.menu?.resize({ width: window.viewportWidth, height: window.viewportHeight }); window.viewport = message.viewport;
window.menu?.resize(message.viewport);
window.lastSubmittedFingerprint = ""; window.lastSubmittedFingerprint = "";
if (window.foreground) renderAndSubmit(window, 0); if (window.foreground) renderAndSubmit(window, 0);
break; break;
@@ -357,7 +367,7 @@ function windowMenu(window: BlocksWindow): WindowMenu {
title: () => window.title, title: () => window.title,
items: () => (window.phase === "playing" ? [] : windowMenuItems(window)), items: () => (window.phase === "playing" ? [] : windowMenuItems(window)),
claimsLongPress: () => window.phase === "playing", claimsLongPress: () => window.phase === "playing",
size: { width: window.viewportWidth, height: window.viewportHeight }, size: window.viewport,
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
}); });
+7 -5
View File
@@ -35,25 +35,27 @@ export function drawGraph(
const clampX = (x: number): number => Math.max(rect.x, Math.min(rect.x + rect.width - 1, x)); const clampX = (x: number): number => Math.max(rect.x, Math.min(rect.x + rect.width - 1, x));
const clampY = (y: number): number => Math.max(rect.y, Math.min(rect.y + rect.height - 1, y)); const clampY = (y: number): number => Math.max(rect.y, Math.min(rect.y + rect.height - 1, y));
// Tick grid first so the curve and axes draw over it. // Tick grid first so the curve and axes draw over it. A tick or axis at
// the viewport's far limit lands on the frame's last column or row, not
// past it: the caller may have run the rect to the window's edge.
for (const tick of graph.xAxis.ticks) { for (const tick of graph.xAxis.ticks) {
if (tick < viewport.xMin || tick > viewport.xMax) continue; if (tick < viewport.xMin || tick > viewport.xMax) continue;
const x = Math.round(px(tick)); const x = Math.round(clampX(px(tick)));
image.drawLine(x, rect.y, x, rect.y + rect.height - 1, GRID_VALUE); image.drawLine(x, rect.y, x, rect.y + rect.height - 1, GRID_VALUE);
} }
for (const tick of graph.yAxis.ticks) { for (const tick of graph.yAxis.ticks) {
if (tick < viewport.yMin || tick > viewport.yMax) continue; if (tick < viewport.yMin || tick > viewport.yMax) continue;
const y = Math.round(py(tick)); const y = Math.round(clampY(py(tick)));
image.drawLine(rect.x, y, rect.x + rect.width - 1, y, GRID_VALUE); image.drawLine(rect.x, y, rect.x + rect.width - 1, y, GRID_VALUE);
} }
// Axes. // Axes.
if (viewport.yMin <= 0 && viewport.yMax >= 0) { if (viewport.yMin <= 0 && viewport.yMax >= 0) {
const y = Math.round(py(0)); const y = Math.round(clampY(py(0)));
image.drawLine(rect.x, y, rect.x + rect.width - 1, y, AXIS_VALUE); image.drawLine(rect.x, y, rect.x + rect.width - 1, y, AXIS_VALUE);
} }
if (viewport.xMin <= 0 && viewport.xMax >= 0) { if (viewport.xMin <= 0 && viewport.xMax >= 0) {
const x = Math.round(px(0)); const x = Math.round(clampX(px(0)));
image.drawLine(x, rect.y, x, rect.y + rect.height - 1, AXIS_VALUE); image.drawLine(x, rect.y, x, rect.y + rect.height - 1, AXIS_VALUE);
} }
+76 -51
View File
@@ -62,6 +62,24 @@ export const calculatorDegreesSetting = new ConfigSettingBoolean({
const CONTINUOUS_CLIENT = "calculator"; const CONTINUOUS_CLIENT = "calculator";
const DICTATION_HOLDER = "calculator-dictation"; const DICTATION_HOLDER = "calculator-dictation";
// ---------------------------------------------------------------------------
// Layout
/**
* The column the view is laid out in: the window's width inside the padding
* suggested for its side edges (viewport.ts). Tabs, text, the plot and the
* footer all start at its left; centred text is centred in it.
*/
type Column = { x: number; width: number };
/** Below the tabs' text top: their underline, and where the body starts. */
const TAB_UNDERLINE_OFFSET = 20;
const BODY_TOP_OFFSET = 31;
/** Indent, on both sides, of wrapped body text (a failure's reason, a step's detail, an answer). */
const BODY_INDENT = 8;
/** The same for the prompt of an empty view, which keeps well clear of the sides. */
const PROMPT_INDENT = 24;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Layer // Layer
@@ -380,14 +398,17 @@ export class CalculatorLayer implements Layer {
// Paint // Paint
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const small = getDefaultSmallFont(); const small = getDefaultSmallFont();
const column: Column = { x: padding.left, width: Math.max(0, width - padding.left - padding.right) };
this.paintTabs(image, small, width); // The tabs sit at the top edge's padding and the footer at the bottom's;
// the body is what lies between.
this.paintTabs(image, small, column, padding.top);
const footerY = height - small.lineHeight - 6; const footerY = height - padding.bottom - small.lineHeight;
const bodyTop = 46; const bodyTop = padding.top + BODY_TOP_OFFSET;
let bodyBottom = footerY - 4; let bodyBottom = footerY - 4;
// A standing offer or a running deep pass takes the rows just above the // A standing offer or a running deep pass takes the rows just above the
@@ -395,35 +416,36 @@ export class CalculatorLayer implements Layer {
const offer = this.coordinator.pendingLongRun; const offer = this.coordinator.pendingLongRun;
const progress = this.coordinator.longRunProgress; const progress = this.coordinator.longRunProgress;
if (offer || progress) { if (offer || progress) {
bodyBottom = this.paintLongRunPanel(image, small, width, bodyBottom, offer, progress); bodyBottom = this.paintLongRunPanel(image, small, column, bodyBottom, offer, progress);
} }
if (this.working) { if (this.working) {
this.drawCentered(image, small, Math.round((bodyTop + bodyBottom) / 2) - 8, "Working…", 180); this.drawCentered(image, small, column, Math.round((bodyTop + bodyBottom) / 2) - 8, "Working…", 180);
} else if (this.lastFailure !== null) { } else if (this.lastFailure !== null) {
this.paintFailure(image, small, width, bodyTop, bodyBottom); this.paintFailure(image, small, column, bodyTop, bodyBottom);
} else if (this.mode === "explain" && this.coordinator.stepPosition !== null) { } else if (this.mode === "explain" && this.coordinator.stepPosition !== null) {
this.paintExplain(image, width, bodyTop, bodyBottom); this.paintExplain(image, column, bodyTop, bodyBottom);
} else if (this.mode === "graph" && this.coordinator.lastGraph) { } else if (this.mode === "graph" && this.coordinator.lastGraph) {
this.paintGraph(image, small, width, bodyTop, bodyBottom); this.paintGraph(image, small, column, bodyTop, bodyBottom);
} else if (this.lastAnswer) { } else if (this.lastAnswer) {
this.paintAnswer(image, width, bodyTop, bodyBottom); this.paintAnswer(image, column, bodyTop, bodyBottom);
} else { } else {
this.paintEmpty(image, small, width, bodyTop, bodyBottom); this.paintEmpty(image, small, column, bodyTop, bodyBottom);
} }
image.drawText(small, 24, footerY, this.footerHints(), 110); image.drawText(small, column.x, footerY, this.footerHints(), 110);
return image; return image;
} }
/** The three modes as tabs, plus the deg/listening status chips. */ /** The three modes as tabs from `y` down, plus the deg/listening status chips. */
private paintTabs(image: GrayImage, font: UiFont, width: number): void { private paintTabs(image: GrayImage, font: UiFont, column: Column, y: number): void {
let x = 24; let x = column.x;
const underlineY = y + TAB_UNDERLINE_OFFSET;
for (const mode of CALCULATOR_MODES) { for (const mode of CALCULATOR_MODES) {
const label = modeLabel(mode); const label = modeLabel(mode);
const active = mode === this.mode; const active = mode === this.mode;
image.drawText(font, x, 15, label, active ? 245 : 105); image.drawText(font, x, y, label, active ? 245 : 105);
image.drawLine(x, 35, x + font.measureText(label), 35, active ? 200 : 30); image.drawLine(x, underlineY, x + font.measureText(label), underlineY, active ? 200 : 30);
x += font.measureText(label) + 18; x += font.measureText(label) + 18;
} }
@@ -433,28 +455,28 @@ export class CalculatorLayer implements Layer {
else if (this.continuousActive && this.foreground) chips.push("mic on"); else if (this.continuousActive && this.foreground) chips.push("mic on");
if (chips.length > 0) { if (chips.length > 0) {
const text = chips.join(" · "); const text = chips.join(" · ");
image.drawText(font, width - 24 - font.measureText(text), 15, text, this.dictating ? 220 : 110); image.drawText(font, column.x + column.width - font.measureText(text), y, text, this.dictating ? 220 : 110);
} }
} }
private paintFailure( private paintFailure(
image: GrayImage, image: GrayImage,
font: UiFont, font: UiFont,
width: number, column: Column,
bodyTop: number, bodyTop: number,
bodyBottom: number, bodyBottom: number,
): void { ): void {
this.paintHeardLine(image, font, width, bodyTop); this.paintHeardLine(image, font, column, bodyTop);
const top = this.lastInput ? bodyTop + lineStep(font) + 6 : bodyTop + 8; const top = this.lastInput ? bodyTop + lineStep(font) + 6 : bodyTop + 8;
const lines = wrapText(font, this.lastFailure ?? "", width - 64); const lines = wrapText(font, this.lastFailure ?? "", column.width - 2 * BODY_INDENT);
const step = lineStep(font); const step = lineStep(font);
const maxLines = Math.max(1, Math.floor((bodyBottom - top) / step)); const maxLines = Math.max(1, Math.floor((bodyBottom - top) / step));
for (let index = 0; index < Math.min(lines.length, maxLines); index++) { for (let index = 0; index < Math.min(lines.length, maxLines); index++) {
image.drawText(font, 32, top + index * step, lines[index]!, 200); image.drawText(font, column.x + BODY_INDENT, top + index * step, lines[index]!, 200);
} }
} }
private paintExplain(image: GrayImage, width: number, bodyTop: number, bodyBottom: number): void { private paintExplain(image: GrayImage, column: Column, bodyTop: number, bodyBottom: number): void {
const small = getDefaultSmallFont(); const small = getDefaultSmallFont();
const medium = getDefaultMediumFont(); const medium = getDefaultMediumFont();
const position = this.coordinator.stepPosition; const position = this.coordinator.stepPosition;
@@ -463,63 +485,65 @@ export class CalculatorLayer implements Layer {
if (!position || !step) return; if (!position || !step) return;
let y = bodyTop + 2; let y = bodyTop + 2;
image.drawText(small, 24, y, `Step ${position.index + 1} of ${position.total}`, 130); image.drawText(small, column.x, y, `Step ${position.index + 1} of ${position.total}`, 130);
y += lineStep(small) + 2; y += lineStep(small) + 2;
image.drawText(medium, 24, y, truncateText(medium, step.title, width - 48), 245); image.drawText(medium, column.x, y, truncateText(medium, step.title, column.width), 245);
y += lineStep(medium) + 2; y += lineStep(medium) + 2;
image.drawText(medium, 24, y, truncateText(medium, plain(step.expression), width - 48), 220); image.drawText(medium, column.x, y, truncateText(medium, plain(step.expression), column.width), 220);
y += lineStep(medium) + 6; y += lineStep(medium) + 6;
const detailLines = wrapText(small, step.detail, width - 64); const detailLines = wrapText(small, step.detail, column.width - 2 * BODY_INDENT);
const stepPitch = lineStep(small); const stepPitch = lineStep(small);
const maxLines = Math.max(0, Math.floor((bodyBottom - y) / stepPitch)); const maxLines = Math.max(0, Math.floor((bodyBottom - y) / stepPitch));
for (let index = 0; index < Math.min(detailLines.length, maxLines); index++) { for (let index = 0; index < Math.min(detailLines.length, maxLines); index++) {
image.drawText(small, 32, y + index * stepPitch, detailLines[index]!, 150); image.drawText(small, column.x + BODY_INDENT, y + index * stepPitch, detailLines[index]!, 150);
} }
} }
private paintGraph( private paintGraph(
image: GrayImage, image: GrayImage,
font: UiFont, font: UiFont,
width: number, column: Column,
bodyTop: number, bodyTop: number,
bodyBottom: number, bodyBottom: number,
): void { ): void {
const graph = this.coordinator.lastGraph; const graph = this.coordinator.lastGraph;
if (!graph) return; if (!graph) return;
const headline = this.lastAnswer.split("\n")[0] ?? ""; const headline = this.lastAnswer.split("\n")[0] ?? "";
image.drawText(font, 24, bodyTop, truncateText(font, headline, width - 48), 200); image.drawText(font, column.x, bodyTop, truncateText(font, headline, column.width), 200);
// The plot's frame spans the column, so it meets the side padding itself.
const plotTop = bodyTop + lineStep(font) + 4; const plotTop = bodyTop + lineStep(font) + 4;
drawGraph(image, graph, { drawGraph(image, graph, {
x: 18, x: column.x,
y: plotTop, y: plotTop,
width: width - 36, width: column.width,
height: Math.max(2, bodyBottom - plotTop), height: Math.max(2, bodyBottom - plotTop),
}); });
} }
private paintAnswer(image: GrayImage, width: number, bodyTop: number, bodyBottom: number): void { private paintAnswer(image: GrayImage, column: Column, bodyTop: number, bodyBottom: number): void {
const small = getDefaultSmallFont(); const small = getDefaultSmallFont();
this.paintHeardLine(image, small, width, bodyTop); this.paintHeardLine(image, small, column, bodyTop);
const top = this.lastInput ? bodyTop + lineStep(small) + 4 : bodyTop; const top = this.lastInput ? bodyTop + lineStep(small) + 4 : bodyTop;
// A short single-line answer earns the large font; anything longer drops // A short single-line answer earns the large font; anything longer drops
// to the medium font and wraps. // to the medium font and wraps.
const lines = this.lastAnswer.split("\n"); const lines = this.lastAnswer.split("\n");
const large = getDefaultLargeFont(); const large = getDefaultLargeFont();
if (lines.length === 1 && large.measureText(lines[0]!) <= width - 64) { const maxWidth = column.width - 2 * BODY_INDENT;
if (lines.length === 1 && large.measureText(lines[0]!) <= maxWidth) {
const y = Math.round((top + bodyBottom - large.lineHeight) / 2); const y = Math.round((top + bodyBottom - large.lineHeight) / 2);
this.drawCentered(image, large, y, lines[0]!, 245); this.drawCentered(image, large, column, y, lines[0]!, 245);
return; return;
} }
const medium = getDefaultMediumFont(); const medium = getDefaultMediumFont();
const wrapped = lines.flatMap((line) => wrapText(medium, line, width - 64)); const wrapped = lines.flatMap((line) => wrapText(medium, line, maxWidth));
const step = lineStep(medium); const step = lineStep(medium);
const maxLines = Math.max(1, Math.floor((bodyBottom - top) / step)); const maxLines = Math.max(1, Math.floor((bodyBottom - top) / step));
const shown = wrapped.slice(0, maxLines); const shown = wrapped.slice(0, maxLines);
let y = Math.max(top, Math.round((top + bodyBottom - shown.length * step) / 2)); let y = Math.max(top, Math.round((top + bodyBottom - shown.length * step) / 2));
for (const line of shown) { for (const line of shown) {
this.drawCentered(image, medium, y, line, 235); this.drawCentered(image, medium, column, y, line, 235);
y += step; y += step;
} }
} }
@@ -527,7 +551,7 @@ export class CalculatorLayer implements Layer {
private paintEmpty( private paintEmpty(
image: GrayImage, image: GrayImage,
font: UiFont, font: UiFont,
width: number, column: Column,
bodyTop: number, bodyTop: number,
bodyBottom: number, bodyBottom: number,
): void { ): void {
@@ -536,31 +560,32 @@ export class CalculatorLayer implements Layer {
: this.listening === "continuous" : this.listening === "continuous"
? `Say a problem, then "${modeLabel(this.mode).toLowerCase()} it"` ? `Say a problem, then "${modeLabel(this.mode).toLowerCase()} it"`
: "Tap to say a problem — or use Voice input to type one"; : "Tap to say a problem — or use Voice input to type one";
const lines = wrapText(font, prompt, width - 96); const lines = wrapText(font, prompt, column.width - 2 * PROMPT_INDENT);
const step = lineStep(font); const step = lineStep(font);
let y = Math.round((bodyTop + bodyBottom - lines.length * step) / 2); let y = Math.round((bodyTop + bodyBottom - lines.length * step) / 2);
for (const line of lines) { for (const line of lines) {
this.drawCentered(image, font, y, line, 150); this.drawCentered(image, font, column, y, line, 150);
y += step; y += step;
} }
} }
private paintHeardLine(image: GrayImage, font: UiFont, width: number, y: number): void { private paintHeardLine(image: GrayImage, font: UiFont, column: Column, y: number): void {
if (!this.lastInput) return; if (!this.lastInput) return;
const label = this.textInput ? "Entered" : "Heard"; const label = this.textInput ? "Entered" : "Heard";
image.drawText(font, 24, y, label, 110); image.drawText(font, column.x, y, label, 110);
const x = 24 + font.measureText(label) + 10; const x = column.x + font.measureText(label) + 10;
image.drawText(font, x, y, truncateText(font, this.lastInput, width - x - 24), 160); image.drawText(font, x, y, truncateText(font, this.lastInput, column.x + column.width - x), 160);
} }
/** /**
* The standing offer, or the live progress of an accepted run, in the two * The standing offer, or the live progress of an accepted run, in the two
* rows above the footer. Returns the new body bottom. * rows above the footer, under a rule across the column. Returns the new
* body bottom.
*/ */
private paintLongRunPanel( private paintLongRunPanel(
image: GrayImage, image: GrayImage,
font: UiFont, font: UiFont,
width: number, column: Column,
bodyBottom: number, bodyBottom: number,
offer: LongRunOffer | null, offer: LongRunOffer | null,
progress: LongRunProgress | null, progress: LongRunProgress | null,
@@ -572,9 +597,9 @@ export class CalculatorLayer implements Layer {
? offerGlassesPrompt(offer).split("\n") ? offerGlassesPrompt(offer).split("\n")
: []; : [];
const panelTop = bodyBottom - lines.length * step - 6; const panelTop = bodyBottom - lines.length * step - 6;
image.drawLine(16, panelTop, width - 16, panelTop, 40); if (column.width > 0) image.drawLine(column.x, panelTop, column.x + column.width - 1, panelTop, 40);
for (let index = 0; index < lines.length; index++) { for (let index = 0; index < lines.length; index++) {
image.drawText(font, 24, panelTop + 4 + index * step, truncateText(font, lines[index]!, width - 48), 190); image.drawText(font, column.x, panelTop + 4 + index * step, truncateText(font, lines[index]!, column.width), 190);
} }
return panelTop - 2; return panelTop - 2;
} }
@@ -604,8 +629,8 @@ export class CalculatorLayer implements Layer {
]); ]);
} }
private drawCentered(image: GrayImage, font: UiFont, y: number, text: string, value: number): void { private drawCentered(image: GrayImage, font: UiFont, column: Column, y: number, text: string, value: number): void {
const x = Math.max(0, Math.round((image.width - font.measureText(text)) / 2)); const x = column.x + Math.max(0, Math.round((column.width - font.measureText(text)) / 2));
image.drawText(font, x, y, text, value); image.drawText(font, x, y, text, value);
} }
} }
+5
View File
@@ -3,6 +3,7 @@ import { invalidateCalendarCache, onCalendarChanged } from "../../native/calenda
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer"; import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
import { CalendarLayer } from "./calendar"; import { CalendarLayer } from "./calendar";
import { renderCalendarDateIcon } from "./calendar-icon"; import { renderCalendarDateIcon } from "./calendar-icon";
import { calendarSelectionMenuItems } from "./calendar-filter";
import { import {
createInProcessWindow, createInProcessWindow,
YieldAtRootLayer, YieldAtRootLayer,
@@ -44,6 +45,10 @@ export function createCalendarAppWindow(options: InProcessAppOptions): InProcess
icon: "calendar", icon: "calendar",
drawIcon: makeImageWindowIcon(renderCalendarDateIcon, windowIcon("calendar", "Ca")), drawIcon: makeImageWindowIcon(renderCalendarDateIcon, windowIcon("calendar", "Ca")),
closeable: true, closeable: true,
menuItems: () => calendarSelectionMenuItems().map(item => ({ ...item, onSelect: (ctx, menu) => {
ctx.stack.pop();
return item.onSelect(ctx, menu);
} })),
actions: options.actions, actions: options.actions,
baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)), baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)),
submitFrame: options.submitFrame, submitFrame: options.submitFrame,
+94
View File
@@ -0,0 +1,94 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { type GrayImage } from "../../graphics/image";
import { truncateText } from "../../graphics/textwrap";
import { readCalendarSelection, setCalendarSelection } from "../../native/calendar-selection";
import { readAvailableCalendars } from "../../native/calendar-sources";
import { hasCalendarPermission } from "../../native/calendar-permissions";
import { type InputEvent } from "../../ui/gestures";
import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
import { drawToggleMenuItem, MenuLayer, type MenuItem } from "../../ui/menu";
/** Shared preference for every Android calendar reader. */
export class CalendarFilterLayer implements Layer {
private menu: MenuLayer | null = null;
private width = 0;
private keys: string[] = [];
private currentMenu(ctx: LayerContext): MenuLayer {
const calendars = readAvailableCalendars().sort((a, b) =>
a.name.localeCompare(b.name) || a.accountName.localeCompare(b.accountName) || a.id.localeCompare(b.id));
const selection = readCalendarSelection();
const known = new Set(calendars.map(calendar => calendar.id));
const keys = ["all", "none"];
const toggle = (id: string) => {
// Leaving all mode snapshots the current calendars. Newly added calendars
// then stay excluded until selected individually or all mode is restored.
const ids = new Set(readCalendarSelection() ?? calendars.map(calendar => calendar.id));
if (ids.has(id)) ids.delete(id); else ids.add(id);
setCalendarSelection(Array.from(ids));
};
const items: MenuItem[] = [{
label: "All calendars",
description: "Include all calendars, including calendars added later.",
onSelect: () => setCalendarSelection(null),
render: ({ image, x, y, width, selected }) => drawToggleMenuItem(image, getDefaultSmallFont(), x, y, width,
"All calendars", readCalendarSelection() === null, selected),
}, {
label: "No calendars",
onSelect: () => setCalendarSelection([]),
render: ({ image, x, y, width, selected }) => drawToggleMenuItem(image, getDefaultSmallFont(), x, y, width,
"No calendars", readCalendarSelection()?.length === 0, selected),
}];
const rows = [
...calendars.map(calendar => ({ id: calendar.id,
label: `${calendar.name || "(unnamed)"} / ${calendar.accountName || "Local"} (${calendar.accountType || "local"}) #${calendar.id}` })),
...(selection ?? []).filter(id => !known.has(id)).map(id => ({ id, label: `Unavailable calendar #${id}` })),
];
for (const row of rows) {
keys.push(`calendar:${row.id}`);
items.push({
label: row.label,
description: row.label,
onSelect: () => toggle(row.id),
render: ({ image, x, y, width, selected }) => {
const font = getDefaultSmallFont();
const ids = readCalendarSelection();
drawToggleMenuItem(image, font, x, y, width, truncateText(font, row.label, width - 48),
ids === null || ids.includes(row.id), selected);
},
});
}
if (!calendars.length) items.push({
label: hasCalendarPermission() ? "No calendars available" : "Grant calendar permission on your phone",
disabled: true, onSelect: () => {},
});
const key = this.menu?.selectedIndex != null ? this.keys[this.menu.selectedIndex] : "all";
const index = Math.max(0, keys.indexOf(key ?? "all"));
this.keys = keys;
const width = ctx.stack.getBaseSize().width;
if (!this.menu || this.width !== width) {
this.width = width;
this.menu = new MenuLayer("Calendars displayed", items, {
x: 8, y: 8, width: width - 16, opaque: true, showBorder: false,
footer: "Shared by Calendar and Glanceboard",
}).selectItem(index);
} else this.menu.setItems(items, index);
return this.menu;
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
return this.currentMenu(ctx).paint(ctx, paintBelow);
}
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
await this.currentMenu(ctx).handleInput(event, ctx);
}
}
export function calendarSelectionMenuItems(): MenuItem[] {
return global.isAndroid ? [{
label: "Calendars displayed",
description: "Choose the calendars used by Calendar, Glanceboard and other calendar views.",
onSelect: ctx => ctx.stack.push(new CalendarFilterLayer()),
}] : [];
}
+68 -31
View File
@@ -8,14 +8,25 @@ import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
import { hasCalendarPermission } from "../../native/calendar-permissions"; import { hasCalendarPermission } from "../../native/calendar-permissions";
import { type Layer, type LayerContext } from "../../ui/layers"; import { type Layer, type LayerContext } from "../../ui/layers";
import { lineStep } from "../../ui/metrics"; import { lineStep } from "../../ui/metrics";
import type { Viewport } from "../../ui/viewport";
// Title position, shared with the other list apps (terminal, notifications). /** How far a row's text sits inside its selection box; the title lines up with it. */
const TITLE_X = 18; const ROW_TEXT_INSET = 10;
const TITLE_Y = 10; /**
const LIST_TOP = 38; * The title's drop below the window's top padding (the position shared with
const ROW_X = 16; * the other list apps: terminal, notifications), and the distance from its
* top to the first row.
*/
const TITLE_OFFSET_Y = 2;
const TITLE_BAND = 28;
const ROW_GAP = 4; const ROW_GAP = 4;
const MAX_EVENTS = 50; const MAX_EVENTS = 50;
/**
* The message shown in place of the list (no permission, nothing to show):
* its indent from the title, and its drop below the window's top padding.
*/
const MESSAGE_INDENT = 6;
const MESSAGE_OFFSET_Y = 64;
/** Height of the day header band above a row that starts a new day. */ /** Height of the day header band above a row that starts a new day. */
function dayHeaderHeight(font: UiFont): number { function dayHeaderHeight(font: UiFont): number {
@@ -46,20 +57,25 @@ export class CalendarLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const { width, height, padding } = viewport;
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
// Rows' selection boxes sit at the padding suggested for the window's
// side edges; the title lines up with their text.
const titleX = padding.left + ROW_TEXT_INSET;
const titleY = padding.top + TITLE_OFFSET_Y;
if (!hasCalendarPermission()) { if (!hasCalendarPermission()) {
image.drawText(font, TITLE_X, TITLE_Y, "Calendar", 220); image.drawText(font, titleX, titleY, "Calendar", 220);
this.paintPermissionPrompt(image, font, width, height); this.paintPermissionPrompt(image, font, viewport);
return image; return image;
} }
const events = readUpcomingEvents(MAX_EVENTS); const events = readUpcomingEvents(MAX_EVENTS);
if (!events.length) { if (!events.length) {
image.drawText(font, TITLE_X, TITLE_Y, "Calendar", 220); image.drawText(font, titleX, titleY, "Calendar", 220);
const state = getCalendarReadState(); const state = getCalendarReadState();
image.drawText(font, 24, 72, state === "loading" ? "Loading calendar..." image.drawText(font, titleX + MESSAGE_INDENT, padding.top + MESSAGE_OFFSET_Y, state === "loading" ? "Loading calendar..."
: state === "error" ? "Calendar unavailable. Try again shortly." : "No upcoming events.", 190); : state === "error" ? "Calendar unavailable. Try again shortly." : "No upcoming events.", 190);
return image; return image;
} }
@@ -67,22 +83,26 @@ export class CalendarLayer implements Layer {
const rows = buildEventRows(font, events); const rows = buildEventRows(font, events);
this.selectedIndex = clamp(this.selectedIndex, 0, rows.length - 1); this.selectedIndex = clamp(this.selectedIndex, 0, rows.length - 1);
const listBottom = height; // The agenda scrolls, so it runs to the window's top and bottom edges
const scrollY = scrollForSelected(rows, this.selectedIndex, listBottom - LIST_TOP); // and rows scrolled past an end are cut off right at the edge. The
// padding suggested for those edges is inside the scrolled content
// instead: above the title and below the last row.
const listTop = titleY + TITLE_BAND;
const scrollY = scrollForSelected(rows, this.selectedIndex, height - listTop, padding.bottom);
// The title scrolls away with the list; row text is deferred glyphs // The title scrolls away with the list; row text is deferred glyphs
// (composited above raster fills), so a fixed title would show through // (composited above raster fills), so a fixed title would show through
// rows scrolled over it. // rows scrolled over it.
if (TITLE_Y - scrollY + font.lineHeight > 0) { if (titleY - scrollY + font.lineHeight > 0) {
image.drawText(font, TITLE_X, TITLE_Y - scrollY, "Calendar", 220); image.drawText(font, titleX, titleY - scrollY, "Calendar", 220);
} }
let cursorY = LIST_TOP - scrollY; const rowWidth = width - padding.left - padding.right;
for (let index = 0; index < rows.length; index++) { let cursorY = listTop - scrollY;
for (let index = 0; index < rows.length && cursorY < height; index++) {
const row = rows[index]!; const row = rows[index]!;
if (cursorY + row.height >= LIST_TOP && cursorY <= listBottom) { if (cursorY + row.height > 0) {
drawEventRow(image, font, row, ROW_X, cursorY, width, index === this.selectedIndex); drawEventRow(image, font, row, padding.left, cursorY, rowWidth, index === this.selectedIndex);
} }
cursorY += row.height + ROW_GAP; cursorY += row.height + ROW_GAP;
if (cursorY > listBottom + 80) break;
} }
return image; return image;
} }
@@ -102,13 +122,21 @@ export class CalendarLayer implements Layer {
} }
} }
private paintPermissionPrompt(image: GrayImage, font: UiFont, width: number, height: number): void { private paintPermissionPrompt(image: GrayImage, font: UiFont, viewport: Viewport): void {
const { width, height, padding } = viewport;
const message = "Grant calendar permission on your phone to see your events on the glasses."; const message = "Grant calendar permission on your phone to see your events on the glasses.";
const lines = wrapText(font, message, width - 48); // Indented under the title, and as far short of the right padding.
for (let index = 0; index < lines.length; index++) { const indent = ROW_TEXT_INSET + MESSAGE_INDENT;
image.drawText(font, 24, 72 + index * lineStep(font), lines[index]!, 190); const x = padding.left + indent;
const lines = wrapText(font, message, width - padding.left - padding.right - 2 * indent);
// The hint rests on the bottom padding; the message keeps to the lines that fit above it.
const hintY = height - padding.bottom - font.lineHeight;
const top = padding.top + MESSAGE_OFFSET_Y;
const maxLines = Math.max(1, Math.floor((hintY - top) / lineStep(font)));
for (let index = 0; index < Math.min(lines.length, maxLines); index++) {
image.drawText(font, x, top + index * lineStep(font), lines[index]!, 190);
} }
image.drawText(font, 24, height - 36, `${GESTURE_CLICK} request`, 110); image.drawText(font, x, hintY, `${GESTURE_CLICK} request`, 110);
} }
} }
@@ -137,6 +165,7 @@ function buildEventRows(font: UiFont, events: CalendarEvent[]): EventRow[] {
return rows; return rows;
} }
/** Draw a row whose selection box spans `width` from `x`; its day header and text sit ROW_TEXT_INSET inside that. */
function drawEventRow( function drawEventRow(
image: GrayImage, image: GrayImage,
font: UiFont, font: UiFont,
@@ -146,30 +175,38 @@ function drawEventRow(
width: number, width: number,
selected: boolean, selected: boolean,
): void { ): void {
const textX = x + ROW_TEXT_INSET;
let cursorY = y; let cursorY = y;
if (row.dayHeader) { if (row.dayHeader) {
image.drawText(font, x, cursorY + 2, row.dayHeader, 150); image.drawText(font, textX, cursorY + 2, row.dayHeader, 150);
cursorY += dayHeaderHeight(font); cursorY += dayHeaderHeight(font);
} }
const bodyHeight = row.lines.length * lineStep(font) + 4; const bodyHeight = row.lines.length * lineStep(font) + 4;
if (selected) { if (selected) {
image.fillRoundedRect(x - 6, cursorY, width - 2 * (x - 6), bodyHeight, 15, 6); image.fillRoundedRect(x, cursorY, width, bodyHeight, 15, 6);
image.drawRoundedRect(x - 6, cursorY, width - 2 * (x - 6), bodyHeight, 90, 6); image.drawRoundedRect(x, cursorY, width, bodyHeight, 90, 6);
} }
const maxTextWidth = width - 2 * x; const maxTextWidth = width - 2 * ROW_TEXT_INSET;
for (let index = 0; index < row.lines.length; index++) { for (let index = 0; index < row.lines.length; index++) {
const value = index === 0 ? (selected ? 235 : 205) : 160; const value = index === 0 ? (selected ? 235 : 205) : 160;
image.drawText(font, x, cursorY + 3 + index * lineStep(font), truncateText(font, row.lines[index]!, maxTextWidth), value); image.drawText(font, textX, cursorY + 3 + index * lineStep(font), truncateText(font, row.lines[index]!, maxTextWidth), value);
} }
} }
function scrollForSelected(rows: EventRow[], selectedIndex: number, viewportHeight: number): number { /**
* The scroll offset that centers the selected row in `viewportHeight`, the
* room below the title's resting place, within the ends of what scrolls
* there: the rows, then `padBottom` after the last of them. So the first
* row rests with the title and the padding above it in view, and the last
* with the padding below it.
*/
function scrollForSelected(rows: EventRow[], selectedIndex: number, viewportHeight: number, padBottom: number): number {
let selectedTop = 0; let selectedTop = 0;
for (let index = 0; index < selectedIndex; index++) { for (let index = 0; index < selectedIndex; index++) {
selectedTop += rows[index]!.height + ROW_GAP; selectedTop += rows[index]!.height + ROW_GAP;
} }
const selectedBottom = selectedTop + rows[selectedIndex]!.height; const selectedBottom = selectedTop + rows[selectedIndex]!.height;
const contentHeight = rows.reduce((sum, row) => sum + row.height + ROW_GAP, 0); const contentHeight = rows.reduce((sum, row) => sum + row.height + ROW_GAP, -ROW_GAP) + padBottom;
const maxScroll = Math.max(0, contentHeight - viewportHeight); const maxScroll = Math.max(0, contentHeight - viewportHeight);
const centered = selectedTop - Math.max(0, (viewportHeight - (selectedBottom - selectedTop)) / 2); const centered = selectedTop - Math.max(0, (viewportHeight - (selectedBottom - selectedTop)) / 2);
return clamp(centered | 0, 0, maxScroll); return clamp(centered | 0, 0, maxScroll);
+9 -10
View File
@@ -25,10 +25,6 @@ const INSTRUCTIONS_BY_FRAME: Record<NorthReference, string> = {
magnetic: "magnetic compass heading (as read by another compass), then adjust the calibration offset below", magnetic: "magnetic compass heading (as read by another compass), then adjust the calibration offset below",
}; };
/** Margins around the instruction paragraph. */
const TEXT_PADDING_X = 16;
const TEXT_PADDING_TOP = 10;
export class CompassCalibrationLayer implements Layer { export class CompassCalibrationLayer implements Layer {
constructor( constructor(
/** Current uncorrected magnetometer heading, or null before the first reading. */ /** Current uncorrected magnetometer heading, or null before the first reading. */
@@ -36,7 +32,7 @@ export class CompassCalibrationLayer implements Layer {
) {} ) {}
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const small = getDefaultSmallFont(); const small = getDefaultSmallFont();
const medium = getDefaultMediumFont(); const medium = getDefaultMediumFont();
@@ -47,14 +43,17 @@ export class CompassCalibrationLayer implements Layer {
// Before the first reading there is no frame to name yet; the true-mode // Before the first reading there is no frame to name yet; the true-mode
// wording is the default and the readout will correct it once data arrives. // wording is the default and the readout will correct it once data arrives.
const frame = resolved?.frame ?? "true"; const frame = resolved?.frame ?? "true";
const lines = wrapText(small, INSTRUCTIONS_PREAMBLE + INSTRUCTIONS_BY_FRAME[frame], width - TEXT_PADDING_X * 2); // The instructions fill the width inside the padding suggested for the
// window's edges, from the top's down.
const lines = wrapText(small, INSTRUCTIONS_PREAMBLE + INSTRUCTIONS_BY_FRAME[frame], Math.max(0, width - padding.left - padding.right));
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
image.drawText(small, TEXT_PADDING_X, TEXT_PADDING_TOP + i * smallStep, lines[i]!, 190); image.drawText(small, padding.left, padding.top + i * smallStep, lines[i]!, 190);
} }
const textBottom = TEXT_PADDING_TOP + lines.length * smallStep; const textBottom = padding.top + lines.length * smallStep;
// Readouts along the bottom: dim label over a bright value, in thirds. // Readouts along the bottom, above its padding: dim label over a bright
const valueTop = height - medium.lineHeight; // value, in equal columns.
const valueTop = height - padding.bottom - medium.lineHeight;
const labelTop = valueTop - small.lineHeight; const labelTop = valueTop - small.lineHeight;
const columns: Array<[string, string]> = [ const columns: Array<[string, string]> = [
["Raw", raw === null ? "--°" : `${Math.round(raw)}°`], ["Raw", raw === null ? "--°" : `${Math.round(raw)}°`],
+18 -21
View File
@@ -41,18 +41,9 @@ export const COMPASS_SURFACE_ID = "window:compass";
const RECONCILE_INTERVAL_MS = 400; const RECONCILE_INTERVAL_MS = 400;
/** Vertical breathing room between the readout, the status line and the rose. */ /** Vertical breathing room between the readout, the status line and the rose. */
const STACK_GAP = 8; const STACK_GAP = 8;
/** Padding above the readout and below the rose's near edge. */
const TOP_PAD = 2;
const BOTTOM_PAD = 4;
/** Clearance between the rose's widest point and the viewport edge. */
const EDGE_PAD = 8;
/** Inset of the top-right magnetometer calibration readout from the window edges. */
const ACCURACY_TOP_PAD = TOP_PAD + 4;
const ACCURACY_RIGHT_PAD = EDGE_PAD + 4;
/** Cap on the rose's radius, so a tall window doesn't get a comical one. */ /** Cap on the rose's radius, so a tall window doesn't get a comical one. */
const MAX_ROSE_RADIUS = 98; const MAX_ROSE_RADIUS = 98;
class CompassLayer implements Layer { class CompassLayer implements Layer {
private rawHeading: number | null = null; private rawHeading: number | null = null;
private diagnostics: CompassDiagnostics | null = null; private diagnostics: CompassDiagnostics | null = null;
@@ -161,35 +152,41 @@ class CompassLayer implements Layer {
} }
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const small = getDefaultSmallFont(); const small = getDefaultSmallFont();
const large = getDefaultLargeFont(); const large = getDefaultLargeFont();
const heading = this.rawHeading === null ? null : resolveHeading(this.rawHeading).displayDegrees; const heading = this.rawHeading === null ? null : resolveHeading(this.rawHeading).displayDegrees;
const headingText = heading === null ? "--°" : `${Math.round(heading)}° ${cardinalDirection(heading)}`; const headingText = heading === null ? "--°" : `${Math.round(heading)}° ${cardinalDirection(heading)}`;
const statusLines = wrapText(small, this.statusText(), width - STACK_GAP * 2); // Text and the rose keep inside the padding suggested for the window's edges.
const textWidth = Math.max(0, width - padding.left - padding.right);
const statusLines = wrapText(small, this.statusText(), textWidth);
const smallStep = lineStep(small); const smallStep = lineStep(small);
const headingFont = large.measureText(headingText) <= width - EDGE_PAD * 2 ? large : small; const headingFont = large.measureText(headingText) <= textWidth ? large : small;
const readoutWidth = headingFont.measureText(headingText); const readoutWidth = headingFont.measureText(headingText);
const readoutHeight = headingFont.lineHeight; const readoutHeight = headingFont.lineHeight;
// One column centred on the display's true centre, so the rose sits where // One column centred on the display's true centre, so the rose sits where
// the wearer is looking rather than 32px beside it (with a side strip). // the wearer is looking rather than 32px beside it (with a side strip).
const cx = screenCenterInViewportX(); const cx = screenCenterInViewportX();
// A line of that column: centred there, short of leaving the padded width.
const lineX = (lineWidth: number) =>
Math.round(Math.max(padding.left, Math.min(width - padding.right - lineWidth, cx - lineWidth / 2)));
// The rose is sized and placed first — it hangs off the bottom edge — and // The rose is sized and placed first — it hangs off the bottom edge — and
// the readout then floats in whatever room is left above it. // the readout then floats in whatever room is left above it. Its far
// edges land on the last row and column inside the padding.
const textHeight = readoutHeight + 4 + statusLines.length * smallStep; const textHeight = readoutHeight + 4 + statusLines.length * smallStep;
const { cy, radius, ringTop } = layoutCompassRose({ const { cy, radius, ringTop } = layoutCompassRose({
width, width,
height, height,
cx, cx,
topClearance: TOP_PAD + textHeight + STACK_GAP, topClearance: padding.top + textHeight + STACK_GAP,
bottomPad: BOTTOM_PAD, bottomPad: padding.bottom + 1,
edgePad: EDGE_PAD, edgePad: { left: padding.left, right: padding.right + 1 },
maxRadius: MAX_ROSE_RADIUS, maxRadius: MAX_ROSE_RADIUS,
}); });
let y = Math.max(TOP_PAD, Math.round((ringTop - TICK_HEIGHT - textHeight) / 2)); let y = Math.max(padding.top, Math.round((ringTop - TICK_HEIGHT - textHeight) / 2));
const fade = heading === null ? 0.45 : 1; const fade = heading === null ? 0.45 : 1;
const clipY = y + textHeight + 6; const clipY = y + textHeight + 6;
const backgroundKey = [width, height, cx, cy, radius, clipY, fade].join(","); const backgroundKey = [width, height, cx, cy, radius, clipY, fade].join(",");
@@ -201,16 +198,16 @@ class CompassLayer implements Layer {
} }
const image = this.background.image.clone(); const image = this.background.image.clone();
drawCompassRose(image, cx, cy, radius, heading); drawCompassRose(image, cx, cy, radius, heading);
const readoutX = Math.round(Math.max(EDGE_PAD, Math.min(width - EDGE_PAD - readoutWidth, cx - readoutWidth / 2))); image.drawText(headingFont, lineX(readoutWidth), y, headingText, heading === null ? 150 : 255);
image.drawText(headingFont, readoutX, y, headingText, heading === null ? 150 : 255);
y += readoutHeight + 4; y += readoutHeight + 4;
for (const line of statusLines) { for (const line of statusLines) {
image.drawText(small, Math.round(cx - small.measureText(line) / 2), y, line, 125); image.drawText(small, lineX(small.measureText(line)), y, line, 125);
y += smallStep; y += smallStep;
} }
if (glassesHaveCompass()) { if (glassesHaveCompass()) {
// The magnetometer calibration readout sits in the window's top-right corner.
const accuracyText = magneticAccuracyText(this.diagnostics); const accuracyText = magneticAccuracyText(this.diagnostics);
image.drawText(small, width - ACCURACY_RIGHT_PAD - small.measureText(accuracyText), ACCURACY_TOP_PAD, accuracyText, 175); image.drawText(small, width - padding.right - small.measureText(accuracyText), padding.top, accuracyText, 175);
} }
return image; return image;
+4 -2
View File
@@ -78,17 +78,19 @@ export function layoutCompassRose(options: {
/** Lowest y already used above the rose (readout text, its gap). */ /** Lowest y already used above the rose (readout text, its gap). */
topClearance: number; topClearance: number;
bottomPad: number; bottomPad: number;
edgePad: number; /** Clearance between the rose's widest point and the box's sides: one figure for both, or each side's. */
edgePad: number | { left: number; right: number };
maxRadius: number; maxRadius: number;
minRadius?: number; minRadius?: number;
}): { cx: number; cy: number; radius: number; ringTop: number } { }): { cx: number; cy: number; radius: number; ringTop: number } {
const { width, height, cx } = options; const { width, height, cx } = options;
const sidePad = typeof options.edgePad === "number" ? { left: options.edgePad, right: options.edgePad } : options.edgePad;
const radius = Math.max( const radius = Math.max(
options.minRadius ?? 24, options.minRadius ?? 24,
Math.min( Math.min(
options.maxRadius, options.maxRadius,
Math.floor((height - options.bottomPad - options.topClearance - TICK_HEIGHT) / (RING_HEIGHT_PER_RADIUS + DISC_DEPTH)), Math.floor((height - options.bottomPad - options.topClearance - TICK_HEIGHT) / (RING_HEIGHT_PER_RADIUS + DISC_DEPTH)),
Math.floor((Math.min(cx, width - cx) - options.edgePad) / RING_HALF_WIDTH_PER_RADIUS), Math.floor(Math.min(cx - sidePad.left, width - cx - sidePad.right) / RING_HALF_WIDTH_PER_RADIUS),
), ),
); );
// The wall hangs below the rim, so the near rim sits a wall's depth up // The wall hangs below the rim, so the near rim sits a wall's depth up
+23 -12
View File
@@ -13,6 +13,12 @@ import { shell } from "../../ui/shell/shell";
const IMU_REPORT_PACE = 200; const IMU_REPORT_PACE = 200;
// How often to reconcile the IMU on/off state with window visibility. // How often to reconcile the IMU on/off state with window visibility.
const RECONCILE_INTERVAL_MS = 400; const RECONCILE_INTERVAL_MS = 400;
/** The readout under the title sits this far in from the title's left edge. */
const BODY_INDENT = 2;
/** An axis row, from the readout's left edge: its value, then its bar, which stops this short of the right edge's padding. */
const VALUE_OFFSET_X = 22;
const BAR_OFFSET_X = 96;
const BAR_RIGHT_INSET = 4;
/** /**
* Accelerometer demo: turns the IMU stream on while this page is visible (the * Accelerometer demo: turns the IMU stream on while this page is visible (the
@@ -77,12 +83,17 @@ export class AccelerometerDemoLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const small = getDefaultSmallFont(); const small = getDefaultSmallFont();
const medium = getDefaultMediumFont(); const medium = getDefaultMediumFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
// The title line sits at the padding suggested for the top, left and
// right edges; everything under it is placed from there.
const top = padding.top;
const right = width - padding.right;
const bodyX = padding.left + BODY_INDENT;
image.drawText(small, 20, 8, "Accelerometer", 220); image.drawText(small, padding.left, top, "Accelerometer", 220);
const status = this.enabled ? "IMU on" : "IMU off"; const status = this.enabled ? "IMU on" : "IMU off";
image.drawText(small, width - 20 - small.measureText(status), 8, status, 150); image.drawText(small, right - small.measureText(status), top, status, 150);
if (this.reading) { if (this.reading) {
const axes: Array<[string, number]> = [ const axes: Array<[string, number]> = [
@@ -90,19 +101,19 @@ export class AccelerometerDemoLayer implements Layer {
["Y", this.reading.y], ["Y", this.reading.y],
["Z", this.reading.z], ["Z", this.reading.z],
]; ];
const barX = 118; const barX = bodyX + BAR_OFFSET_X;
const barW = width - barX - 24; const barW = Math.max(0, right - BAR_RIGHT_INSET - barX);
const scale = Math.max(this.peak, 1e-6); const scale = Math.max(this.peak, 1e-6);
let y = 40; let y = top + 32;
for (const [label, value] of axes) { for (const [label, value] of axes) {
image.drawText(medium, 22, y, label, 210); image.drawText(medium, bodyX, y, label, 210);
image.drawText(medium, 44, y, value.toFixed(3), 235); image.drawText(medium, bodyX + VALUE_OFFSET_X, y, value.toFixed(3), 235);
drawCenteredBar(image, barX, y + 2, barW, 12, clamp(value / scale, -1, 1)); drawCenteredBar(image, barX, y + 2, barW, 12, clamp(value / scale, -1, 1));
y += 30; y += 30;
} }
image.drawText( image.drawText(
small, small,
22, bodyX,
y + 6, y + 6,
`source: ${imuSourceLabel(this.reading.source)} samples: ${this.sampleCount}`, `source: ${imuSourceLabel(this.reading.source)} samples: ${this.sampleCount}`,
130, 130,
@@ -111,9 +122,9 @@ export class AccelerometerDemoLayer implements Layer {
const message = this.enabled const message = this.enabled
? "Waiting for IMU data…" ? "Waiting for IMU data…"
: "Paused (page not visible)."; : "Paused (page not visible).";
image.drawText(small, 22, 44, message, 190); image.drawText(small, bodyX, top + 36, message, 190);
image.drawText(small, 22, 66, "The firmware may not report the", 120); image.drawText(small, bodyX, top + 58, "The firmware may not report the", 120);
image.drawText(small, 22, 82, "accelerometer at all — experimental.", 120); image.drawText(small, bodyX, top + 74, "accelerometer at all — experimental.", 120);
} }
return image; return image;
+27 -16
View File
@@ -27,9 +27,12 @@ const POLL_INTERVAL_MS = 500;
// timeout drain + slack). // timeout drain + slack).
const POLL_DEADLINE_MS = DURATION_MS + 15_000; const POLL_DEADLINE_MS = DURATION_MS + 15_000;
const HEADER_HEIGHT = 30; /** The title band: the rows and the run's text start this far below the top edge's padding. */
const LIST_X = 20; const HEADER_HEIGHT = 22;
const VALUE_X = 150; /** Horizontal inset of a row's text from its highlight box; the title and the text under the rows line up with it. */
const ROW_TEXT_INSET = 6;
/** A row's value column, from its label's left edge. */
const VALUE_OFFSET_X = 130;
type Phase = "config" | "arming" | "running" | "done"; type Phase = "config" | "arming" | "running" | "done";
type ConfigRow = "size" | "window" | "link" | "start"; type ConfigRow = "size" | "window" | "link" | "start";
@@ -126,36 +129,43 @@ export class BandwidthBenchmarkLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
// The rows' highlight boxes span the window inside the padding suggested
// for its side edges, and the title sits at the top edge's; the page's
// text shares the rows' text column.
const textX = padding.left + ROW_TEXT_INSET;
const bodyTop = padding.top + HEADER_HEIGHT;
image.drawText(font, 20, 8, "BLE bandwidth", 220); image.drawText(font, textX, padding.top, "BLE bandwidth", 220);
if (this.phase === "arming" || this.phase === "running") { if (this.phase === "arming" || this.phase === "running") {
image.drawText(font, LIST_X, HEADER_HEIGHT + 8, "Running: streaming no-op packets for 15 s...", 200); image.drawText(font, textX, bodyTop + 8, "Running: streaming no-op packets for 15 s...", 200);
image.drawText( image.drawText(
font, font,
LIST_X, textX,
HEADER_HEIGHT + 30, bodyTop + 30,
`${MESSAGE_SIZES[this.sizeIndex]} B, window ${WINDOW_SIZES[this.windowIndex]}` `${MESSAGE_SIZES[this.sizeIndex]} B, window ${WINDOW_SIZES[this.windowIndex]}`
+ (LINK_REQUESTS_SUPPORTED ? `, ${LINK_MODES[this.linkModeIndex]}` : ""), + (LINK_REQUESTS_SUPPORTED ? `, ${LINK_MODES[this.linkModeIndex]}` : ""),
150, 150,
); );
image.drawText(font, LIST_X, HEADER_HEIGHT + 52, "Display updates pause until the run finishes.", 110); image.drawText(font, textX, bodyTop + 52, "Display updates pause until the run finishes.", 110);
return image; return image;
} }
// The rows all fit their box, so it is a fixed block under the title
// rather than a scroller that would run to the window's bottom edge.
const rowH = tightRowHeight(font) + 4; const rowH = tightRowHeight(font) + 4;
const rowCount = this.menu.items.length; const rowCount = this.menu.items.length;
this.menu.paint( this.menu.paint(
image, image,
{ x: LIST_X - 6, y: HEADER_HEIGHT - 1, width: width - 2 * LIST_X + 12, height: rowCount * rowH }, { x: padding.left, y: bodyTop - 1, width: Math.max(0, width - padding.left - padding.right), height: rowCount * rowH },
ctx.stack.isFocused(), ctx.stack.isFocused(),
); );
let y = HEADER_HEIGHT + rowCount * rowH + 10; let y = bodyTop + rowCount * rowH + 10;
if (this.error) { if (this.error) {
image.drawText(font, LIST_X, y, this.error, 180); image.drawText(font, textX, y, this.error, 180);
} else if (this.result) { } else if (this.result) {
const r = this.result; const r = this.result;
const seconds = r.elapsedMs / 1000; const seconds = r.elapsedMs / 1000;
@@ -171,7 +181,9 @@ export class BandwidthBenchmarkLayer implements Layer {
lines.push(`Link request: ${LINK_MODES[r.linkMode] ?? "Current"}${phy}`); lines.push(`Link request: ${LINK_MODES[r.linkMode] ?? "Current"}${phy}`);
} }
for (const line of lines) { for (const line of lines) {
image.drawText(font, LIST_X, y, line, 190); // A window too short for every line (the RayNeo iO's) shows the first ones.
if (y + font.lineHeight > height) break;
image.drawText(font, textX, y, line, 190);
y += 20; y += 20;
} }
} }
@@ -187,10 +199,9 @@ export class BandwidthBenchmarkLayer implements Layer {
: item === "link" ? ["Link request", LINK_MODES[this.linkModeIndex]!] : item === "link" ? ["Link request", LINK_MODES[this.linkModeIndex]!]
: [this.phase === "done" ? "Run again" : "Start", ""]; : [this.phase === "done" ? "Run again" : "Start", ""];
const textY = centeredTextY(font, y, height); const textY = centeredTextY(font, y, height);
// Text sits 6px in from the row box (LIST_X), values at VALUE_X. image.drawText(font, x + ROW_TEXT_INSET, textY, label, selected ? 255 : 200);
image.drawText(font, x + 6, textY, label, selected ? 255 : 200);
if (value) { if (value) {
image.drawText(font, x + 6 + VALUE_X - LIST_X, textY, value, selected ? 235 : 160); image.drawText(font, x + ROW_TEXT_INSET + VALUE_OFFSET_X, textY, value, selected ? 235 : 160);
} }
} }
+24 -14
View File
@@ -13,9 +13,12 @@ import {
type SoundEffect, type SoundEffect,
} from "../../ui/sound-effects"; } from "../../ui/sound-effects";
const HEADER_HEIGHT = 30; /** The title band: the list starts this far below the top edge's padding. */
const LIST_X = 20; const HEADER_HEIGHT = 22;
const FOOTER_HEIGHT = 0; /** Horizontal inset of a row's text from its highlight box; the title lines up with it. */
const ROW_TEXT_INSET = 6;
/** The status text ends this far short of the rows' right edge. */
const STATUS_INSET = 10;
function sleep(ms: number): Promise<void> { function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
@@ -39,19 +42,26 @@ export class BuzzerDemoLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
image.drawText(font, 20, 8, "Buzzer demo", 220); image.drawText(font, padding.left + ROW_TEXT_INSET, padding.top, "Buzzer demo", 220);
const status = this.playing ? `Playing: ${this.playing}` : `${GESTURE_CLICK} play`; const status = this.playing ? `Playing: ${this.playing}` : `${GESTURE_CLICK} play`;
image.drawText(font, width - 24 - font.measureText(status), 8, status, 140); image.drawText(font, width - padding.right - STATUS_INSET - font.measureText(status), padding.top, status, 140);
const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT; // The title line stays put, so the list starts right under it with no
this.menu.paint( // padding of its own there. It scrolls, so it runs to the window's
image, // bottom edge with the padding suggested for that edge inside it, after
{ x: LIST_X - 6, y: HEADER_HEIGHT - 1, width: width - 2 * LIST_X + 12, height: listHeight }, // the last row.
ctx.stack.isFocused(), const listTop = padding.top + HEADER_HEIGHT - 1;
); if (height > listTop) {
this.menu.paint(
image,
{ x: padding.left, y: listTop, width: Math.max(0, width - padding.left - padding.right), height: height - listTop,
padTop: 0, padBottom: padding.bottom },
ctx.stack.isFocused(),
);
}
return image; return image;
} }
@@ -104,6 +114,6 @@ export class BuzzerDemoLayer implements Layer {
function drawEffectRow({ image, item: effect, x, y, height, selected }: MenuDrawArgs<SoundEffect>): void { function drawEffectRow({ image, item: effect, x, y, height, selected }: MenuDrawArgs<SoundEffect>): void {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const textY = centeredTextY(font, y, height); const textY = centeredTextY(font, y, height);
image.drawText(font, x + 6, textY, effect.name, selected ? 255 : 200); image.drawText(font, x + ROW_TEXT_INSET, textY, effect.name, selected ? 255 : 200);
image.drawText(font, x + 6 + 110, textY, effect.desc, selected ? 180 : 120); image.drawText(font, x + ROW_TEXT_INSET + 110, textY, effect.desc, selected ? 180 : 120);
} }
+3 -12
View File
@@ -12,7 +12,6 @@ import { RingStatusLayer } from "./ring-status";
import { LoadAppFromQrLayer, LoadAppFromUrlLayer } from "./load-app"; import { LoadAppFromQrLayer, LoadAppFromUrlLayer } from "./load-app";
import { unicodeTestMenu } from "./unicode-test"; import { unicodeTestMenu } from "./unicode-test";
import { type AppContext } from "../app-definition"; import { type AppContext } from "../app-definition";
import { appViewportSize } from "../../ui/shell/geometry";
import { import {
createInProcessWindow, createInProcessWindow,
YieldAtRootLayer, YieldAtRootLayer,
@@ -23,17 +22,9 @@ import {
export const DEVELOPER_WINDOW_ID = "developer"; export const DEVELOPER_WINDOW_ID = "developer";
export const DEVELOPER_SURFACE_ID = "window:developer"; export const DEVELOPER_SURFACE_ID = "window:developer";
const MENU_LAYOUT = { // These menus are pages, not popups: "Debug tests" replaces the root menu
x: 8, // visually instead of letting the taller root show through beneath it.
y: 8, const MENU_LAYOUT = { page: true, width: 248 } as const;
width: 272,
showBorder: false,
minHeight: 0,
maxHeight: appViewportSize("min").height - 16,
// These menus are pages, not popups: "Debug tests" replaces the root menu
// visually instead of letting the taller root show through beneath it.
opaque: true,
};
type OpenPage = (ctx: Parameters<MenuItem["onSelect"]>[0]) => void; type OpenPage = (ctx: Parameters<MenuItem["onSelect"]>[0]) => void;
+36 -15
View File
@@ -6,6 +6,14 @@ import { addInputListener, InputEventLog, inputTimestamp } from "../../ui/input-
import type { Layer, LayerContext } from "../../ui/layers"; import type { Layer, LayerContext } from "../../ui/layers";
import { drawListScrollbar, type MenuItem } from "../../ui/menu"; import { drawListScrollbar, type MenuItem } from "../../ui/menu";
/** Room the log's rows keep free on the right for the scrollbar, and the bar's own width. */
const SCROLLBAR_GUTTER = 6;
const SCROLLBAR_WIDTH = 3;
/** A row's second (raw report) line is indented this far, and stops as far short of the row's end. */
const DETAIL_INDENT = 12;
/** Gap between the log and the hint line under it. */
const FOOTER_GAP = 6;
/** Gestures are samples here; back/clear/pause live in the tap-then-hold menu. */ /** Gestures are samples here; back/clear/pause live in the tap-then-hold menu. */
export class InputEventsLayer implements Layer { export class InputEventsLayer implements Layer {
readonly acceptsDirectional = true; readonly acceptsDirectional = true;
@@ -48,30 +56,41 @@ export class InputEventsLayer implements Layer {
} }
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
image.drawText(font, 12, 8, "Input events", 230); // The title and column-heading lines stay put at the top and the hint
// line at the bottom, each inside the padding suggested for its edge.
// The log scrolls between them, so it needs no padding of its own.
const left = padding.left;
const top = padding.top;
const right = width - padding.right;
const footerY = height - padding.bottom - font.lineHeight;
const listTop = top + 42;
const listBottom = footerY - FOOTER_GAP;
// The rows stop short of the scrollbar, which keeps inside the padding.
const rowsRight = right - SCROLLBAR_GUTTER;
image.drawText(font, left, top, "Input events", 230);
const status = `${this.log.paused ? "Paused" : "Live"} ${this.log.count} events`; const status = `${this.log.paused ? "Paused" : "Live"} ${this.log.count} events`;
image.drawText(font, width - 12 - font.measureText(status), 8, status, 180); image.drawText(font, right - font.measureText(status), top, status, 180);
image.drawText(font, 12, 28, this.phoneTime ? "Phone receive time | gap ms | source | event" : "Time (R=ring tick) | gap | source | event", 140); image.drawText(font, left, top + 20, this.phoneTime ? "Phone receive time | gap ms | source | event" : "Time (R=ring tick) | gap | source | event", 140);
const lineHeight = Math.max(18, font.lineHeight + 2); const lineHeight = Math.max(18, font.lineHeight + 2);
const rowHeight = lineHeight * 2 + 4; const rowHeight = lineHeight * 2 + 4;
this.visibleRows = Math.max(1, Math.floor((height - 76) / rowHeight)); this.visibleRows = Math.max(1, Math.floor((listBottom - listTop) / rowHeight));
this.scrollRow = Math.min(this.scrollRow, Math.max(0, this.log.entries.length - this.visibleRows)); this.scrollRow = Math.min(this.scrollRow, Math.max(0, this.log.entries.length - this.visibleRows));
const timeX = 12; const timeX = left;
const gapX = timeX + font.measureText("00:00:00.000") + 12; const gapX = timeX + font.measureText("00:00:00.000") + 12;
const sourceX = gapX + font.measureText("+99999") + 12; const sourceX = gapX + font.measureText("+99999") + 12;
const eventX = sourceX + font.measureText("right-arm") + 12; const eventX = sourceX + font.measureText("right-arm") + 12;
if (!this.log.entries.length) { if (!this.log.entries.length) {
image.drawText(font, 12, 62, "Touch, tap, double-tap, hold, or swipe the ring.", 210); image.drawText(font, left, listTop + 12, "Touch, tap, double-tap, hold, or swipe the ring.", 210);
image.drawText(font, 12, 82, "Press arrives before an interpreted gesture.", 150); image.drawText(font, left, listTop + 32, "Press arrives before an interpreted gesture.", 150);
} }
for (const [index, entry] of this.log.entries.slice(this.scrollRow, this.scrollRow + this.visibleRows).entries()) { for (const [index, entry] of this.log.entries.slice(this.scrollRow, this.scrollRow + this.visibleRows).entries()) {
const { event } = entry; const { event } = entry;
const ringTime = !this.phoneTime && event.ringInput; const ringTime = !this.phoneTime && event.ringInput;
const gapMs = ringTime ? entry.ringGapTicks : entry.gapMs; const gapMs = ringTime ? entry.ringGapTicks : entry.gapMs;
const y = 50 + index * rowHeight; const y = listTop + index * rowHeight;
const gap = gapMs === null ? "-" : `${gapMs >= 0 ? "+" : ""}${gapMs}`; const gap = gapMs === null ? "-" : `${gapMs >= 0 ? "+" : ""}${gapMs}`;
const source = "source" in event ? event.source ?? "-" : "-"; const source = "source" in event ? event.source ?? "-" : "-";
const label = (entry.filtered ? "*" : "") + (event.type === "unknown" const label = (entry.filtered ? "*" : "") + (event.type === "unknown"
@@ -80,18 +99,20 @@ export class InputEventsLayer implements Layer {
image.drawText(font, timeX, y, ringTime ? `R${ringTime.tick}` : inputTimestamp(event.timestampMs), 170); image.drawText(font, timeX, y, ringTime ? `R${ringTime.tick}` : inputTimestamp(event.timestampMs), 170);
image.drawText(font, gapX, y, truncateText(font, gap, sourceX - gapX - 4), 160); image.drawText(font, gapX, y, truncateText(font, gap, sourceX - gapX - 4), 160);
image.drawText(font, sourceX, y, source, 180); image.drawText(font, sourceX, y, source, 180);
image.drawText(font, eventX, y, truncateText(font, label, width - eventX - 12), event.type === "ring-press" ? 255 : 200); image.drawText(font, eventX, y, truncateText(font, label, rowsRight - eventX), event.type === "ring-press" ? 255 : 200);
if (event.ringInput) { if (event.ringInput) {
const { type, aux, speed } = event.ringInput; const { type, aux, speed } = event.ringInput;
// These are the original report bytes, not physical distance/speed units. // These are the original report bytes, not physical distance/speed units.
const details = `Raw ring: type ${type} AUX ${aux} speed ${speed}`; const details = `Raw ring: type ${type} AUX ${aux} speed ${speed}`;
image.drawText(font, timeX + 12, y + lineHeight, image.drawText(font, timeX + DETAIL_INDENT, y + lineHeight,
truncateText(font, details, width - timeX - 36), 170); truncateText(font, details, rowsRight - timeX - 2 * DETAIL_INDENT), 170);
} }
} }
if (this.log.paused) drawListScrollbar(image, width - 5, 50, height - 78, if (this.log.paused && listBottom > listTop) {
this.scrollRow, this.visibleRows, this.log.entries.length); drawListScrollbar(image, right - SCROLLBAR_WIDTH, listTop, listBottom - listTop,
image.drawText(font, 12, height - 20, this.scrollRow, this.visibleRows, this.log.entries.length);
}
image.drawText(font, left, footerY,
this.log.paused ? "Scroll: history Tap-hold: controls" : "Unfiltered (*=dedup) Tap-hold: controls", 140); this.log.paused ? "Scroll: history Tap-hold: controls" : "Unfiltered (*=dedup) Tap-hold: controls", 140);
return image; return image;
} }
+29 -16
View File
@@ -22,6 +22,10 @@ const RECONCILE_INTERVAL_MS = 400;
// Length of the on-screen trace. // Length of the on-screen trace.
const HISTORY_MS = 30_000; const HISTORY_MS = 30_000;
const MAX_SAMPLES = Math.ceil(HISTORY_MS / 100) + 2; const MAX_SAMPLES = Math.ceil(HISTORY_MS / 100) + 2;
/** The readout under the title sits this far in from the title's left edge. */
const BODY_INDENT = 2;
/** Gap between the trace's box and the footer line under it. */
const CHART_FOOTER_GAP = 18;
type Sample = { atMs: number; value: number; peak: number }; type Sample = { atMs: number; value: number; peak: number };
@@ -102,39 +106,47 @@ export class LightSensorDemoLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const small = getDefaultSmallFont(); const small = getDefaultSmallFont();
const medium = getDefaultMediumFont(); const medium = getDefaultMediumFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
// The title line, the trace's box and the footer line sit at the padding
// suggested for the edges they reach; the rest is placed from them.
const left = padding.left;
const top = padding.top;
const right = width - padding.right;
const bodyX = left + BODY_INDENT;
const footerY = height - padding.bottom - small.lineHeight;
image.drawText(small, 20, 8, "Light sensor", 220); image.drawText(small, left, top, "Light sensor", 220);
const status = this.enabled ? "polling" : "paused"; const status = this.enabled ? "polling" : "paused";
image.drawText(small, width - 20 - small.measureText(status), 8, status, 150); image.drawText(small, right - small.measureText(status), top, status, 150);
const report = this.report; const report = this.report;
if (!report) { if (!report) {
const message = this.enabled ? "Waiting for a report…" : "Paused (page not visible)."; const message = this.enabled ? "Waiting for a report…" : "Paused (page not visible).";
image.drawText(small, 22, 44, message, 190); image.drawText(small, bodyX, top + 36, message, 190);
image.drawText(small, 22, 66, "Needs Faceclaw's custom firmware.", 120); image.drawText(small, bodyX, top + 58, "Needs Faceclaw's custom firmware.", 120);
image.drawText(small, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110); image.drawText(small, left, footerY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image; return image;
} }
// Headline reading. The stock driver's unit is roughly a tenth of a lux. // Headline reading. The stock driver's unit is roughly a tenth of a lux.
const lux = (report.alsValue / 10).toFixed(1); const lux = (report.alsValue / 10).toFixed(1);
image.drawText(medium, 22, 30, `${lux} lux`, 245); image.drawText(medium, bodyX, top + 22, `${lux} lux`, 245);
const peakText = `peak ${(report.peak / 10).toFixed(1)}`; const peakText = `peak ${(report.peak / 10).toFixed(1)}`;
image.drawText(small, 22 + medium.measureText(`${lux} lux`) + 14, 36, peakText, 170); image.drawText(small, bodyX + medium.measureText(`${lux} lux`) + 14, top + 28, peakText, 170);
const flags: string[] = []; const flags: string[] = [];
if (!report.opened) flags.push("sensor closed"); if (!report.opened) flags.push("sensor closed");
if (report.passive) flags.push("passive"); if (report.passive) flags.push("passive");
if (report.autoBrightness) flags.push("auto on"); if (report.autoBrightness) flags.push("auto on");
if (report.passive && !report.readOk) flags.push("read failed"); if (report.passive && !report.readOk) flags.push("read failed");
image.drawText(small, 22, 58, flags.join(" ") || "stock polling", 150); image.drawText(small, bodyX, top + 50, flags.join(" ") || "stock polling", 150);
const statsY = top + 68;
image.drawText( image.drawText(
small, small,
22, bodyX,
76, statsY,
`brightness ${report.brightness} stock target ${report.stockTarget} gear ${report.gear} scale ${(report.scaleQ10 / 1024).toFixed(2)}`, `brightness ${report.brightness} stock target ${report.stockTarget} gear ${report.gear} scale ${(report.scaleQ10 / 1024).toFixed(2)}`,
170, 170,
); );
@@ -142,16 +154,17 @@ export class LightSensorDemoLayer implements Layer {
// 30 s trace of the reading (bright) and the driver's 5-sample peak (dim). // 30 s trace of the reading (bright) and the driver's 5-sample peak (dim).
// The axis label sits between the stats line and the chart, so the chart // The axis label sits between the stats line and the chart, so the chart
// starts a full text line lower than the stats. // starts a full text line lower than the stats.
const chartTop = 76 + small.lineHeight * 2 + 4; const chartTop = statsY + small.lineHeight * 2 + 4;
const bounds = { x: 20, y: chartTop, width: width - 40, height: height - chartTop - 34 }; const bounds = { x: left, y: chartTop, width: right - left, height: footerY - CHART_FOOTER_GAP - chartTop };
const maxValue = Math.max(...this.samples.map((sample) => Math.max(sample.value, sample.peak)), 10); const maxValue = Math.max(...this.samples.map((sample) => Math.max(sample.value, sample.peak)), 10);
const scale = roundUpScale(maxValue * 1.08); const scale = roundUpScale(maxValue * 1.08);
image.drawText(small, bounds.x, bounds.y - small.lineHeight - 2, `0–${(scale / 10).toFixed(0)} lux, last 30 s`, 120); image.drawText(small, bounds.x, bounds.y - small.lineHeight - 2, `0–${(scale / 10).toFixed(0)} lux, last 30 s`, 120);
drawTrace(image, this.samples, Date.now(), bounds, scale); // A window too short for the trace (a large font on the RayNeo iO) goes without.
if (bounds.width > 1 && bounds.height > 1) drawTrace(image, this.samples, Date.now(), bounds, scale);
image.drawText(small, 20, height - 16, `reports: ${this.reportCount}`, 110); image.drawText(small, left, footerY, `reports: ${this.reportCount}`, 110);
const back = `${GESTURE_DOUBLE_CLICK} back`; const back = `${GESTURE_DOUBLE_CLICK} back`;
image.drawText(small, width - 20 - small.measureText(back), height - 16, back, 110); image.drawText(small, right - small.measureText(back), footerY, back, 110);
return image; return image;
} }
+21 -17
View File
@@ -9,8 +9,6 @@ import { lineStep } from "../../ui/metrics";
import { developerAppUrlSetting } from "../../ui/dashboard-settings"; import { developerAppUrlSetting } from "../../ui/dashboard-settings";
import { cancelQrScan, isQrScannerAvailable, scanQrCode } from "../../native/qr-scan"; import { cancelQrScan, isQrScannerAvailable, scanQrCode } from "../../native/qr-scan";
const MARGIN = 20;
/** /**
* "Load app from URL": the glasses side of the phone text editor. Entering the * "Load app from URL": the glasses side of the phone text editor. Entering the
* page opens the editor on developerAppUrlSetting, the typed URL echoes here * page opens the editor on developerAppUrlSetting, the typed URL echoes here
@@ -44,27 +42,30 @@ export class LoadAppFromUrlLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); // The page's text fills the window inside the padding suggested for its
// edges: the title at the top, the hint line at the bottom.
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const step = lineStep(font); const step = lineStep(font);
const textWidth = width - 2 * MARGIN; const left = padding.left;
const textWidth = Math.max(0, width - padding.left - padding.right);
image.drawText(font, MARGIN, 8, "Load app from URL", 220); image.drawText(font, left, padding.top, "Load app from URL", 220);
let y = 8 + step + 6; let y = padding.top + step + 6;
image.drawText(font, MARGIN, y, "Type the app's URL in the phone app", 150); image.drawText(font, left, y, "Type the app's URL in the phone app", 150);
y += step; y += step;
image.drawText(font, MARGIN, y, "(or use voice input from the menu).", 150); image.drawText(font, left, y, "(or use voice input from the menu).", 150);
y += step + 8; y += step + 8;
const url = developerAppUrlSetting.get(); const url = developerAppUrlSetting.get();
for (const line of wrapText(font, url || "(empty)", textWidth).slice(0, 3)) { for (const line of wrapText(font, url || "(empty)", textWidth).slice(0, 3)) {
image.drawText(font, MARGIN, y, line, url ? 230 : 110); image.drawText(font, left, y, line, url ? 230 : 110);
y += step; y += step;
} }
if (this.error) { if (this.error) {
y += 4; y += 4;
for (const line of wrapText(font, this.error, textWidth).slice(0, 2)) { for (const line of wrapText(font, this.error, textWidth).slice(0, 2)) {
image.drawText(font, MARGIN, y, line, 150); image.drawText(font, left, y, line, 150);
y += step; y += step;
} }
} }
@@ -72,7 +73,7 @@ export class LoadAppFromUrlLayer implements Layer {
const footer = this.launching const footer = this.launching
? "Loading..." ? "Loading..."
: `${GESTURE_CLICK} load ${GESTURE_DOUBLE_CLICK} cancel`; : `${GESTURE_CLICK} load ${GESTURE_DOUBLE_CLICK} cancel`;
image.drawText(font, MARGIN, height - font.lineHeight - 12, footer, 110); image.drawText(font, left, height - padding.bottom - font.lineHeight, footer, 110);
return image; return image;
} }
@@ -145,19 +146,22 @@ export class LoadAppFromQrLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); // Laid out like the URL page: text inside the padding suggested for the
// window's edges, the hint line at the bottom.
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const step = lineStep(font); const step = lineStep(font);
const left = padding.left;
image.drawText(font, MARGIN, 8, "Load app from QR code", 220); image.drawText(font, left, padding.top, "Load app from QR code", 220);
let y = 8 + step + 6; let y = padding.top + step + 6;
for (const line of wrapText(font, this.status, width - 2 * MARGIN).slice(0, 5)) { for (const line of wrapText(font, this.status, Math.max(0, width - padding.left - padding.right)).slice(0, 5)) {
image.drawText(font, MARGIN, y, line, 170); image.drawText(font, left, y, line, 170);
y += step; y += step;
} }
const footer = this.busy ? `${GESTURE_DOUBLE_CLICK} back` : `${GESTURE_CLICK} scan again ${GESTURE_DOUBLE_CLICK} back`; const footer = this.busy ? `${GESTURE_DOUBLE_CLICK} back` : `${GESTURE_CLICK} scan again ${GESTURE_DOUBLE_CLICK} back`;
image.drawText(font, MARGIN, height - font.lineHeight - 12, footer, 110); image.drawText(font, left, height - padding.bottom - font.lineHeight, footer, 110);
return image; return image;
} }
+24 -16
View File
@@ -37,6 +37,8 @@ const STOCK_COUNTER_OFFSET = 204;
// Counter gaps at or beyond this are late/duplicate copies, not losses. // Counter gaps at or beyond this are late/duplicate copies, not losses.
const STOCK_LATE_GAP = 128; const STOCK_LATE_GAP = 128;
const LEVEL_FLOOR_DB = -90; const LEVEL_FLOOR_DB = -90;
/** Gap between the two temples' columns. */
const COLUMN_GAP = 16;
// wallMs (JS receipt time) windows the rates; arrivalMs (the session core's // wallMs (JS receipt time) windows the rates; arrivalMs (the session core's
// elapsed-realtime stamp, taken on the BLE thread) measures gaps without the // elapsed-realtime stamp, taken on the BLE thread) measures gaps without the
@@ -229,39 +231,45 @@ export class MicrophonesMonitorLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const line = font.lineHeight; const line = font.lineHeight;
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const nowMs = Date.now(); const nowMs = Date.now();
// The title line, the two columns and the footer line span the window
// inside the padding suggested for its edges.
const left = padding.left;
const titleY = padding.top;
const right = width - padding.right;
const footerY = height - padding.bottom - line;
image.drawText(font, 16, 5, "Microphones (passive)", 230); image.drawText(font, left, titleY, "Microphones (passive)", 230);
const capture = isFaceclawAudioCaptureActive() ? "Faceclaw capture: on" : "Faceclaw capture: off"; const capture = isFaceclawAudioCaptureActive() ? "Faceclaw capture: on" : "Faceclaw capture: off";
image.drawText(font, width - 16 - font.measureText(capture), 5, capture, 170); image.drawText(font, right - font.measureText(capture), titleY, capture, 170);
if (!this.communicator) { if (!this.communicator) {
image.drawText(font, 16, 5 + line * 2, "Glasses not connected.", 190); image.drawText(font, left, titleY + line * 2, "Glasses not connected.", 190);
image.drawText(font, 16, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110); image.drawText(font, left, footerY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image; return image;
} }
const gutter = 16; const columnWidth = Math.max(0, Math.floor((right - left - COLUMN_GAP) / 2));
const columnWidth = Math.floor((width - gutter * 3) / 2); const rightColumnX = left + columnWidth + COLUMN_GAP;
const stripHeight = 22; const stripHeight = 22;
const top = 5 + line + 6; const top = titleY + line + 6;
const bottom = height - 16 - stripHeight - 8; const bottom = footerY - stripHeight - 8;
this.paintArm(image, "L", "Left", gutter, top, columnWidth, bottom, nowMs); this.paintArm(image, "L", "Left", left, top, columnWidth, bottom, nowMs);
this.paintArm(image, "R", "Right", gutter * 2 + columnWidth, top, columnWidth, bottom, nowMs); this.paintArm(image, "R", "Right", rightColumnX, top, columnWidth, bottom, nowMs);
const stripY = height - 16 - stripHeight - 4; const stripY = footerY - stripHeight - 4;
const stripMax = Math.max(1, ...this.stats.L.buckets, ...this.stats.R.buckets); const stripMax = Math.max(1, ...this.stats.L.buckets, ...this.stats.R.buckets);
drawStrip(image, this.stats.L.buckets, gutter, stripY, columnWidth, stripHeight, stripMax); drawStrip(image, this.stats.L.buckets, left, stripY, columnWidth, stripHeight, stripMax);
drawStrip(image, this.stats.R.buckets, gutter * 2 + columnWidth, stripY, columnWidth, stripHeight, stripMax); drawStrip(image, this.stats.R.buckets, rightColumnX, stripY, columnWidth, stripHeight, stripMax);
const footer = this.unknownArmPackets > 0 const footer = this.unknownArmPackets > 0
? `last ${HISTORY_MS / 1000} s unattributed packets ${this.unknownArmPackets}` ? `last ${HISTORY_MS / 1000} s unattributed packets ${this.unknownArmPackets}`
: `packets per ${BUCKET_MS} ms, last ${HISTORY_MS / 1000} s`; : `packets per ${BUCKET_MS} ms, last ${HISTORY_MS / 1000} s`;
image.drawText(font, gutter, height - 16, footer, 110); image.drawText(font, left, footerY, footer, 110);
const back = `${GESTURE_DOUBLE_CLICK} back tap reset`; const back = `${GESTURE_DOUBLE_CLICK} back tap reset`;
image.drawText(font, width - gutter - font.measureText(back), height - 16, back, 110); image.drawText(font, right - font.measureText(back), footerY, back, 110);
return image; return image;
} }
+46 -21
View File
@@ -16,6 +16,14 @@ const HISTORY_MS = 60_000;
const MAX_SAMPLES = Math.ceil(HISTORY_MS / SAMPLE_INTERVAL_MS) + 2; const MAX_SAMPLES = Math.ceil(HISTORY_MS / SAMPLE_INTERVAL_MS) + 2;
/** Line brightness per memory series, headline first. */ /** Line brightness per memory series, headline first. */
const MEMORY_SHADES = [240, 155, 80]; const MEMORY_SHADES = [240, 155, 80];
/** The charts' heights where the window has room for them. */
const MEMORY_CHART_HEIGHT = 70;
const CPU_CHART_HEIGHT = 60;
/** Between the charts: a gap, then the CPU chart's label line. */
const CHART_GAP = 10;
const CHART_LABEL_HEIGHT = 16;
/** Least gap between the CPU chart and the footer line. */
const CHART_FOOTER_GAP = 4;
type ChartSample = ResourceSample & { cpuPercent: number }; type ChartSample = ResourceSample & { cpuPercent: number };
@@ -56,20 +64,26 @@ export class ResourceUsageLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const latest = this.samples[this.samples.length - 1]; const latest = this.samples[this.samples.length - 1];
// The title line, the charts and the footer line span the window inside
// the padding suggested for its edges; the rest is placed from the top.
const left = padding.left;
const top = padding.top;
const right = width - padding.right;
const footerY = height - padding.bottom - font.lineHeight;
image.drawText(font, 16, 5, "Resource usage — last minute", 230); image.drawText(font, left, top, "Resource usage — last minute", 230);
if (!latest) { if (!latest) {
image.drawText(font, 16, 30, this.sampleError || "Waiting for first sample…", 170); image.drawText(font, left, top + 25, this.sampleError || "Waiting for first sample…", 170);
image.drawText(font, 16, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110); image.drawText(font, left, footerY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image; return image;
} }
const cpuText = `CPU ${formatPercent(latest.cpuPercent)} ${latest.threads} threads`; const cpuText = `CPU ${formatPercent(latest.cpuPercent)} ${latest.threads} threads`;
image.drawText(font, width - 16 - font.measureText(cpuText), 5, cpuText, 200); image.drawText(font, right - font.measureText(cpuText), top, cpuText, 200);
image.drawText(font, 16, 21, this.sampleError || latest.status, this.sampleError ? 170 : 140); image.drawText(font, left, top + 16, this.sampleError || latest.status, this.sampleError ? 170 : 140);
const memorySeries = MEMORY_SERIES.map((label, index) => ({ const memorySeries = MEMORY_SERIES.map((label, index) => ({
label, label,
@@ -78,34 +92,44 @@ export class ResourceUsageLayer implements Layer {
})); }));
const memoryPeak = Math.max(...this.samples.flatMap((sample) => sample.memoryMb), 64); const memoryPeak = Math.max(...this.samples.flatMap((sample) => sample.memoryMb), 64);
const memoryScale = roundUp(memoryPeak * 1.08, 64); const memoryScale = roundUp(memoryPeak * 1.08, 64);
const legendY = top + 43;
const legendLeft = drawLegend( const legendLeft = drawLegend(
image, image,
font, font,
width, right,
48, legendY,
memorySeries.map((series) => [`${series.label} ${formatMb(series.value(latest))}`, series.shade] as const), memorySeries.map((series) => [`${series.label} ${formatMb(series.value(latest))}`, series.shade] as const),
); );
const scaleLabel = `Memory 0–${formatMb(memoryScale)}`; const scaleLabel = `Memory 0–${formatMb(memoryScale)}`;
const shortScaleLabel = `0–${formatMb(memoryScale)}`; const shortScaleLabel = `0–${formatMb(memoryScale)}`;
image.drawText( image.drawText(
font, font,
16, left,
48, legendY,
16 + font.measureText(scaleLabel) + 8 <= legendLeft ? scaleLabel : shortScaleLabel, left + font.measureText(scaleLabel) + 8 <= legendLeft ? scaleLabel : shortScaleLabel,
140, 140,
); );
drawChart(image, this.samples, latest.atMs, { x: 16, y: 64, width: width - 32, height: 70 }, memoryScale, memorySeries); // The charts shrink together where the window is too short for both
// above the footer line (the RayNeo iO's).
const chartsTop = legendY + CHART_LABEL_HEIGHT;
const room = footerY - CHART_FOOTER_GAP - chartsTop - CHART_GAP - CHART_LABEL_HEIGHT;
const fit = clamp(room / (MEMORY_CHART_HEIGHT + CPU_CHART_HEIGHT), 0, 1);
const memoryHeight = Math.floor(MEMORY_CHART_HEIGHT * fit);
const chartWidth = Math.max(0, right - left);
drawChart(image, this.samples, latest.atMs, { x: left, y: chartsTop, width: chartWidth, height: memoryHeight }, memoryScale, memorySeries);
const cpuPeak = Math.max(...this.samples.map((sample) => sample.cpuPercent), 100); const cpuPeak = Math.max(...this.samples.map((sample) => sample.cpuPercent), 100);
const cpuScale = roundUp(cpuPeak * 1.08, 25); const cpuScale = roundUp(cpuPeak * 1.08, 25);
image.drawText(font, 16, 144, `CPU 0–${Math.round(cpuScale)}% (one core)`, 140); const cpuLabelY = chartsTop + memoryHeight + CHART_GAP;
drawChart(image, this.samples, latest.atMs, { x: 16, y: 160, width: width - 32, height: 60 }, cpuScale, [ image.drawText(font, left, cpuLabelY, `CPU 0–${Math.round(cpuScale)}% (one core)`, 140);
{ value: (sample) => sample.cpuPercent, shade: 220 }, drawChart(image, this.samples, latest.atMs,
]); { x: left, y: cpuLabelY + CHART_LABEL_HEIGHT, width: chartWidth, height: Math.floor(CPU_CHART_HEIGHT * fit) }, cpuScale, [
{ value: (sample) => sample.cpuPercent, shade: 220 },
]);
image.drawText(font, 16, height - 16, `-60s`, 80); image.drawText(font, left, footerY, `-60s`, 80);
const nowLabel = `now`; const nowLabel = `now`;
image.drawText(font, width - 16 - font.measureText(nowLabel), height - 16, nowLabel, 110); image.drawText(font, right - font.measureText(nowLabel), footerY, nowLabel, 110);
return image; return image;
} }
@@ -148,6 +172,7 @@ function drawChart(
scale: number, scale: number,
series: readonly Series[], series: readonly Series[],
): void { ): void {
if (bounds.width < 2 || bounds.height < 2) return;
image.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 45); image.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 45);
const midY = bounds.y + Math.round((bounds.height - 1) / 2); const midY = bounds.y + Math.round((bounds.height - 1) / 2);
image.drawLine(bounds.x + 1, midY, bounds.x + bounds.width - 2, midY, 24); image.drawLine(bounds.x + 1, midY, bounds.x + bounds.width - 2, midY, 24);
@@ -167,16 +192,16 @@ function drawChart(
} }
} }
/** Right-aligned legend of line swatches and labels; returns its left edge. */ /** Legend of line swatches and labels, right-aligned to end at `right`; returns its left edge. */
function drawLegend( function drawLegend(
image: GrayImage, image: GrayImage,
font: ReturnType<typeof getDefaultSmallFont>, font: ReturnType<typeof getDefaultSmallFont>,
width: number, right: number,
y: number, y: number,
entries: ReadonlyArray<readonly [string, number]>, entries: ReadonlyArray<readonly [string, number]>,
): number { ): number {
const totalWidth = entries.reduce((sum, [label]) => sum + font.measureText(label) + 14, 0); const totalWidth = entries.reduce((sum, [label]) => sum + font.measureText(label) + 14, 0);
const left = width - 16 - totalWidth; const left = right - totalWidth;
let x = left; let x = left;
for (const [label, shade] of entries) { for (const [label, shade] of entries) {
image.drawLine(x, y + 6, x + 8, y + 6, shade); image.drawLine(x, y + 6, x + 8, y + 6, shade);
+17 -10
View File
@@ -18,8 +18,10 @@ import {
} from "../../native/ring-status"; } from "../../native/ring-status";
const POLL_INTERVAL_MS = 1_000; const POLL_INTERVAL_MS = 1_000;
const LEFT_X = 16; /** The title sits this far in from the left edge of the rows and buttons under it. */
const VALUE_X = 130; const TITLE_INDENT = 2;
/** A row's value column, from its label's left edge. */
const VALUE_OFFSET_X = 114;
const BUTTON_GAP = 8; const BUTTON_GAP = 8;
type Row = { label: string; value: string; dim?: boolean }; type Row = { label: string; value: string; dim?: boolean };
@@ -102,26 +104,31 @@ export class RingStatusLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const lineStep = font.lineHeight + 2; const lineStep = font.lineHeight + 2;
const buttonHeight = font.lineHeight + 8; const buttonHeight = font.lineHeight + 8;
const buttonTop = height - buttonHeight - 6; // The rows and the button strip span the window inside the padding
// suggested for its side edges; the title sits at the top edge's and the
// buttons' outlines at the bottom edge's.
const left = padding.left;
const buttonTop = height - padding.bottom - buttonHeight;
image.drawText(font, 18, 10, "Ring status", 230); image.drawText(font, left + TITLE_INDENT, padding.top, "Ring status", 230);
let y = 10 + lineStep + 4; let y = padding.top + lineStep + 4;
const rows = this.rows(); const rows = this.rows();
if (this.notice) rows.push({ label: "", value: this.notice }); if (this.notice) rows.push({ label: "", value: this.notice });
for (const row of rows) { for (const row of rows) {
if (y + font.lineHeight > buttonTop - 4) break; if (y + font.lineHeight > buttonTop - 4) break;
image.drawText(font, LEFT_X, y, row.label, row.dim ? 100 : 150); image.drawText(font, left, y, row.label, row.dim ? 100 : 150);
image.drawText(font, VALUE_X, y, row.value, row.dim ? 120 : 220); image.drawText(font, left + VALUE_OFFSET_X, y, row.value, row.dim ? 120 : 220);
y += lineStep; y += lineStep;
} }
const buttonWidth = Math.floor((width - 2 * LEFT_X - BUTTON_GAP * (BUTTONS.length - 1)) / BUTTONS.length); const buttonWidth = Math.max(0,
Math.floor((width - padding.left - padding.right - BUTTON_GAP * (BUTTONS.length - 1)) / BUTTONS.length));
BUTTONS.forEach((button, index) => { BUTTONS.forEach((button, index) => {
const x = LEFT_X + index * (buttonWidth + BUTTON_GAP); const x = left + index * (buttonWidth + BUTTON_GAP);
const selected = index === this.selected; const selected = index === this.selected;
if (selected) image.fillRoundedRect(x, buttonTop, buttonWidth, buttonHeight, 40, 4); if (selected) image.fillRoundedRect(x, buttonTop, buttonWidth, buttonHeight, 40, 4);
image.drawRoundedRect(x, buttonTop, buttonWidth, buttonHeight, selected ? 200 : 70, 4); image.drawRoundedRect(x, buttonTop, buttonWidth, buttonHeight, selected ? 200 : 70, 4);
+15 -14
View File
@@ -3,7 +3,7 @@ import { fontSelectionLabel, getDefaultSmallFont, getUiFontSelection } from "../
import { GrayImage, type UiFont } from "../../graphics/image"; import { GrayImage, type UiFont } from "../../graphics/image";
import { type InputEvent } from "../../ui/gestures"; import { type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
import { MenuLayer, type MenuLayout } from "../../ui/menu"; import { MenuLayer, type MenuPageLayout } from "../../ui/menu";
/** /**
* Unicode test: sample texts chosen to exercise text-rendering features that * Unicode test: sample texts chosen to exercise text-rendering features that
@@ -175,9 +175,6 @@ export const UNICODE_SAMPLES: readonly UnicodeSample[] = [
}, },
]; ];
const MARGIN_X = 18;
const TITLE_Y = 8;
const FOOTER_MARGIN = 20;
const BODY_GAP = 6; const BODY_GAP = 6;
/** /**
@@ -196,32 +193,36 @@ export class UnicodeSampleLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); // The title and note stay put at the top and the footer line at the
// bottom, inside the padding suggested for the window's edges; the text
// pages between them, so it needs no padding of its own.
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const textWidth = width - 2 * MARGIN_X; const left = padding.left;
const textWidth = Math.max(0, width - padding.left - padding.right);
image.drawText(font, MARGIN_X, TITLE_Y, truncateText(font, this.sample.label, textWidth), 220); image.drawText(font, left, padding.top, truncateText(font, this.sample.label, textWidth), 220);
const noteY = TITLE_Y + font.lineHeight; const noteY = padding.top + font.lineHeight;
const noteLines = wrapText(font, this.sample.exercises, textWidth); const noteLines = wrapText(font, this.sample.exercises, textWidth);
for (let i = 0; i < noteLines.length; i++) { for (let i = 0; i < noteLines.length; i++) {
image.drawText(font, MARGIN_X, noteY + i * font.lineHeight, noteLines[i]!, 120); image.drawText(font, left, noteY + i * font.lineHeight, noteLines[i]!, 120);
} }
const bodyY = noteY + noteLines.length * font.lineHeight + BODY_GAP; const bodyY = noteY + noteLines.length * font.lineHeight + BODY_GAP;
const footerY = height - FOOTER_MARGIN; const footerY = height - padding.bottom - font.lineHeight;
this.bodyLineCount = Math.max(1, Math.floor((footerY - bodyY) / font.lineHeight)); this.bodyLineCount = Math.max(1, Math.floor((footerY - bodyY) / font.lineHeight));
const lines = this.getLines(font, textWidth); const lines = this.getLines(font, textWidth);
this.clampScroll(lines.length); this.clampScroll(lines.length);
const visible = lines.slice(this.firstLine, this.firstLine + this.bodyLineCount); const visible = lines.slice(this.firstLine, this.firstLine + this.bodyLineCount);
for (let i = 0; i < visible.length; i++) { for (let i = 0; i < visible.length; i++) {
image.drawText(font, MARGIN_X, bodyY + i * font.lineHeight, visible[i]!, 235); image.drawText(font, left, bodyY + i * font.lineHeight, visible[i]!, 235);
} }
const page = Math.floor(this.firstLine / this.pageStep()) + 1; const page = Math.floor(this.firstLine / this.pageStep()) + 1;
image.drawText(font, MARGIN_X, footerY, `Page ${page}/${this.pageCount(lines.length)}`, 110); image.drawText(font, left, footerY, `Page ${page}/${this.pageCount(lines.length)}`, 110);
const fontLabel = fontSelectionLabel(getUiFontSelection()); const fontLabel = fontSelectionLabel(getUiFontSelection());
image.drawText(font, width - MARGIN_X - font.measureText(fontLabel), footerY, fontLabel, 110); image.drawText(font, width - padding.right - font.measureText(fontLabel), footerY, fontLabel, 110);
return image; return image;
} }
@@ -271,7 +272,7 @@ export class UnicodeSampleLayer implements Layer {
} }
/** The language list; selecting a row opens its sample. */ /** The language list; selecting a row opens its sample. */
export function unicodeTestMenu(layout: MenuLayout): MenuLayer { export function unicodeTestMenu(layout: MenuPageLayout): MenuLayer {
return new MenuLayer( return new MenuLayer(
"Unicode test", "Unicode test",
UNICODE_SAMPLES.map((sample) => ({ UNICODE_SAMPLES.map((sample) => ({
+24 -14
View File
@@ -4,7 +4,7 @@
* makes the content area exactly the 576x288 surface EvenHub apps expect. * makes the content area exactly the 576x288 surface EvenHub apps expect.
*/ */
import { GrayImage } from "../../graphics/image"; import { GrayImage } from "../../graphics/image";
import { EVENHUB_SCREEN_WIDTH } from "./compositor"; import { EVENHUB_SCREEN_WIDTH, EVENHUB_SCREEN_HEIGHT } from "./compositor";
import { directionalFallback, isDirectionalInput, type InputEvent } from "../../ui/gestures"; import { directionalFallback, isDirectionalInput, type InputEvent } from "../../ui/gestures";
import { type Layer, type LayerContext } from "../../ui/layers"; import { type Layer, type LayerContext } from "../../ui/layers";
import { import {
@@ -26,21 +26,26 @@ class EvenHubAppLayer implements Layer {
* extension's source field should see that they came from the watch. * extension's source field should see that they came from the watch.
*/ */
readonly acceptsDirectional = true; readonly acceptsDirectional = true;
private tallCanvas = false;
constructor(private readonly session: EvenHubSession) {} constructor(private readonly session: EvenHubSession) {}
setTallCanvas(tall: boolean): void {
this.tallCanvas = tall;
}
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const size = ctx.stack.getBaseSize(); const size = ctx.stack.getBaseSize();
// EvenHub apps lay out for the stock 576-wide surface. In the Full // Host full screen hides chrome; it does not enlarge the stock app canvas.
// Screen display mode the window is 640 wide; paint at stock width and // Only the app's explicit Faceclaw extended-layout request opts into height.
// centre it rather than leaving all the slack on the right. const canvas = { width: EVENHUB_SCREEN_WIDTH, height: this.tallCanvas ? size.height : EVENHUB_SCREEN_HEIGHT };
if (size.width > EVENHUB_SCREEN_WIDTH) { const content = this.session.paint(canvas, ctx.stack.isFocused());
const content = this.session.paint({ width: EVENHUB_SCREEN_WIDTH, height: size.height }, ctx.stack.isFocused()); if (size.width === canvas.width && size.height === canvas.height) return content;
const image = new GrayImage(size.width, size.height, 0); const image = new GrayImage(size.width, size.height, 0);
content.composeInto(image, Math.floor((size.width - EVENHUB_SCREEN_WIDTH) / 2), 0); // Clip text to its logical canvas before placing it in the larger host window.
return image; image.bitBlt(content.withDrawsBaked(), Math.max(0, Math.floor((size.width - canvas.width) / 2)),
} Math.max(0, Math.floor((size.height - canvas.height) / 2)));
return this.session.paint(size, ctx.stack.isFocused()); return image;
} }
handleInput(event: InputEvent): void { handleInput(event: InputEvent): void {
@@ -62,6 +67,7 @@ export function createEvenHubWindow(
requestShellRender: () => void, requestShellRender: () => void,
): InProcessWindow { ): InProcessWindow {
const fallbackIcon = windowIcon("package", session.manifest.name.charAt(0).toUpperCase() || "E"); const fallbackIcon = windowIcon("package", session.manifest.name.charAt(0).toUpperCase() || "E");
const appLayer = new EvenHubAppLayer(session);
const created = createInProcessWindow({ const created = createInProcessWindow({
appId, appId,
windowId, windowId,
@@ -90,10 +96,11 @@ export function createEvenHubWindow(
})), })),
// Glasses-first: the app runs without the phone showing it; this reveals // Glasses-first: the app runs without the phone showing it; this reveals
// its phone UI (config pages, etc.) over the dashboard on demand. // its phone UI (config pages, etc.) over the dashboard on demand.
{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } }, ...(session.manifest.packageId === "dev.guillaume.evenanchor" && session.contextMenuItems().length > 0
? [] : [{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } }]),
], ],
actions: options.actions, actions: options.actions,
baseLayer: new EvenHubAppLayer(session), baseLayer: appLayer,
submitFrame: options.submitFrame, submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible, setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface, removeSurface: options.removeSurface,
@@ -111,7 +118,10 @@ export function createEvenHubWindow(
pushOverlay: (layer) => created.stack.push(layer), pushOverlay: (layer) => created.stack.push(layer),
// The extended layout uses the full 576x452 app area ("max"); stock apps // The extended layout uses the full 576x452 app area ("max"); stock apps
// stay in the 576x288 band ("medium"). // stay in the 576x288 band ("medium").
setTallCanvas: (tall) => created.setHeightMode(tall ? "max" : "medium"), setTallCanvas: (tall) => {
appLayer.setTallCanvas(tall);
created.setHeightMode(tall ? "max" : "medium");
},
setAttention: (attention) => shell.setWindowAttention(windowId, attention), setAttention: (attention) => shell.setWindowAttention(windowId, attention),
// Only while the app listens for text: otherwise the shell's Type Into App // Only while the app listens for text: otherwise the shell's Type Into App
// destinations (voice dialog, phone keyboard, watch) would send into a void. // destinations (voice dialog, phone keyboard, watch) would send into a void.
+7 -7
View File
@@ -6,8 +6,8 @@
* *
* Glasses-first: launching does NOT take over the phone screen. The phone * Glasses-first: launching does NOT take over the phone screen. The phone
* stays on the Faceclaw dashboard; an app's phone UI is shown on demand * stays on the Faceclaw dashboard; an app's phone UI is shown on demand
* (window menu -> "Show phone UI", or the app-icon button in the phone's * (window menu -> "Show phone UI", or the app-icon button in the bar under the
* action bar while the app is foreground on the glasses), overlaying the * phone's mirror while the app is foreground on the glasses), overlaying the
* dashboard, and the Back button or the overlay's close button returns to it. * dashboard, and the Back button or the overlay's close button returns to it.
* Apps are kept alive until explicitly closed (no memory eviction yet). * Apps are kept alive until explicitly closed (no memory eviction yet).
*/ */
@@ -40,14 +40,14 @@ type RunningApp = {
packageId: string; packageId: string;
session: EvenHubSession; session: EvenHubSession;
webView: EvenHubWebView; webView: EvenHubWebView;
/** The app's icon for the phone action bar, rendered on first use. */ /** The app's icon for the phone's button bar, rendered on first use. */
phoneIcon?: ImageSource | null; phoneIcon?: ImageSource | null;
}; };
/** The phone action bar's button for opening the foreground app's phone UI. */ /** The button under the phone's mirror that opens the foreground app's phone UI. */
export type PhoneUiButton = { windowId: string; title: string; icon: ImageSource | null }; export type PhoneUiButton = { windowId: string; title: string; icon: ImageSource | null };
/** Pixel size the action-bar icon is rendered at (~21dp at xxhdpi). */ /** Pixel size the button's icon is rendered at (~21dp at xxhdpi; shown at 20dp). */
const PHONE_ICON_SIZE = 63; const PHONE_ICON_SIZE = 63;
const running = new Map<string, RunningApp>(); const running = new Map<string, RunningApp>();
@@ -244,7 +244,7 @@ export function hidePhone(): void {
/** /**
* The foreground glasses window, when it is an EvenHub app whose phone UI * The foreground glasses window, when it is an EvenHub app whose phone UI
* isn't showing: the phone action bar then offers a button to show it. * isn't showing: the bar under the phone's mirror then offers a button to show it.
*/ */
export function phoneUiButton(): PhoneUiButton | null { export function phoneUiButton(): PhoneUiButton | null {
const window = shell.foregroundWindow(); const window = shell.foregroundWindow();
@@ -252,7 +252,7 @@ export function phoneUiButton(): PhoneUiButton | null {
if (!window || !app || phoneShownWindowId === app.windowId) return null; if (!window || !app || phoneShownWindowId === app.windowId) return null;
if (app.phoneIcon === undefined) { if (app.phoneIcon === undefined) {
// The same artwork as the glasses sidebar (installed icon, else the // The same artwork as the glasses sidebar (installed icon, else the
// generic package icon), drawn white. // generic package icon), drawn white; the button's stylesheet tints it.
const image = new GrayImage(PHONE_ICON_SIZE, PHONE_ICON_SIZE, 0); const image = new GrayImage(PHONE_ICON_SIZE, PHONE_ICON_SIZE, 0);
window.drawIcon(image, 0, 0, PHONE_ICON_SIZE); window.drawIcon(image, 0, 0, PHONE_ICON_SIZE);
app.phoneIcon = grayImageToWhiteIconSource(image); app.phoneIcon = grayImageToWhiteIconSource(image);
+22 -17
View File
@@ -16,7 +16,11 @@ import { cleanError, installStoreApp } from "./store-install";
import { describeUpdate } from "./updates"; import { describeUpdate } from "./updates";
import { lineStep, listRowHeight } from "../../ui/metrics"; import { lineStep, listRowHeight } from "../../ui/metrics";
const X = 18; /** How far an action row's highlight box overhangs the column of text it belongs to, on each side. */
const ACTION_BOX_OVERHANG = 5;
/** The side-by-side layout: the action menu's label column, and the gap between the details and its box. */
const SIDE_MENU_WIDTH = 150;
const SIDE_MENU_GAP = 9;
type DetailAction = "about" | "whats-new" | "primary"; type DetailAction = "about" | "whats-new" | "primary";
const ACTIONS: readonly DetailAction[] = ["about", "whats-new", "primary"]; const ACTIONS: readonly DetailAction[] = ["about", "whats-new", "primary"];
@@ -60,10 +64,15 @@ export class EvenHubStoreDetailLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
if (!this.detailPromise) void this.ensureDetail(ctx); if (!this.detailPromise) void this.ensureDetail(ctx);
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const step = lineStep(font); const step = lineStep(font);
const actionRowH = listRowHeight(font) + 4; const actionRowH = listRowHeight(font) + 4;
// The action rows' highlight boxes are the outermost thing drawn toward
// the edges they reach, so they sit at the padding suggested for those
// edges; the details keep to the text column inside the boxes' overhang.
const textX = padding.left + ACTION_BOX_OVERHANG;
const fullTextWidth = Math.max(0, width - padding.left - padding.right - 2 * ACTION_BOX_OVERHANG);
const installed = getInstalledEvenHubApp(this.app.packageId); const installed = getInstalledEvenHubApp(this.app.packageId);
this.primaryLabel = this.working ? "Installing..." : this.primaryActionLabel(installed); this.primaryLabel = this.working ? "Installing..." : this.primaryActionLabel(installed);
@@ -109,26 +118,22 @@ export class EvenHubStoreDetailLayer implements Layer {
// Stacked layout (details full-width, actions at the bottom) when it // Stacked layout (details full-width, actions at the bottom) when it
// fits; otherwise the actions become a narrow top-right menu and the // fits; otherwise the actions become a narrow top-right menu and the
// details flow down a left column beside it. // details flow down a left column beside it.
const stackedActionTop = height - 6 - ACTIONS.length * actionRowH; const stackedActionTop = height - padding.bottom - ACTIONS.length * actionRowH;
const stacked = 8 + linesHeight(buildLines(width - X * 2)) + 6 <= stackedActionTop; const stacked = padding.top + linesHeight(buildLines(fullTextWidth)) + 6 <= stackedActionTop;
const menuW = 150; const sideBoxWidth = SIDE_MENU_WIDTH + 2 * ACTION_BOX_OVERHANG;
const menuX = width - menuW - 12; const sideBoxX = width - padding.right - sideBoxWidth;
const textWidth = stacked ? width - X * 2 : menuX - X - 14; const textWidth = stacked ? fullTextWidth : Math.max(0, sideBoxX - SIDE_MENU_GAP - textX);
let y = 8; let y = padding.top;
for (const line of buildLines(textWidth)) { for (const line of buildLines(textWidth)) {
image.drawText(font, X, y, line.text, line.value); image.drawText(font, textX, y, line.text, line.value);
y += step + line.gapAfter; y += step + line.gapAfter;
} }
const actionX = stacked ? X : menuX; const actionBox = stacked
const actionW = stacked ? textWidth : menuW; ? { x: padding.left, y: stackedActionTop, width: fullTextWidth + 2 * ACTION_BOX_OVERHANG }
const actionTop = stacked ? stackedActionTop : 8; : { x: sideBoxX, y: padding.top, width: sideBoxWidth };
this.actions.paint( this.actions.paint(image, { ...actionBox, height: ACTIONS.length * actionRowH - 1 }, ctx.stack.isFocused());
image,
{ x: actionX - 5, y: actionTop, width: actionW + 10, height: ACTIONS.length * actionRowH - 1 },
ctx.stack.isFocused(),
);
return image; return image;
} }
+65 -33
View File
@@ -14,15 +14,37 @@ import { EvenHubStoreDetailLayer, type EvenHubStoreDetailOptions } from "./store
import { cleanError, installStoreApp } from "./store-install"; import { cleanError, installStoreApp } from "./store-install";
import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates"; import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates";
import { lineStep } from "../../ui/metrics"; import { lineStep } from "../../ui/metrics";
import type { Viewport } from "../../ui/viewport";
import { isEvenHubStoreAvailable } from "./glasses-compat"; import { isEvenHubStoreAvailable } from "./glasses-compat";
const LIST_X = 18; /** Horizontal inset of a row's text from its highlight box; the header's text lines up with it. */
const ROW_TEXT_INSET = 6;
/** Horizontal gap between tab labels. */ /** Horizontal gap between tab labels. */
const TAB_GAP = 18; const TAB_GAP = 18;
/** How far a focused tab's highlight box reaches past its label, sideways and above/below. */
const TAB_HIGHLIGHT_PAD_X = 6;
const TAB_HIGHLIGHT_PAD_Y = 3;
/** Room kept right of the rows for the scrollbar, and the bar's own width. */
const SCROLLBAR_GUTTER = 6;
const SCROLLBAR_WIDTH = 3;
/** Header: title + tabs line, then the status/subtitle line, then a small gap. */ /**
function headerHeight(font: UiFont): number { * Where the header sits in a viewport. Its text shares a column with the
return 8 + lineStep(font) + font.lineHeight + 6; * rows' text, whose highlight boxes start at the left edge's padding. The
* outermost thing it draws toward the top is a focused tab's highlight box,
* so that box sits at the top edge's padding and the title line follows
* from it. `bottom` is where the header ends: title + tabs line, then the
* status/subtitle line, then a small gap.
*/
function headerLayout(viewport: Viewport, font: UiFont): { textX: number; textWidth: number; titleY: number; bottom: number } {
const { width, padding } = viewport;
const titleY = padding.top + TAB_HIGHLIGHT_PAD_Y;
return {
textX: padding.left + ROW_TEXT_INSET,
textWidth: Math.max(0, width - padding.left - padding.right - 2 * ROW_TEXT_INSET),
titleY,
bottom: titleY + lineStep(font) + font.lineHeight + 6,
};
} }
/** Row pitch of the two-line app list (title + detail), including the 2px gap between highlights. */ /** Row pitch of the two-line app list (title + detail), including the 2px gap between highlights. */
@@ -119,8 +141,8 @@ function emptyTab(): TabState {
draw: ({ image, item, x, y, width }) => { draw: ({ image, item, x, y, width }) => {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { title, detail, titleValue } = rowText(item); const { title, detail, titleValue } = rowText(item);
const textX = x + 6; const textX = x + ROW_TEXT_INSET;
const textW = width - 12; const textW = width - 2 * ROW_TEXT_INSET;
image.drawText(font, textX, y + 2, truncateText(font, title, textW), titleValue); image.drawText(font, textX, y + 2, truncateText(font, title, textW), titleValue);
image.drawText(font, textX, y + 2 + lineStep(font), truncateText(font, detail, textW), 115); image.drawText(font, textX, y + 2 + lineStep(font), truncateText(font, detail, textW), 115);
}, },
@@ -198,83 +220,93 @@ export class EvenHubStoreLayer implements Layer {
} }
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const { width, height, padding } = viewport;
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const headerH = headerHeight(font); const { textX, textWidth, titleY, bottom: headerBottom } = headerLayout(viewport, font);
image.drawText(font, LIST_X, 8, "EvenHub", 220); image.drawText(font, textX, titleY, "EvenHub", 220);
if (this.showingLogin) { if (this.showingLogin) {
image.drawText(font, LIST_X, 8 + lineStep(font), truncateText(font, this.loginStatus, width - LIST_X * 2), 125); image.drawText(font, textX, titleY + lineStep(font), truncateText(font, this.loginStatus, textWidth), 125);
const message = this.loginBusy const message = this.loginBusy
? "Signing in..." ? "Signing in..."
: "Enter your Even account email and password in the phone app."; : "Enter your Even account email and password in the phone app.";
for (const [index, line] of wrapText(font, message, width - LIST_X * 2).entries()) { for (const [index, line] of wrapText(font, message, textWidth).entries()) {
image.drawText(font, LIST_X, headerH + 16 + index * lineStep(font), line, 190); image.drawText(font, textX, headerBottom + 16 + index * lineStep(font), line, 190);
} }
image.drawText(font, LIST_X, height - font.lineHeight - 4, `${GESTURE_CLICK} log in`, 105); image.drawText(font, textX, height - padding.bottom - font.lineHeight, `${GESTURE_CLICK} log in`, 105);
return image; return image;
} }
this.paintTabs(image, font, ctx); this.paintTabs(image, font, ctx, textX, titleY);
const tab = this.tabs[this.activeTab]; const tab = this.tabs[this.activeTab];
const subtitle = tab.status || this.subtitle(this.activeTab, tab); const subtitle = tab.status || this.subtitle(this.activeTab, tab);
image.drawText(font, LIST_X, 8 + lineStep(font), truncateText(font, subtitle, width - LIST_X * 2), 125); image.drawText(font, textX, titleY + lineStep(font), truncateText(font, subtitle, textWidth), 125);
if (tab.rows.length === 0) { if (tab.rows.length === 0) {
const message = tab.loading ? "Loading..." : this.emptyMessage(this.activeTab, tab); const message = tab.loading ? "Loading..." : this.emptyMessage(this.activeTab, tab);
for (const [index, line] of wrapText(font, message, width - LIST_X * 2).slice(0, 3).entries()) { for (const [index, line] of wrapText(font, message, textWidth).slice(0, 3).entries()) {
image.drawText(font, LIST_X, headerH + 22 + index * lineStep(font), line, 190); image.drawText(font, textX, headerBottom + 22 + index * lineStep(font), line, 190);
} }
return image; return image;
} }
if (height <= headerBottom) return image;
const rowH = storeRowHeight(font); // The header stays put, so the list starts right under it with no
const visibleRows = Math.max(1, Math.floor((height - headerH - 4) / rowH)); // padding of its own there. It scrolls, so it runs to the window's
// bottom edge, the padding suggested for that edge inside it: the last
// row keeps clear of a border there, and a row cut off for scrolling
// meets the edge rather than a blank strip. The scrollbar keeps inside
// the padding, in a gutter the rows leave free.
const listFocused = ctx.stack.isFocused() && this.focus === "list"; const listFocused = ctx.stack.isFocused() && this.focus === "list";
const menu = tabMenu(tab); const menu = tabMenu(tab);
const rowsWidth = Math.max(0, width - padding.left - padding.right - SCROLLBAR_GUTTER);
menu.paint( menu.paint(
image, image,
{ x: LIST_X - 6, y: headerH, width: width - LIST_X * 2 + 12, height: visibleRows * rowH - 2 }, { x: padding.left, y: headerBottom, width: rowsWidth, height: height - headerBottom, padTop: 0, padBottom: padding.bottom },
listFocused, listFocused,
); );
menu.drawScrollbar(image, width - 5, headerH, visibleRows * rowH - 3); menu.drawScrollbar(image, width - padding.right - SCROLLBAR_WIDTH, headerBottom,
Math.max(0, height - padding.bottom - headerBottom));
return image; return image;
} }
/** The notice that replaces the store when the paired glasses can't use it. */ /** The notice that replaces the store when the paired glasses can't use it. */
private paintUnavailable(ctx: LayerContext): GrayImage { private paintUnavailable(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(viewport.width, viewport.height, 0);
image.drawText(font, LIST_X, 8, "EvenHub", 220); const { textX, textWidth, titleY, bottom: headerBottom } = headerLayout(viewport, font);
image.drawText(font, textX, titleY, "EvenHub", 220);
if (this.unavailablePackageName) { if (this.unavailablePackageName) {
const status = `${this.unavailablePackageName}'s package is missing.`; const status = `${this.unavailablePackageName}'s package is missing.`;
image.drawText(font, LIST_X, 8 + lineStep(font), truncateText(font, status, width - LIST_X * 2), 125); image.drawText(font, textX, titleY + lineStep(font), truncateText(font, status, textWidth), 125);
} }
const message = "Using the Even Realities app store requires Even Realities glasses."; const message = "Using the Even Realities app store requires Even Realities glasses.";
for (const [index, line] of wrapText(font, message, width - LIST_X * 2).entries()) { for (const [index, line] of wrapText(font, message, textWidth).entries()) {
image.drawText(font, LIST_X, headerHeight(font) + 16 + index * lineStep(font), line, 190); image.drawText(font, textX, headerBottom + 16 + index * lineStep(font), line, 190);
} }
return image; return image;
} }
/** Tab labels to the right of the title; the active one is bright and underlined. */ /** Tab labels to the right of the title (at titleX, titleY); the active one is bright and underlined. */
private paintTabs(image: GrayImage, font: UiFont, ctx: LayerContext): void { private paintTabs(image: GrayImage, font: UiFont, ctx: LayerContext, titleX: number, titleY: number): void {
const tabsFocused = ctx.stack.isFocused() && this.focus === "tabs"; const tabsFocused = ctx.stack.isFocused() && this.focus === "tabs";
let x = LIST_X + font.measureText("EvenHub") + 28; let x = titleX + font.measureText("EvenHub") + 28;
for (const tab of TABS) { for (const tab of TABS) {
const label = this.tabLabel(tab.id); const label = this.tabLabel(tab.id);
const w = font.measureText(label); const w = font.measureText(label);
const active = tab.id === this.activeTab; const active = tab.id === this.activeTab;
if (active) { if (active) {
if (tabsFocused) { if (tabsFocused) {
drawSelectionHighlight(image, x - 6, 5, w + 12, font.lineHeight + 6, true, 4); drawSelectionHighlight(image, x - TAB_HIGHLIGHT_PAD_X, titleY - TAB_HIGHLIGHT_PAD_Y,
w + 2 * TAB_HIGHLIGHT_PAD_X, font.lineHeight + 2 * TAB_HIGHLIGHT_PAD_Y, true, 4);
} else { } else {
image.fillRect(x, 8 + font.lineHeight + 1, w, 1, 150); image.fillRect(x, titleY + font.lineHeight + 1, w, 1, 150);
} }
} }
image.drawText(font, x, 8, label, active ? 235 : 120); image.drawText(font, x, titleY, label, active ? 235 : 120);
x += w + TAB_GAP; x += w + TAB_GAP;
} }
} }
+34 -24
View File
@@ -19,13 +19,21 @@ import {
import { directionalFallback, type InputEvent } from "../../ui/gestures"; import { directionalFallback, type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
const LIST_X = 20;
/** List view: the selection box extends this far left and right of the row text. */ /** List view: the selection box extends this far left and right of the row text. */
const LIST_HIGHLIGHT_PAD = 6; const LIST_HIGHLIGHT_PAD = 6;
/** Header text: how far in from the rows' sides, which lines it up with list-row text. */
const HEADER_INSET_X = LIST_HIGHLIGHT_PAD;
/** Between the header's title and the path after it. */
const HEADER_PATH_GAP = 14;
/** Under the header's line, before the rows. */
const HEADER_GAP = 2;
/** Header: one line holding both the title and the current path. */ /**
function headerHeight(font: UiFont): number { * Bottom of the header: one line holding both the title and the current
return 10 + font.lineHeight; * path, below the padding suggested for the window's top edge.
*/
function headerBottom(font: UiFont, paddingTop: number): number {
return paddingTop + font.lineHeight + HEADER_GAP;
} }
export type FilesViewMode = "icons" | "list"; export type FilesViewMode = "icons" | "list";
@@ -147,35 +155,37 @@ export class FileBrowserLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
// The rows (grid bands, list selection boxes) span the window inside the
// padding suggested for its sides.
const rowsX = padding.left;
const rowsWidth = Math.max(0, width - padding.left - padding.right);
image.drawText(font, 20, 8, "Files", 220); const titleX = rowsX + HEADER_INSET_X;
image.drawText(font, titleX, padding.top, "Files", 220);
const pathLabel = this.location === null ? "Places" : this.location; const pathLabel = this.location === null ? "Places" : this.location;
const pathX = 20 + font.measureText("Files") + 14; const pathX = titleX + font.measureText("Files") + HEADER_PATH_GAP;
image.drawText(font, pathX, 8, truncateLeft(font, pathLabel, width - pathX - 20), 130); image.drawText(font, pathX, padding.top, truncateLeft(font, pathLabel, rowsX + rowsWidth - HEADER_INSET_X - pathX), 130);
if (filesViewModeSetting.get() === "list") { // The header stays put and the rows scroll under it, as far as the
this.paintList(image, font, ctx); // window's bottom edge: the padding suggested for that edge goes inside
// the scrolled content, so the last row keeps clear of a border there
// and a row cut off for scrolling meets it rather than a blank strip.
const listView = filesViewModeSetting.get() === "list";
const headerEnd = headerBottom(font, padding.top);
// List row boxes start one pixel above the header's bottom edge.
const top = listView ? headerEnd - 1 : headerEnd;
const box = { x: rowsX, y: top, width: rowsWidth, height: Math.max(0, height - top), padTop: 0, padBottom: padding.bottom };
if (listView) {
this.listMenu.setItems(this.flatRows());
this.listMenu.paint(image, box, ctx.stack.isFocused());
} else { } else {
const headerH = headerHeight(font); this.grid.paint(image, box, ctx.stack.isFocused());
this.grid.paint(image, { x: 0, y: headerH, width, height: height - headerH - 6 }, ctx.stack.isFocused());
} }
return image; return image;
} }
private paintList(image: GrayImage, font: UiFont, ctx: LayerContext): void {
const { width, height } = ctx.stack.getBaseSize();
const headerH = headerHeight(font);
this.listMenu.setItems(this.flatRows());
// Row boxes start one pixel above the header's bottom edge.
this.listMenu.paint(
image,
{ x: LIST_X - LIST_HIGHLIGHT_PAD, y: headerH - 1, width: width - 2 * LIST_X + 2 * LIST_HIGHLIGHT_PAD, height: height - headerH - 4 },
ctx.stack.isFocused(),
);
}
private drawListRow({ image, item, x, y, width, height, selected }: MenuDrawArgs<BrowserItem>): void { private drawListRow({ image, item, x, y, width, height, selected }: MenuDrawArgs<BrowserItem>): void {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const label = truncateText(font, item.label, width - 2 * LIST_HIGHLIGHT_PAD); const label = truncateText(font, item.label, width - 2 * LIST_HIGHLIGHT_PAD);
+19 -16
View File
@@ -5,10 +5,8 @@ import { canLoadFontFile, fontFileDisplayName, fontFileMetrics, renderFontFileTe
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, gestureHints, type InputEvent } from "../../ui/gestures"; import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, gestureHints, type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
const MARGIN_X = 18; /** From the title's top to the first sample's. */
const TITLE_Y = 8; const TITLE_BAND = 18;
const BODY_TOP = 26;
const FOOTER_MARGIN = 20;
const SAMPLE_GAP = 4; const SAMPLE_GAP = 4;
const SIZES = [8,9,10,11, 12, 13, 14, 16, 18, 20, 24, 28, 32, 40, 48] as const; const SIZES = [8,9,10,11, 12, 13, 14, 16, 18, 20, 24, 28, 32, 40, 48] as const;
@@ -48,36 +46,41 @@ export class FontPreviewerLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const out = new GrayImage(width, height, 0); const out = new GrayImage(width, height, 0);
const size = SIZES[this.sizeIndex]!; const size = SIZES[this.sizeIndex]!;
const gamma = GAMMAS[this.gammaIndex]!; const gamma = GAMMAS[this.gammaIndex]!;
// Everything keeps inside the padding suggested for the window's edges:
// the title line at the top, the samples across the width, the hint
// line at the bottom.
const left = padding.left;
const bodyWidth = Math.max(0, width - padding.left - padding.right);
const bodyTop = padding.top + TITLE_BAND;
const status = `${size}px γ ${gamma.toFixed(1)}`; const status = `${size}px γ ${gamma.toFixed(1)}`;
const statusWidth = font.measureText(status); const statusWidth = font.measureText(status);
const title = truncateText(font, this.getDisplayName(), width - 2 * MARGIN_X - statusWidth - 12); const title = truncateText(font, this.getDisplayName(), bodyWidth - statusWidth - 12);
out.drawText(font, MARGIN_X, TITLE_Y, title, 220); out.drawText(font, left, padding.top, title, 220);
out.drawText(font, width - MARGIN_X - statusWidth, TITLE_Y, status, 150); out.drawText(font, left + bodyWidth - statusWidth, padding.top, status, 150);
if (this.loadable === null) { if (this.loadable === null) {
this.loadable = canLoadFontFile(this.path); this.loadable = canLoadFontFile(this.path);
} }
const footerY = height - FOOTER_MARGIN; const footerY = height - padding.bottom - font.lineHeight;
if (!this.loadable) { if (!this.loadable) {
out.drawText(font, MARGIN_X, BODY_TOP + 16, "(could not load font)", 160); out.drawText(font, left, bodyTop + 16, "(could not load font)", 160);
out.drawText(font, MARGIN_X, footerY, gestureHints([[GESTURE_DOUBLE_CLICK, "back"]]), 110); out.drawText(font, left, footerY, gestureHints([[GESTURE_DOUBLE_CLICK, "back"]]), 110);
return out; return out;
} }
const bodyWidth = width - 2 * MARGIN_X; let y = bodyTop;
let y = BODY_TOP;
for (const [id, text] of [ for (const [id, text] of [
["pangram", PANGRAM], ["pangram", PANGRAM],
["charset", CHARSET], ["charset", CHARSET],
] as const) { ] as const) {
const line = this.getCached(id, () => renderFontFileText(this.path, text, size, gamma)); const line = this.getCached(id, () => renderFontFileText(this.path, text, size, gamma));
if (!line) continue; if (!line) continue;
out.bitBlt(line, MARGIN_X, y, { width: bodyWidth }); out.bitBlt(line, left, y, { width: bodyWidth });
y += line.height + SAMPLE_GAP; y += line.height + SAMPLE_GAP;
} }
@@ -97,13 +100,13 @@ export class FontPreviewerLayer implements Layer {
}), }),
); );
if (paragraph) { if (paragraph) {
out.bitBlt(paragraph, MARGIN_X, y + SAMPLE_GAP); out.bitBlt(paragraph, left, y + SAMPLE_GAP);
} }
} }
out.drawText( out.drawText(
font, font,
MARGIN_X, left,
footerY, footerY,
gestureHints([ gestureHints([
[GESTURE_SCROLL, "size"], [GESTURE_SCROLL, "size"],
+21 -13
View File
@@ -5,9 +5,9 @@ import { loadImageFileAsGray, PHOTO_TONE } from "../../native/image-files";
import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures"; import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
const MARGIN_X = 18; /** From the title's top to the image area's. */
const TITLE_Y = 8; const TITLE_BAND = 16;
const BODY_TOP = 24; /** How far the image area keeps from the window's sides and bottom. */
const BODY_MARGIN = 2; const BODY_MARGIN = 2;
/** /**
@@ -19,7 +19,8 @@ const BODY_MARGIN = 2;
*/ */
export class ImageViewerLayer implements Layer { export class ImageViewerLayer implements Layer {
private image: GrayImage | null = null; private image: GrayImage | null = null;
private loadAttempted = false; /** The image area ("WxH") the file was last decoded to fit; null before the first load. */
private fittedTo: string | null = null;
constructor( constructor(
private readonly path: string, private readonly path: string,
@@ -28,24 +29,31 @@ export class ImageViewerLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const out = new GrayImage(width, height, 0); const out = new GrayImage(width, height, 0);
out.drawText(font, MARGIN_X, TITLE_Y, truncateText(font, this.title, width - 2 * MARGIN_X), 220); // The title line keeps inside the padding suggested for the window's
// edges; the image fills the rest of the window whatever its edges touch.
out.drawText(font, padding.left, padding.top, truncateText(font, this.title, width - padding.left - padding.right), 220);
const bodyHeight = height - BODY_TOP - BODY_MARGIN; const bodyTop = padding.top + TITLE_BAND;
if (!this.loadAttempted) { const bodyWidth = width - 2 * BODY_MARGIN;
this.loadAttempted = true; const bodyHeight = height - bodyTop - BODY_MARGIN;
this.image = loadImageFileAsGray(this.path, width - 2 * BODY_MARGIN, bodyHeight, PHOTO_TONE); // The area moves with the window's size and its top padding, so the
// file is decoded again whenever it changes rather than once.
const fit = `${bodyWidth}x${bodyHeight}`;
if (this.fittedTo !== fit) {
this.fittedTo = fit;
this.image = loadImageFileAsGray(this.path, bodyWidth, bodyHeight, PHOTO_TONE);
} }
if (!this.image) { if (!this.image) {
out.drawText(font, MARGIN_X, BODY_TOP + 16, "(could not load image)", 160); out.drawText(font, padding.left, bodyTop + 16, "(could not load image)", 160);
out.drawText(font, MARGIN_X, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110); out.drawText(font, padding.left, height - padding.bottom - font.lineHeight, `${GESTURE_DOUBLE_CLICK} back`, 110);
return out; return out;
} }
out.bitBlt( out.bitBlt(
this.image, this.image,
Math.round((width - this.image.width) / 2), Math.round((width - this.image.width) / 2),
BODY_TOP + Math.round((bodyHeight - this.image.height) / 2), bodyTop + Math.round((bodyHeight - this.image.height) / 2),
); );
return out; return out;
} }
+23 -18
View File
@@ -5,11 +5,9 @@ import { GrayImage, type UiFont } from "../../graphics/image";
import { type InputEvent } from "../../ui/gestures"; import { type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
const MARGIN_X = 18; /** The title: how far right of the body's column, and from its top to the first body line's. */
const TITLE_Y = 16; const TITLE_INSET_X = 4;
const BODY_X = 18; const TITLE_BAND = 28;
const BODY_Y = 44;
const FOOTER_MARGIN = 36;
/** Line step for a bitmap face (the 12px font plus leading, as before). */ /** Line step for a bitmap face (the 12px font plus leading, as before). */
const BDF_LINE_STEP = 14; const BDF_LINE_STEP = 14;
@@ -24,8 +22,11 @@ function lineStepOf(font: UiFont): number {
} }
/** /**
* Paged text viewer for a document. Sized to its hosting stack (a Files * Paged text viewer for a document: a title line, the page's lines, and a
* document window, or pushed over the file browser for view-in-place). * page-number line, all inside the padding suggested for the window's edges
* (the title and page number stay put, so the lines page between them).
* Sized to its hosting stack (a Files document window, or pushed over the
* file browser for view-in-place).
*/ */
export class TextViewerLayer implements Layer { export class TextViewerLayer implements Layer {
private lines: string[] | null = null; private lines: string[] | null = null;
@@ -42,20 +43,23 @@ export class TextViewerLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getViewerFont(); const font = getViewerFont();
const lineStep = lineStepOf(font); const lineStep = lineStepOf(font);
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const footerY = height - FOOTER_MARGIN; const bodyX = padding.left;
this.bodyLineCount = Math.max(1, Math.floor((footerY - BODY_Y) / lineStep)); const bodyWidth = Math.max(0, width - padding.left - padding.right);
image.drawText(font, MARGIN_X + 4, TITLE_Y, truncateText(font, this.title, width - 2 * MARGIN_X - 8), 220); const bodyY = padding.top + TITLE_BAND;
const footerY = height - padding.bottom - font.lineHeight;
this.bodyLineCount = Math.max(1, Math.floor((footerY - bodyY) / lineStep));
image.drawText(font, bodyX + TITLE_INSET_X, padding.top, truncateText(font, this.title, bodyWidth - 2 * TITLE_INSET_X), 220);
const lines = this.getLines(font, width); const lines = this.getLines(font, bodyWidth);
const visibleLines = lines.slice(this.firstLine, this.firstLine + this.bodyLineCount); const visibleLines = lines.slice(this.firstLine, this.firstLine + this.bodyLineCount);
for (let index = 0; index < visibleLines.length; index++) { for (let index = 0; index < visibleLines.length; index++) {
image.drawText(font, BODY_X, BODY_Y + index * lineStep, visibleLines[index]!, 230); image.drawText(font, bodyX, bodyY + index * lineStep, visibleLines[index]!, 230);
} }
const currentPage = Math.floor(this.firstLine / this.pageStep()) + 1; const currentPage = Math.floor(this.firstLine / this.pageStep()) + 1;
image.drawText(font, BODY_X, footerY, `Page ${currentPage}/${this.totalPageCount(lines.length)}`, 110); image.drawText(font, bodyX, footerY, `Page ${currentPage}/${this.totalPageCount(lines.length)}`, 110);
return image; return image;
} }
@@ -89,14 +93,15 @@ export class TextViewerLayer implements Layer {
this.firstLine = Math.max(0, Math.min(maxFirstLine, this.firstLine + delta)); this.firstLine = Math.max(0, Math.min(maxFirstLine, this.firstLine + delta));
} }
private getLines(font: UiFont, width: number): string[] { /** The document wrapped to the body column's width; cached per width and font. */
if (this.lines === null || this.wrappedForWidth !== width || this.wrappedWithFont !== font.fingerprintId) { private getLines(font: UiFont, bodyWidth: number): string[] {
if (this.lines === null || this.wrappedForWidth !== bodyWidth || this.wrappedWithFont !== font.fingerprintId) {
const normalized = this.documentText.replace(/\t/g, " ").replace(/\r/g, ""); const normalized = this.documentText.replace(/\t/g, " ").replace(/\r/g, "");
this.lines = wrapText(font, normalized, width - BODY_X - 12, { this.lines = wrapText(font, normalized, bodyWidth, {
preserveLeadingWhitespace: true, preserveLeadingWhitespace: true,
breakLongWords: true, breakLongWords: true,
}); });
this.wrappedForWidth = width; this.wrappedForWidth = bodyWidth;
this.wrappedWithFont = font.fingerprintId; this.wrappedWithFont = font.fingerprintId;
} }
return this.lines; return this.lines;
+24 -14
View File
@@ -53,9 +53,11 @@ export const videoMonochromeSetting = new ConfigSettingBoolean({
/** How far one ring scroll seeks. */ /** How far one ring scroll seeks. */
const SEEK_STEP_MS = 10_000; const SEEK_STEP_MS = 10_000;
const MARGIN_X = 18; /** The settings panel's rows: at most this wide, their text this far inside their selection box. */
const TITLE_Y = 10;
const PANEL_WIDTH = 340; const PANEL_WIDTH = 340;
const PANEL_ROW_TEXT_INSET = 10;
/** The panel's title: how far below the window's top padding. */
const TITLE_OFFSET_Y = 2;
/** /**
* One opened video: its probe result, the native player, and the window * One opened video: its probe result, the native player, and the window
@@ -202,7 +204,9 @@ type PanelRow = { kind: "size" } | { kind: "audio" } | { kind: "monochrome" } |
/** /**
* The pre-play settings panel (the window's root): picture size, audio and * The pre-play settings panel (the window's root): picture size, audio and
* monochrome, all remembered for the next video, then Play (or Resume plus * monochrome, all remembered for the next video, then Play (or Resume plus
* Play from start once a position is kept). * Play from start once a position is kept). The rows' selection boxes start
* at the padding suggested for the window's left edge, and the title and
* the lines under it line up with the rows' text.
*/ */
class VideoSettingsLayer implements Layer { class VideoSettingsLayer implements Layer {
private readonly menu = new Menu<PanelRow>({ private readonly menu = new Menu<PanelRow>({
@@ -224,11 +228,16 @@ class VideoSettingsLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
image.drawText(font, MARGIN_X, TITLE_Y, truncateText(font, this.session.title, width - 2 * MARGIN_X), 220); const rowsX = padding.left;
const available = Math.max(0, width - padding.left - padding.right);
const textX = rowsX + PANEL_ROW_TEXT_INSET;
const textWidth = available - 2 * PANEL_ROW_TEXT_INSET;
const titleY = padding.top + TITLE_OFFSET_Y;
image.drawText(font, textX, titleY, truncateText(font, this.session.title, textWidth), 220);
const step = lineStep(font); const step = lineStep(font);
let y = TITLE_Y + step; let y = titleY + step;
const info = this.session.info; const info = this.session.info;
const errors: string[] = []; const errors: string[] = [];
@@ -236,12 +245,12 @@ class VideoSettingsLayer implements Layer {
if (this.session.error) errors.push(`Playback stopped: ${this.session.error}`); if (this.session.error) errors.push(`Playback stopped: ${this.session.error}`);
if (info) { if (info) {
const facts = [`${info.width}x${info.height}`, formatMediaTime(info.durationMs), info.hasAudio ? "sound" : "no sound"]; const facts = [`${info.width}x${info.height}`, formatMediaTime(info.durationMs), info.hasAudio ? "sound" : "no sound"];
image.drawText(font, MARGIN_X, y, facts.join(" · "), 130); image.drawText(font, textX, y, facts.join(" · "), 130);
y += step; y += step;
} }
for (const error of errors) { for (const error of errors) {
for (const line of wrapText(font, error, width - 2 * MARGIN_X, { breakLongWords: true }).slice(0, 3)) { for (const line of wrapText(font, error, textWidth, { breakLongWords: true }).slice(0, 3)) {
image.drawText(font, MARGIN_X, y, line, 200); image.drawText(font, textX, y, line, 200);
y += step; y += step;
} }
} }
@@ -253,9 +262,10 @@ class VideoSettingsLayer implements Layer {
// Land on Resume/Play by default: the settings usually stay as they were. // Land on Resume/Play by default: the settings usually stay as they were.
const playIndex = rows.findIndex((row) => row.kind === "play"); const playIndex = rows.findIndex((row) => row.kind === "play");
this.menu.setItems(rows, index >= 0 ? index : playIndex >= 0 ? playIndex : undefined); this.menu.setItems(rows, index >= 0 ? index : playIndex >= 0 ? playIndex : undefined);
const panelWidth = Math.min(PANEL_WIDTH, width - 2 * (MARGIN_X - 6)); // The rows scroll under the fixed lines above, as far as the window's
this.menu.paint(image, { x: MARGIN_X - 6, y, width: panelWidth, height: Math.max(0, height - y - 4) }, // bottom edge, with the padding suggested for that edge inside the list.
ctx.stack.isFocused()); this.menu.paint(image, { x: rowsX, y, width: Math.min(PANEL_WIDTH, available), height: Math.max(0, height - y),
padTop: 0, padBottom: padding.bottom }, ctx.stack.isFocused());
return image; return image;
} }
@@ -294,8 +304,8 @@ class VideoSettingsLayer implements Layer {
private drawRow({ image, item, x, y, width, selected }: MenuDrawArgs<PanelRow>): void { private drawRow({ image, item, x, y, width, selected }: MenuDrawArgs<PanelRow>): void {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const textX = x + 10; const textX = x + PANEL_ROW_TEXT_INSET;
const textWidth = width - 20; const textWidth = width - 2 * PANEL_ROW_TEXT_INSET;
switch (item.kind) { switch (item.kind) {
case "size": { case "size": {
const size = videoSizeSetting.get(); const size = videoSizeSetting.get();
+25 -5
View File
@@ -41,6 +41,7 @@ import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting";
import { type MenuItem } from "../../ui/menu"; import { type MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { Viewport } from "../../ui/viewport";
import { import {
directionalFallback, directionalFallback,
GESTURE_CLICK, GESTURE_CLICK,
@@ -95,6 +96,12 @@ const RENDER_TICK_MS = 30;
/** Physics steps per wing frame while flying. */ /** Physics steps per wing frame while flying. */
const WING_STEPS_PER_FRAME = 6; const WING_STEPS_PER_FRAME = 6;
// --- HUD (pixels below the top line's y) --------------------------------------
/** The title: a shorter font than the score's, centered on the same line. */
const HUD_TITLE_DROP = 4;
/** The best score, under the title. */
const HUD_BEST_DROP = 34;
const SFX_FLAP: Step[] = [{ freq: 880, duty: 40, ms: 20 }, { freq: 1175, duty: 40, ms: 25 }]; const SFX_FLAP: Step[] = [{ freq: 880, duty: 40, ms: 20 }, { freq: 1175, duty: 40, ms: 25 }];
const SFX_SCORE: Step[] = [{ freq: 1568, duty: 40, ms: 40 }, { freq: 2093, duty: 40, ms: 60 }]; const SFX_SCORE: Step[] = [{ freq: 1568, duty: 40, ms: 40 }, { freq: 2093, duty: 40, ms: 60 }];
const SFX_HIT: Step[] = [{ freq: 220, duty: 55, ms: 80 }, { freq: 165, duty: 55, ms: 120 }]; const SFX_HIT: Step[] = [{ freq: 220, duty: 55, ms: 80 }, { freq: 165, duty: 55, ms: 120 }];
@@ -135,6 +142,13 @@ type FlappyWindow = {
title: string; title: string;
viewportWidth: number; viewportWidth: number;
viewportHeight: number; viewportHeight: number;
/**
* The viewport as the shell last sent it: besides the size above, what each
* edge touches and the padding suggested there. The playfield fills the
* window whatever its edges touch; only the HUD's top line keeps the
* padding (see paintHud).
*/
viewport: Viewport;
foreground: boolean; foreground: boolean;
/** Whether this window is the shell's input target (pushed with each message). */ /** Whether this window is the shell's input target (pushed with each message). */
focused: boolean; focused: boolean;
@@ -198,6 +212,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
title: message.title, title: message.title,
viewportWidth: message.viewport.width, viewportWidth: message.viewport.width,
viewportHeight: message.viewport.height, viewportHeight: message.viewport.height,
viewport: message.viewport,
foreground: false, foreground: false,
focused: false, focused: false,
menu: null, menu: null,
@@ -225,7 +240,8 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
if (!window) break; if (!window) break;
window.viewportWidth = message.viewport.width; window.viewportWidth = message.viewport.width;
window.viewportHeight = message.viewport.height; window.viewportHeight = message.viewport.height;
window.menu?.resize({ width: window.viewportWidth, height: window.viewportHeight }); window.viewport = message.viewport;
window.menu?.resize(message.viewport);
if (window.foreground) renderAndSubmit(window, 0); if (window.foreground) renderAndSubmit(window, 0);
break; break;
} }
@@ -372,7 +388,7 @@ function windowMenu(window: FlappyWindow): WindowMenu {
post, post,
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window), items: () => windowMenuItems(window),
size: { width: window.viewportWidth, height: window.viewportHeight }, size: window.viewport,
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
}); });
@@ -712,14 +728,18 @@ function birdWingFrame(window: FlappyWindow): number {
function paintHud(image: GrayImage, window: FlappyWindow): void { function paintHud(image: GrayImage, window: FlappyWindow): void {
const width = window.viewportWidth; const width = window.viewportWidth;
// The top line (the score, or the title before the first flap) is the
// only thing here placed from a window edge: it keeps the padding
// suggested for the top, and the best score hangs under it.
const top = window.viewport.padding.top;
if (window.phase !== "ready") { if (window.phase !== "ready") {
drawCenteredIn(image, largeFont, 0, width, 10, String(window.score), 245); drawCenteredIn(image, largeFont, 0, width, top, String(window.score), 245);
} }
switch (window.phase) { switch (window.phase) {
case "ready": case "ready":
drawCenteredIn(image, mediumFont, 0, width, 14, "FLAPPY", 245); drawCenteredIn(image, mediumFont, 0, width, top + HUD_TITLE_DROP, "FLAPPY", 245);
if (window.highScore > 0) { if (window.highScore > 0) {
drawCenteredIn(image, smallFont, 0, width, 44, `best ${window.highScore}`, 150); drawCenteredIn(image, smallFont, 0, width, top + HUD_BEST_DROP, `best ${window.highScore}`, 150);
} }
drawCenteredIn(image, smallFont, 0, width, groundTop(window) - 26, "Touch ring / swipe to flap", 150); drawCenteredIn(image, smallFont, 0, width, groundTop(window) - 26, "Touch ring / swipe to flap", 150);
break; break;
+87 -22
View File
@@ -33,6 +33,7 @@ import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting";
import { WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import type { MenuItem } from "../../ui/menu"; import type { MenuItem } from "../../ui/menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { Viewport } from "../../ui/viewport";
import { directionalFallback, GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_LONG_PRESS, type InputEvent } from "../../ui/gestures"; import { directionalFallback, GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_LONG_PRESS, type InputEvent } from "../../ui/gestures";
declare const global: any; declare const global: any;
@@ -61,8 +62,16 @@ function isRed(card: number): boolean {
const CARD_W = 60; const CARD_W = 60;
const CARD_H = 36; const CARD_H = 36;
const TOP_Y = 4; /** How far outside the card or cascade it marks the cursor's outline is drawn. */
const CASCADE_Y = 48; const CURSOR_OUTSET = 3;
/** Gap between the top row (free cells and foundations) and the cascades. */
const ROW_GAP = 8;
/** The most of a buried cascade card left showing: enough for its label. */
const MAX_STRIP = 16;
/** Least column pitch that keeps the cursor's outline round one column off the next column's cards. */
const MIN_PITCH = CARD_W + CURSOR_OUTSET;
/** Height of the longest cascade of a fresh deal (7 cards) fanned at MAX_STRIP. */
const DEALT_CASCADE_H = 6 * MAX_STRIP + CARD_H;
/** /**
* Cursor locations, in scroll order: free cells 0-3, foundations 0-3 (the * Cursor locations, in scroll order: free cells 0-3, foundations 0-3 (the
@@ -106,6 +115,12 @@ type FreecellWindow = {
title: string; title: string;
viewportWidth: number; viewportWidth: number;
viewportHeight: number; viewportHeight: number;
/**
* The viewport as the shell last sent it: besides the size above, what each
* edge touches and the padding suggested there, which the board is laid
* out inside (see layoutFor).
*/
viewport: Viewport;
foreground: boolean; foreground: boolean;
/** Whether this window is the shell's input target (pushed with each message). */ /** Whether this window is the shell's input target (pushed with each message). */
focused: boolean; focused: boolean;
@@ -155,6 +170,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
title: message.title, title: message.title,
viewportWidth: message.viewport.width, viewportWidth: message.viewport.width,
viewportHeight: message.viewport.height, viewportHeight: message.viewport.height,
viewport: message.viewport,
foreground: false, foreground: false,
focused: false, focused: false,
menu: null, menu: null,
@@ -210,7 +226,8 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
if (!window) break; if (!window) break;
window.viewportWidth = message.viewport.width; window.viewportWidth = message.viewport.width;
window.viewportHeight = message.viewport.height; window.viewportHeight = message.viewport.height;
window.menu?.resize({ width: window.viewportWidth, height: window.viewportHeight }); window.viewport = message.viewport;
window.menu?.resize(message.viewport);
window.lastSubmittedFingerprint = ""; window.lastSubmittedFingerprint = "";
if (window.foreground) renderAndSubmit(window, 0); if (window.foreground) renderAndSubmit(window, 0);
break; break;
@@ -286,7 +303,7 @@ function windowMenu(window: FreecellWindow): WindowMenu {
post, post,
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window), items: () => windowMenuItems(window),
size: { width: window.viewportWidth, height: window.viewportHeight }, size: window.viewport,
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
}); });
@@ -706,21 +723,67 @@ function checkWin(window: FreecellWindow): void {
// Painting // Painting
type Layout = { type Layout = {
/** Distance between the left edges of neighboring columns. */
pitch: number; pitch: number;
/** Left edge of the first column's cards. */
marginX: number; marginX: number;
/** Top of the free cells and foundations. */
topY: number;
/** Top of the cascades. */
cascadeY: number;
/** Vertical pixels per buried cascade card (its visible label strip). */ /** Vertical pixels per buried cascade card (its visible label strip). */
strip: (cascadeLength: number) => number; strip: (cascadeLength: number) => number;
}; };
/**
* The eight columns across a window of the given width, keeping the given
* padding at its left and right edges: spread as far apart as a whole-pixel
* pitch allows, with what is left over split between the two sides.
*/
function columnLayout(width: number, padLeft: number, padRight: number): Pick<Layout, "pitch" | "marginX"> {
const left = padLeft + CURSOR_OUTSET;
const slack = width - padRight - CURSOR_OUTSET - left - CARD_W;
const pitch = Math.floor(slack / 7);
return { pitch, marginX: left + Math.floor((slack - pitch * 7) / 2) };
}
/**
* The two rows down a window of the given height, keeping the given padding
* at its top and bottom edges, and the height that leaves a cascade to fan
* out in.
*/
function rowLayout(
height: number,
padTop: number,
padBottom: number,
): Pick<Layout, "topY" | "cascadeY"> & { cascadeH: number } {
const topY = padTop + CURSOR_OUTSET;
const cascadeY = topY + CARD_H + ROW_GAP;
return { topY, cascadeY, cascadeH: height - padBottom - CURSOR_OUTSET - cascadeY };
}
/**
* Lay the board out in the window. The cursor's outline is the outermost
* thing drawn toward every edge (CURSOR_OUTSET outside whatever it marks), so
* it is what sits at the padding suggested for the edge; the columns spread
* across the width inside it, and the cascades fan down the height. A
* window too small for that (the RayNeo iO's) is short of room for the cards
* as it is, so along the axis where they would crowd, they take the
* padding's room too.
*/
function layoutFor(window: FreecellWindow): Layout { function layoutFor(window: FreecellWindow): Layout {
const pitch = Math.floor((window.viewportWidth - 12) / 8); const { padding } = window.viewport;
const marginX = Math.floor((window.viewportWidth - (pitch * 8 - (pitch - CARD_W))) / 2); let columns = columnLayout(window.viewportWidth, padding.left, padding.right);
const available = window.viewportHeight - CASCADE_Y - 2; if (columns.pitch < MIN_PITCH) columns = columnLayout(window.viewportWidth, 0, 0);
let rows = rowLayout(window.viewportHeight, padding.top, padding.bottom);
if (rows.cascadeH < DEALT_CASCADE_H) rows = rowLayout(window.viewportHeight, 0, 0);
const { topY, cascadeY, cascadeH } = rows;
return { return {
pitch, ...columns,
marginX, topY,
cascadeY,
strip: (cascadeLength: number) => strip: (cascadeLength: number) =>
cascadeLength <= 1 ? 0 : Math.min(16, Math.floor((available - CARD_H) / (cascadeLength - 1))), cascadeLength <= 1 ? 0 : Math.min(MAX_STRIP, Math.floor((cascadeH - CARD_H) / (cascadeLength - 1))),
}; };
} }
@@ -743,25 +806,26 @@ function paintContent(window: FreecellWindow): GrayImage {
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0); const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
const layout = layoutFor(window); const layout = layoutFor(window);
const colX = (i: number) => layout.marginX + i * layout.pitch; const colX = (i: number) => layout.marginX + i * layout.pitch;
const { topY } = layout;
// Top row: free cells then foundations, with a divider between the groups. // Top row: free cells then foundations, with a divider between the groups.
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
const card = window.cells[i]!; const card = window.cells[i]!;
if (card === null) { if (card === null) {
image.drawRoundedRect(colX(i), TOP_Y, CARD_W, CARD_H, 70, 4); image.drawRoundedRect(colX(i), topY, CARD_W, CARD_H, 70, 4);
} else { } else {
paintCard(image, colX(i), TOP_Y, card, window.selected === LOC_CELL0 + i, true); paintCard(image, colX(i), topY, card, window.selected === LOC_CELL0 + i, true);
} }
} }
image.drawLine(colX(4) - 4, TOP_Y + 4, colX(4) - 4, TOP_Y + CARD_H - 4, 70); image.drawLine(colX(4) - 4, topY + 4, colX(4) - 4, topY + CARD_H - 4, 70);
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
const x = colX(4 + i); const x = colX(4 + i);
const card = window.foundations[i]!; const card = window.foundations[i]!;
if (card === null) { if (card === null) {
image.drawRoundedRect(x, TOP_Y, CARD_W, CARD_H, 70, 4); image.drawRoundedRect(x, topY, CARD_W, CARD_H, 70, 4);
image.drawText(labelFont, x + Math.round((CARD_W - labelFont.measureText("A")) / 2), TOP_Y + 10, "A", 70); image.drawText(labelFont, x + Math.round((CARD_W - labelFont.measureText("A")) / 2), topY + 10, "A", 70);
} else { } else {
paintCard(image, x, TOP_Y, card, window.selected === LOC_FOUNDATION0 + i, true); paintCard(image, x, topY, card, window.selected === LOC_FOUNDATION0 + i, true);
} }
} }
@@ -777,7 +841,7 @@ function paintCascade(image: GrayImage, window: FreecellWindow, layout: Layout,
const x = layout.marginX + index * layout.pitch; const x = layout.marginX + index * layout.pitch;
const cascade = window.cascades[index]!; const cascade = window.cascades[index]!;
if (cascade.length === 0) { if (cascade.length === 0) {
image.drawRoundedRect(x, CASCADE_Y, CARD_W, CARD_H, 45, 4); image.drawRoundedRect(x, layout.cascadeY, CARD_W, CARD_H, 45, 4);
return; return;
} }
const strip = layout.strip(cascade.length); const strip = layout.strip(cascade.length);
@@ -788,7 +852,7 @@ function paintCascade(image: GrayImage, window: FreecellWindow, layout: Layout,
highlightFrom = cascade.length - run; highlightFrom = cascade.length - run;
} }
for (let i = 0; i < cascade.length; i++) { for (let i = 0; i < cascade.length; i++) {
paintCard(image, x, CASCADE_Y + i * strip, cascade[i]!, i >= highlightFrom, i === cascade.length - 1); paintCard(image, x, layout.cascadeY + i * strip, cascade[i]!, i >= highlightFrom, i === cascade.length - 1);
} }
} }
@@ -831,17 +895,18 @@ function paintCursor(image: GrayImage, window: FreecellWindow, layout: Layout):
let height: number; let height: number;
if (window.cursor < LOC_CASCADE0) { if (window.cursor < LOC_CASCADE0) {
x = layout.marginX + (window.cursor % 8) * layout.pitch; x = layout.marginX + (window.cursor % 8) * layout.pitch;
y = TOP_Y; y = layout.topY;
height = CARD_H; height = CARD_H;
} else { } else {
const index = window.cursor - LOC_CASCADE0; const index = window.cursor - LOC_CASCADE0;
const cascade = window.cascades[index]!; const cascade = window.cascades[index]!;
x = layout.marginX + index * layout.pitch; x = layout.marginX + index * layout.pitch;
y = CASCADE_Y; y = layout.cascadeY;
height = cascade.length === 0 ? CARD_H : (cascade.length - 1) * layout.strip(cascade.length) + CARD_H; height = cascade.length === 0 ? CARD_H : (cascade.length - 1) * layout.strip(cascade.length) + CARD_H;
} }
image.drawRect(x - 3, y - 3, CARD_W + 6, height + 6, 255); for (const outset of [CURSOR_OUTSET, CURSOR_OUTSET - 1]) {
image.drawRect(x - 2, y - 2, CARD_W + 4, height + 4, 255); image.drawRect(x - outset, y - outset, CARD_W + 2 * outset, height + 2 * outset, 255);
}
} }
function paintWinOverlay(image: GrayImage, window: FreecellWindow): void { function paintWinOverlay(image: GrayImage, window: FreecellWindow): void {
+47 -30
View File
@@ -10,6 +10,7 @@ import { Menu } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics"; import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics";
import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window"; import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window";
import { shell } from "../../ui/shell/shell"; import { shell } from "../../ui/shell/shell";
import type { Viewport } from "../../ui/viewport";
import { GlanceBoard } from "./board"; import { GlanceBoard } from "./board";
import { glanceFont } from "./glance-font"; import { glanceFont } from "./glance-font";
import { import {
@@ -33,17 +34,20 @@ import { findGlanceWidget, glanceWidgetSpans } from "./widgets";
export const GLANCEBOARD_WINDOW_ID = "glanceboard"; export const GLANCEBOARD_WINDOW_ID = "glanceboard";
export const GLANCEBOARD_SURFACE_ID = "window:glanceboard"; export const GLANCEBOARD_SURFACE_ID = "window:glanceboard";
const TITLE_X = 18; /** The entry page's title: its drop below the top padding. It lines up with the menu rows' text. */
const TITLE_Y = 10; const TITLE_OFFSET_Y = 2;
const PARAGRAPH_X = 24; /** Indent of the intro paragraph under the title, and how far short of the middle it wraps. */
/** The entry page splits at the middle: menu left, slot preview right. */ const PARAGRAPH_INDENT = 6;
const PARAGRAPH_RIGHT_GAP = 12;
/** The entry page splits at the middle: menu left, slot preview right, this far from the split. */
const PREVIEW_MARGIN = 8; const PREVIEW_MARGIN = 8;
/** The preview's outline, drawn just outside the scaled board. */
const PREVIEW_OUTLINE = 1;
const PREVIEW_MIN_LINE_VALUE = 20; const PREVIEW_MIN_LINE_VALUE = 20;
const PREVIEW_LINE_VALUE = 100; const PREVIEW_LINE_VALUE = 100;
/** The entry menu's row boxes: left inset, gap below the paragraph, and inset from the page's bottom. */ /** The entry menu's row boxes: gap below the paragraph, and how far short of the middle they end. */
const HOME_MENU_X = 20;
const HOME_MENU_TOP_GAP = 12; const HOME_MENU_TOP_GAP = 12;
const HOME_MENU_BOTTOM_MARGIN = 8; const HOME_MENU_RIGHT_GAP = 20;
/** Horizontal inset of row text (and custom row content) from its selection box. */ /** Horizontal inset of row text (and custom row content) from its selection box. */
const HOME_ROW_TEXT_X = 10; const HOME_ROW_TEXT_X = 10;
// A throwaway menu to satisfy MenuItem.onSelect's second parameter; the // A throwaway menu to satisfy MenuItem.onSelect's second parameter; the
@@ -56,9 +60,7 @@ const INTRO =
"long-press-and-hold. It will close automatically."; "long-press-and-hold. It will close automatically.";
/** Full-page list layout shared by the sub-screens. */ /** Full-page list layout shared by the sub-screens. */
function pageMenuLayout(width: number) { const PAGE_MENU_LAYOUT = { page: true } as const;
return { x: 8, y: 8, width: width - 16, opaque: true, showBorder: false } as const;
}
/** /**
* The Glanceboard app's entry page. Left half: title, a short description * The Glanceboard app's entry page. Left half: title, a short description
@@ -67,6 +69,10 @@ function pageMenuLayout(width: number) {
* name of the widget in each. "Select Contents" moves focus into that * name of the widget in each. "Select Contents" moves focus into that
* preview, where scroll picks a slot and a tap opens the picker for it; * preview, where scroll picks a slot and a tap opens the picker for it;
* a double-tap returns focus to the menu. * a double-tap returns focus to the menu.
*
* The menu's row boxes and the preview's outline sit at the padding
* suggested for the window's edges (viewport.ts). The menu scrolls, so it
* runs to the bottom edge itself, with that edge's padding after its last row.
*/ */
class GlanceboardHomeLayer implements Layer { class GlanceboardHomeLayer implements Layer {
private readonly menu: Menu<MenuItem>; private readonly menu: Menu<MenuItem>;
@@ -125,17 +131,23 @@ class GlanceboardHomeLayer implements Layer {
}); });
} }
/** Where the scaled board sits: the right half, board aspect, vertically centred. */ /**
private previewRect(width: number, height: number): { x: number; y: number; width: number; height: number } { * Where the scaled board sits: board aspect, centred in the right half's
const half = (width / 2) | 0; * room inside the window's padding, which its outline may reach.
const availableWidth = width - half - 2 * PREVIEW_MARGIN; */
private previewRect(viewport: Viewport): { x: number; y: number; width: number; height: number } {
const { width, height, padding } = viewport;
const left = ((width / 2) | 0) + PREVIEW_MARGIN;
const top = padding.top + PREVIEW_OUTLINE;
const availableWidth = Math.max(0, width - padding.right - PREVIEW_OUTLINE - left);
const availableHeight = Math.max(0, height - padding.bottom - PREVIEW_OUTLINE - top);
const layout = glanceLayout(); const layout = glanceLayout();
const scale = Math.min(availableWidth / layout.width, (height - 2 * PREVIEW_MARGIN) / layout.height); const scale = Math.min(availableWidth / layout.width, availableHeight / layout.height);
const previewWidth = Math.round(layout.width * scale); const previewWidth = Math.round(layout.width * scale);
const previewHeight = Math.round(layout.height * scale); const previewHeight = Math.round(layout.height * scale);
return { return {
x: half + PREVIEW_MARGIN + (((availableWidth - previewWidth) / 2) | 0), x: left + (((availableWidth - previewWidth) / 2) | 0),
y: ((height - previewHeight) / 2) | 0, y: top + (((availableHeight - previewHeight) / 2) | 0),
width: previewWidth, width: previewWidth,
height: previewHeight, height: previewHeight,
}; };
@@ -143,32 +155,37 @@ class GlanceboardHomeLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const { width, height, padding } = viewport;
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const half = (width / 2) | 0; const half = (width / 2) | 0;
image.drawText(font, TITLE_X, TITLE_Y, "Glanceboard", 220); const menuX = padding.left;
const titleX = menuX + HOME_ROW_TEXT_X;
const titleY = padding.top + TITLE_OFFSET_Y;
image.drawText(font, titleX, titleY, "Glanceboard", 220);
const step = lineStep(font); const step = lineStep(font);
let y = TITLE_Y + step + 6; const paragraphX = titleX + PARAGRAPH_INDENT;
for (const line of wrapText(font, INTRO, half - PARAGRAPH_X - 12)) { let y = titleY + step + 6;
image.drawText(font, PARAGRAPH_X, y, line, 160); for (const line of wrapText(font, INTRO, half - PARAGRAPH_RIGHT_GAP - paragraphX)) {
image.drawText(font, paragraphX, y, line, 160);
y += step; y += step;
} }
// The menu sits below the paragraph in the left half. While the preview // The menu sits below the paragraph in the left half. While the preview
// has focus the menu keeps its outline-only selection. // has focus the menu keeps its outline-only selection.
const menuTop = y + HOME_MENU_TOP_GAP; const menuTop = y + HOME_MENU_TOP_GAP;
const menuWidth = half - 2 * HOME_MENU_X; const menuWidth = Math.max(0, half - HOME_MENU_RIGHT_GAP - menuX);
const menuHeight = Math.max(0, height - menuTop - HOME_MENU_BOTTOM_MARGIN); const menuHeight = Math.max(0, height - menuTop);
this.paintCtx = ctx; this.paintCtx = ctx;
try { try {
this.menu.paint(image, { x: HOME_MENU_X, y: menuTop, width: menuWidth, height: menuHeight }, this.menu.paint(image, { x: menuX, y: menuTop, width: menuWidth, height: menuHeight, padBottom: padding.bottom },
ctx.stack.isFocused() && this.focus === "menu"); ctx.stack.isFocused() && this.focus === "menu");
} finally { } finally {
this.paintCtx = null; this.paintCtx = null;
} }
this.menu.drawScrollbar(image, HOME_MENU_X + menuWidth + 5, menuTop, menuHeight - 4); this.menu.drawScrollbar(image, menuX + menuWidth + 5, menuTop, Math.max(0, menuHeight - padding.bottom - 4));
this.selectedSlot = Math.min(this.selectedSlot, glanceLayout().slots.length - 1); this.selectedSlot = Math.min(this.selectedSlot, glanceLayout().slots.length - 1);
const preview = this.previewRect(width, height); const preview = this.previewRect(viewport);
drawSlotPreview(image, preview, { drawSlotPreview(image, preview, {
selectedSlot: this.selectedSlot, selectedSlot: this.selectedSlot,
selectionFocused: ctx.stack.isFocused() && this.focus === "preview", selectionFocused: ctx.stack.isFocused() && this.focus === "preview",
@@ -238,7 +255,7 @@ function drawSlotPreview(
height: Math.round(r.height * sy), height: Math.round(r.height * sy),
}); });
image.drawRect(rect.x - 1, rect.y - 1, rect.width + 2, rect.height + 2, 72); image.drawRect(rect.x - PREVIEW_OUTLINE, rect.y - PREVIEW_OUTLINE, rect.width + 2 * PREVIEW_OUTLINE, rect.height + 2 * PREVIEW_OUTLINE, 72);
const selected = scaled(layout.slots[options.selectedSlot]!.rect); const selected = scaled(layout.slots[options.selectedSlot]!.rect);
drawSelectionHighlight(image, selected.x + 1, selected.y + 1, selected.width - 2, selected.height - 2, options.selectionFocused, 4); drawSelectionHighlight(image, selected.x + 1, selected.y + 1, selected.width - 2, selected.height - 2, options.selectionFocused, 4);
@@ -321,7 +338,7 @@ function openGlanceSettings(ctx: LayerContext): void {
enumSettingMenuItem(glanceDepthSetting), enumSettingMenuItem(glanceDepthSetting),
...widgetSettingsMenuItems(), ...widgetSettingsMenuItems(),
]; ];
const layer = new MenuLayer("Glanceboard settings", items(), pageMenuLayout(ctx.stack.getBaseSize().width)); const layer = new MenuLayer("Glanceboard settings", items(), PAGE_MENU_LAYOUT);
ctx.stack.push(layer); ctx.stack.push(layer);
} }
@@ -341,7 +358,7 @@ function widgetSettingsMenuItems(): MenuItem[] {
return { label: widget.label, description: `${widget.label} has no settings.`, disabled: true, onSelect: () => {} }; return { label: widget.label, description: `${widget.label} has no settings.`, disabled: true, onSelect: () => {} };
} }
return submenuItem(widget.label, (ctx) => { return submenuItem(widget.label, (ctx) => {
ctx.stack.push(new MenuLayer(`${widget.label} settings`, settingsMenuItems(), pageMenuLayout(ctx.stack.getBaseSize().width))); ctx.stack.push(new MenuLayer(`${widget.label} settings`, settingsMenuItems(), PAGE_MENU_LAYOUT));
}, { description: `Settings for the ${widget.label} widget.` }); }, { description: `Settings for the ${widget.label} widget.` });
}); });
} }
+2 -1
View File
@@ -1,5 +1,6 @@
import { type GlanceWidgetDefinition, type GlanceWidgetId } from "../widget"; import { type GlanceWidgetDefinition, type GlanceWidgetId } from "../widget";
import { CalendarWidget } from "./calendar-widget"; import { CalendarWidget } from "./calendar-widget";
import { calendarSelectionMenuItems } from "../../calendar/calendar-filter";
import { CompassWidget } from "./compass-widget"; import { CompassWidget } from "./compass-widget";
import { MusicWidget, musicSettingsMenuItems } from "./music-widget"; import { MusicWidget, musicSettingsMenuItems } from "./music-widget";
import { NightscoutWidget } from "./nightscout-widget"; import { NightscoutWidget } from "./nightscout-widget";
@@ -11,7 +12,7 @@ import { HealthWidget } from "./health-widget";
/** Every widget a board slot can hold. */ /** Every widget a board slot can hold. */
export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [ export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [
{ id: "system-card", label: "System card", settingsMenuItems: systemCardSettingsMenuItems, create: () => new SystemCardWidget() }, { id: "system-card", label: "System card", settingsMenuItems: systemCardSettingsMenuItems, create: () => new SystemCardWidget() },
{ id: "calendar", label: "Calendar", tall: true, create: () => new CalendarWidget() }, { id: "calendar", label: "Calendar", tall: true, settingsMenuItems: calendarSelectionMenuItems, create: () => new CalendarWidget() },
{ id: "terminal", label: "Terminal", tall: true, create: () => new TerminalWidget() }, { id: "terminal", label: "Terminal", tall: true, create: () => new TerminalWidget() },
{ id: "t3code", label: "T3 Code", tall: true, create: () => new T3CodeWidget() }, { id: "t3code", label: "T3 Code", tall: true, create: () => new T3CodeWidget() },
{ id: "nightscout", label: "Nightscout", create: () => new NightscoutWidget() }, { id: "nightscout", label: "Nightscout", create: () => new NightscoutWidget() },
+18 -1
View File
@@ -11,6 +11,7 @@ import { ensureLocationPermission, hasLocationPermission } from "../../../native
import { onAndroidNotificationsChanged, readActiveNotificationIcons } from "../../../native/notification-icons"; import { onAndroidNotificationsChanged, readActiveNotificationIcons } from "../../../native/notification-icons";
import { NOTIFICATION_ICON_SIZE } from "../../../native/notification-types"; import { NOTIFICATION_ICON_SIZE } from "../../../native/notification-types";
import { readPhoneBatteryState } from "../../../native/phone-battery"; import { readPhoneBatteryState } from "../../../native/phone-battery";
import { voiceControlBridge } from "../../../native/voice-control";
import { weatherBridge } from "../../../native/weather"; import { weatherBridge } from "../../../native/weather";
import { formatClockDate, formatClockTime } from "../../../ui/clock-format"; import { formatClockDate, formatClockTime } from "../../../ui/clock-format";
import { import {
@@ -26,6 +27,7 @@ import {
watchBatteryVisibilitySetting, watchBatteryVisibilitySetting,
type BatteryIndicatorVisibility, type BatteryIndicatorVisibility,
} from "../../../ui/dashboard-settings"; } from "../../../ui/dashboard-settings";
import { RECORDING_ICON } from "../../../ui/listening-header";
import { type MenuItem } from "../../../ui/menu"; import { type MenuItem } from "../../../ui/menu";
import { shell } from "../../../ui/shell/shell"; import { shell } from "../../../ui/shell/shell";
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../../util/render-freshness"; import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../../util/render-freshness";
@@ -149,13 +151,16 @@ function requestWeatherLocationAccess(): void {
* off, and the layout mirrored either way, in the card's submenu of * off, and the layout mirrored either way, in the card's submenu of
* Glanceboard > Settings. Battery style and per-device visibility follow * Glanceboard > Settings. Battery style and per-device visibility follow
* Settings > Customization > Battery indicators, so the card agrees with * Settings > Customization > Battery indicators, so the card agrees with
* the bar. Countdowns tick once a second only while one is running. * the bar. Countdowns tick once a second only while one is running. While
* Transcribe or Translate is saving the mic's audio (their Save Recording),
* the recording circle sits under the batteries and weather.
*/ */
export class SystemCardWidget implements GlanceWidget { export class SystemCardWidget implements GlanceWidget {
private requestRender: (() => void) | null = null; private requestRender: (() => void) | null = null;
private minuteTimer: ReturnType<typeof setTimeout> | null = null; private minuteTimer: ReturnType<typeof setTimeout> | null = null;
private secondTimer: ReturnType<typeof setInterval> | null = null; private secondTimer: ReturnType<typeof setInterval> | null = null;
private unsubscribeNotifications: (() => void) | null = null; private unsubscribeNotifications: (() => void) | null = null;
private unsubscribeRecording: (() => void) | null = null;
private unsubscribeSettings: (() => void) | null = null; private unsubscribeSettings: (() => void) | null = null;
private unsubscribeTimers: (() => void) | null = null; private unsubscribeTimers: (() => void) | null = null;
private unsubscribeWeather: (() => void) | null = null; private unsubscribeWeather: (() => void) | null = null;
@@ -164,6 +169,7 @@ export class SystemCardWidget implements GlanceWidget {
this.requestRender = requestRender; this.requestRender = requestRender;
this.scheduleMinuteTick(); this.scheduleMinuteTick();
this.unsubscribeNotifications = onAndroidNotificationsChanged(() => this.requestRender?.()); this.unsubscribeNotifications = onAndroidNotificationsChanged(() => this.requestRender?.());
this.unsubscribeRecording = voiceControlBridge.onRecordingChange(() => this.requestRender?.());
this.unsubscribeSettings = onAnySettingChanged(() => this.requestRender?.()); this.unsubscribeSettings = onAnySettingChanged(() => this.requestRender?.());
this.unsubscribeTimers = timerEngine.onChange(() => { this.unsubscribeTimers = timerEngine.onChange(() => {
this.syncSecondTick(); this.syncSecondTick();
@@ -182,6 +188,8 @@ export class SystemCardWidget implements GlanceWidget {
this.secondTimer = null; this.secondTimer = null;
this.unsubscribeNotifications?.(); this.unsubscribeNotifications?.();
this.unsubscribeNotifications = null; this.unsubscribeNotifications = null;
this.unsubscribeRecording?.();
this.unsubscribeRecording = null;
this.unsubscribeSettings?.(); this.unsubscribeSettings?.();
this.unsubscribeSettings = null; this.unsubscribeSettings = null;
this.unsubscribeTimers?.(); this.unsubscribeTimers?.();
@@ -237,6 +245,8 @@ export class SystemCardWidget implements GlanceWidget {
if (batteryItems.length) sideBlocks.push(batteryBlock(small, batteryItems)); if (batteryItems.length) sideBlocks.push(batteryBlock(small, batteryItems));
const weather = weatherShowOnSystemCardSetting.get() ? weatherBlock(medium, now.getTime()) : null; const weather = weatherShowOnSystemCardSetting.get() ? weatherBlock(medium, now.getTime()) : null;
if (weather) sideBlocks.push(weather); if (weather) sideBlocks.push(weather);
// Last, so it comes and goes without moving the others.
if (voiceControlBridge.recording) sideBlocks.push(RECORDING_BLOCK);
const side: Rect[] = []; const side: Rect[] = [];
let sideOffset = PAD; let sideOffset = PAD;
for (const block of sideBlocks) { for (const block of sideBlocks) {
@@ -382,6 +392,13 @@ function batteryBlock(font: UiFont, items: readonly BatteryItem[]): SideBlock {
}; };
} }
/** The recording circle: the mic's audio is being saved (see RECORDING_ICON). */
const RECORDING_BLOCK: SideBlock = {
width: RECORDING_ICON.width,
height: RECORDING_ICON.height,
draw: (image, left, top) => image.drawImage(RECORDING_ICON, left, top),
};
/** The current weather's condition icon and temperature, or null without a fresh reading. */ /** The current weather's condition icon and temperature, or null without a fresh reading. */
function weatherBlock(font: UiFont, nowMs: number): SideBlock | null { function weatherBlock(font: UiFont, nowMs: number): SideBlock | null {
const reading = weatherReading(weatherBridge.snapshot(), nowMs); const reading = weatherReading(weatherBridge.snapshot(), nowMs);
+3 -2
View File
@@ -123,11 +123,12 @@ class HealthLayer implements Layer {
} }
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize(); // The pages lay out inside the padding suggested for the window's edges.
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
drawGlancePage( drawGlancePage(
image, image,
{ width, height }, { width, height, padding },
{ small: getDefaultSmallFont(), large: getDefaultLargeFont() }, { small: getDefaultSmallFont(), large: getDefaultLargeFont() },
GLANCE_PAGES[this.pageIndex] ?? GLANCE_PAGES[0]!, GLANCE_PAGES[this.pageIndex] ?? GLANCE_PAGES[0]!,
{ {
+149 -33
View File
@@ -4,11 +4,15 @@ import { GrayImage } from "../../graphics/image";
import { type Plane } from "../../graphics/plane"; import { type Plane } from "../../graphics/plane";
import { renderIcon, type IconName } from "../../graphics/icons"; import { renderIcon, type IconName } from "../../graphics/icons";
import { InputEvent } from "../../ui/gestures"; import { InputEvent } from "../../ui/gestures";
import { IconGrid, ICON_GRID_BAND_INSET_X, ICON_GRID_HIGHLIGHT_INSET_Y, ICON_GRID_ICON_SIZE } from "../../ui/icon-grid"; import { IconGrid, ICON_GRID_ICON_SIZE } from "../../ui/icon-grid";
import { Layer, LayerActions, LayerContext } from "../../ui/layers"; import { Layer, LayerActions, LayerContext } from "../../ui/layers";
import { MenuLayer, type MenuItem } from "../../ui/menu"; import { MenuLayer, type MenuItem } from "../../ui/menu";
import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu"; import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu";
import { onAnySettingChanged } from "../../ui/dashboard-settings"; import {
onAnySettingChanged, launcherLayoutSetting, enumSettingMenuItem,
ConfigSettingString, EditTextSettingLayer,
} from "../../ui/dashboard-settings";
import { getLauncherLayoutFingerprint, orderLauncherEntries, moveLauncherEntry } from "./launcher-layout";
import { createInProcessWindow } from "../../ui/shell/in-process-window"; import { createInProcessWindow } from "../../ui/shell/in-process-window";
import { import {
getFolderAssignments, getFolderAssignments,
@@ -16,6 +20,7 @@ import {
getFolderStateFingerprint, getFolderStateFingerprint,
setAppFolder, setAppFolder,
unusedNewFolderName, unusedNewFolderName,
getExplicitFolderNames, createFolder, renameFolder, folderNameError, disbandFolder,
} from "./launcher-folders"; } from "./launcher-folders";
import { shell, type ShellWindow } from "../../ui/shell/shell"; import { shell, type ShellWindow } from "../../ui/shell/shell";
@@ -43,12 +48,9 @@ export type LauncherOptions = {
export const LAUNCHER_WINDOW_ID = "launcher"; export const LAUNCHER_WINDOW_ID = "launcher";
export const LAUNCHER_SURFACE_ID = "window:launcher"; export const LAUNCHER_SURFACE_ID = "window:launcher";
const GRID_TOP = 6; /** A folder's name, above its grid: how far in from the grid's side, and the gap under it. */
/** const FOLDER_NAME_INSET_X = 4;
* The root grid's top: its first row's highlight band then sits as far const FOLDER_NAME_GAP = 6;
* below the window's top edge as it is from the side edges.
*/
const ROOT_GRID_TOP = ICON_GRID_BAND_INSET_X - ICON_GRID_HIGHLIGHT_INSET_Y;
/** One cell of the grid: an app, or a folder holding some of the apps. */ /** One cell of the grid: an app, or a folder holding some of the apps. */
type LauncherGridEntry = type LauncherGridEntry =
@@ -66,6 +68,14 @@ type LauncherGridEntry =
* and is re-read every paint, so assistant folder tools take effect without * and is re-read every paint, so assistant folder tools take effect without
* the layer holding any copy of the state. * the layer holding any copy of the state.
*/ */
const entryKey = (entry: LauncherGridEntry) => entry.kind === "app" ? `app:${entry.appId}` : `folder:${entry.name}`;
/** Reuse the phone text editor; dismiss it if the glasses leave this page. */
class FolderNameEditorLayer extends EditTextSettingLayer {
constructor(setting: ConfigSettingString, private readonly actions: LayerActions) { super(setting); }
onRemoved(): void { void this.actions.endTextSettingEdit(); }
}
class LauncherGridLayer implements Layer { class LauncherGridLayer implements Layer {
// Watch swipes are spatial: up/down move between rows, left/right between // Watch swipes are spatial: up/down move between rows, left/right between
// columns. From the leftmost column, left keeps going out: it leaves the // columns. From the leftmost column, left keeps going out: it leaves the
@@ -74,6 +84,12 @@ class LauncherGridLayer implements Layer {
readonly acceptsDirectional = true; readonly acceptsDirectional = true;
/** Folder whose contents the grid is showing, or null for the top grid. */ /** Folder whose contents the grid is showing, or null for the top grid. */
private currentFolder: string | null = null; private currentFolder: string | null = null;
private editingFolder = false;
private moving: { key: string; label: string; folder: string | null } | null = null;
private sortEntries(entries: LauncherGridEntry[]): LauncherGridEntry[] {
return orderLauncherEntries(entries, entryKey, this.currentFolder, launcherLayoutSetting.get() === "custom");
}
private readonly grid = new IconGrid<LauncherGridEntry>({ private readonly grid = new IconGrid<LauncherGridEntry>({
items: () => this.entries(), items: () => this.entries(),
describe: (entry) => ({ describe: (entry) => ({
@@ -104,25 +120,23 @@ class LauncherGridLayer implements Layer {
const members = (getFolders().get(this.currentFolder) ?? []) const members = (getFolders().get(this.currentFolder) ?? [])
.map((appId) => byAppId.get(appId)) .map((appId) => byAppId.get(appId))
.filter(Boolean) as LauncherAppEntry[]; .filter(Boolean) as LauncherAppEntry[];
if (members.length > 0) { if (members.length > 0 || getExplicitFolderNames().includes(this.currentFolder)) {
return members return this.sortEntries(members.map((app): LauncherGridEntry => ({
.map((app): LauncherGridEntry => ({
kind: "app", kind: "app",
label: app.label, label: app.label,
icon: app.icon, icon: app.icon,
appId: app.appId, appId: app.appId,
renderIcon: app.renderIcon, renderIcon: app.renderIcon,
})) })));
.sort((a, b) => a.label.localeCompare(b.label));
} }
this.currentFolder = null; this.currentFolder = null;
} }
const assignments = getFolderAssignments(); const assignments = getFolderAssignments();
const entries: LauncherGridEntry[] = []; const entries: LauncherGridEntry[] = [];
// A folder cell appears only when it holds at least one known app; stale // Legacy folders need a known member; explicitly created folders may be empty.
// assignments to removed apps are ignored. const explicit = new Set(getExplicitFolderNames());
for (const [name, members] of getFolders()) { for (const [name, members] of getFolders()) {
if (members.some((appId) => byAppId.has(appId))) { if (explicit.has(name) || members.some((appId) => byAppId.has(appId))) {
entries.push({ kind: "folder", label: name, name }); entries.push({ kind: "folder", label: name, name });
} }
} }
@@ -137,7 +151,7 @@ class LauncherGridLayer implements Layer {
}); });
} }
} }
return entries.sort((a, b) => a.label.localeCompare(b.label)); return this.sortEntries(entries);
} }
/** Leave the current folder, putting the selection back on its cell. */ /** Leave the current folder, putting the selection back on its cell. */
@@ -151,6 +165,16 @@ class LauncherGridLayer implements Layer {
/** Enter a folder or launch an app; true when that left the grid (a launch). */ /** Enter a folder or launch an app; true when that left the grid (a launch). */
private async openEntry(entry: LauncherGridEntry): Promise<boolean> { private async openEntry(entry: LauncherGridEntry): Promise<boolean> {
if (this.moving) {
const moving = this.moving;
this.moving = null;
if (launcherLayoutSetting.get() === "custom" && moving.folder === this.currentFolder) {
moveLauncherEntry(this.currentFolder, this.entries().map(entryKey), moving.key, entryKey(entry));
const index = this.entries().findIndex(item => entryKey(item) === moving.key);
if (index >= 0) this.grid.selectIndex(index);
}
return false;
}
if (entry.kind === "folder") { if (entry.kind === "folder") {
this.currentFolder = entry.name; this.currentFolder = entry.name;
this.grid.resetSelection(); this.grid.resetSelection();
@@ -166,6 +190,13 @@ class LauncherGridLayer implements Layer {
/** Leave the open folder, else yield to the sidebar; true when that left the grid. */ /** Leave the open folder, else yield to the sidebar; true when that left the grid. */
private back(): boolean { private back(): boolean {
if (this.moving) {
const key = this.moving.key;
this.moving = null;
const index = this.entries().findIndex(entry => entryKey(entry) === key);
if (index >= 0) this.grid.selectIndex(index);
return false;
}
if (this.currentFolder !== null) { if (this.currentFolder !== null) {
this.exitFolder(); this.exitFolder();
return false; return false;
@@ -175,14 +206,54 @@ class LauncherGridLayer implements Layer {
} }
/** /**
* App-specific entries for the window's context menu. Only item mode * Layout and folder creation are always available. Per-icon actions need
* pins the selection to a single cell, and only apps can move to folders, * item mode so row navigation never edits an ambiguous selection.
* so anywhere else the menu falls back to just the defaults.
*/ */
menuItems(): MenuItem[] { menuItems(): MenuItem[] {
if (this.editingFolder) return [];
const entry = this.grid.selectedItem; const entry = this.grid.selectedItem;
if (!entry || entry.kind !== "app") return []; const items: MenuItem[] = [
return [ enumSettingMenuItem(launcherLayoutSetting, { onChange: () => { this.moving = null; this.grid.resetSelection(); } }),
{
label: "New folder",
onSelect: ctx => {
const name = unusedNewFolderName();
if (createFolder(name)) {
this.currentFolder = null;
this.moving = null;
this.grid.resetSelection();
this.grid.selectIndex(this.entries().findIndex(item => item.kind === "folder" && item.name === name));
}
ctx.stack.pop();
},
},
];
const folder = entry?.kind === "folder" ? entry.name : this.currentFolder;
if (folder !== null) {
items.push({ label: "Rename folder", onSelect: ctx => this.editFolderName(folder, ctx) }, {
label: "Delete folder",
onSelect: ctx => {
ctx.stack.pop();
ctx.stack.push(new MenuLayer("Delete folder? Apps stay installed.", [
{ label: "Delete folder", onSelect: confirm => {
disbandFolder(folder);
if (this.currentFolder === folder) this.currentFolder = null;
this.moving = null;
this.grid.resetSelection();
confirm.stack.pop();
} },
{ label: "Cancel", onSelect: confirm => confirm.stack.pop() },
], WINDOW_MENU_LAYOUT));
},
});
}
if (this.moving) items.push({ label: "Cancel move", onSelect: ctx => { this.back(); ctx.stack.pop(); } });
else if (entry && launcherLayoutSetting.get() === "custom") items.push({
label: "Move icon",
onSelect: ctx => { this.moving = { key: entryKey(entry), label: entry.label, folder: this.currentFolder }; ctx.stack.pop(); },
});
if (!entry || entry.kind !== "app") return items;
return [...items,
{ {
label: "Move to folder", label: "Move to folder",
onSelect: (ctx) => { onSelect: (ctx) => {
@@ -221,6 +292,32 @@ class LauncherGridLayer implements Layer {
]; ];
} }
private editFolderName(folder: string, ctx: LayerContext): void {
ctx.stack.pop();
const setting = new ConfigSettingString({
id: "launcher-folder-name", label: "Folder name", storageKey: "launcher.folderNameDraft",
defaultValue: folder, normalize: value => value ?? "",
validate: value => folderNameError(value, folder), reportInAnalytics: false,
});
setting.set(folder);
this.editingFolder = true;
const editor = new FolderNameEditorLayer(setting, ctx.actions);
ctx.stack.push(editor);
void ctx.actions.startTextSettingsEdit([setting], "Rename folder", () => {
this.editingFolder = false;
if (renameFolder(folder, setting.get())) {
if (this.currentFolder === folder) this.currentFolder = setting.get().trim();
this.moving = null;
}
ctx.stack.popIfTop(layer => layer === editor);
ctx.actions.requestRender();
}, undefined, () => {
this.editingFolder = false;
ctx.stack.popIfTop(layer => layer === editor);
ctx.actions.requestRender();
});
}
/** /**
* The folder-picker submenu: every existing folder except the app's own, * The folder-picker submenu: every existing folder except the app's own,
* plus a generated-name "New folder" (ring input has no text entry) and, * plus a generated-name "New folder" (ring input has no text entry) and,
@@ -242,7 +339,9 @@ class LauncherGridLayer implements Layer {
items.push({ items.push({
label: "New folder", label: "New folder",
onSelect: (ctx) => { onSelect: (ctx) => {
setAppFolder(appId, unusedNewFolderName()); const name = unusedNewFolderName();
createFolder(name);
setAppFolder(appId, name);
ctx.stack.pop(); ctx.stack.pop();
}, },
}); });
@@ -260,20 +359,37 @@ class LauncherGridLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
// The folder-name header band scales with the font. const entries = this.entries();
const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : ROOT_GRID_TOP; if (this.moving && (launcherLayoutSetting.get() !== "custom" || this.moving.folder !== this.currentFolder ||
if (this.currentFolder !== null) { !entries.some(entry => entryKey(entry) === this.moving!.key))) this.moving = null;
image.drawText(font, 8, GRID_TOP - 2, truncateText(font, this.currentFolder, width - 16), 160); const gridX = padding.left;
const gridWidth = width - padding.left - padding.right;
// Scrolling rows reach the window edges, with the suggested padding
// inside the grid. Folder and move headers stay fixed above it.
let gridTop = 0;
let padTop = padding.top;
const nameX = gridX + FOLDER_NAME_INSET_X;
const nameWidth = gridWidth - 2 * FOLDER_NAME_INSET_X;
if (this.moving) {
image.drawText(font, nameX, padding.top, truncateText(font, `Move ${this.moving.label}`, nameWidth), 220);
image.drawText(font, nameX, padding.top + font.lineHeight + 2,
truncateText(font, "Select position; double tap cancels", nameWidth), 160);
gridTop = padding.top + 2 * (font.lineHeight + 2) + FOLDER_NAME_GAP;
padTop = 0;
} else if (this.currentFolder !== null) {
image.drawText(font, nameX, padding.top, truncateText(font, this.currentFolder, nameWidth), 160);
gridTop = padding.top + font.lineHeight + FOLDER_NAME_GAP;
padTop = 0;
} }
// The grid runs to the window's bottom edge, so a row cut off there for this.grid.paint(image, { x: gridX, y: gridTop, width: gridWidth, height: height - gridTop, padTop, padBottom: padding.bottom },
// scrolling meets the window's border rather than a blank strip. ctx.stack.isFocused());
this.grid.paint(image, { x: 0, y: gridTop, width, height: height - gridTop }, ctx.stack.isFocused());
return image; return image;
} }
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> { async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
if (this.moving && event.type === "double-click") { this.back(); return; }
await this.grid.handleInput(event, ctx); await this.grid.handleInput(event, ctx);
} }
@@ -311,9 +427,9 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow {
// keeps every unrelated setting change from repainting the launcher. The // keeps every unrelated setting change from repainting the launcher. The
// launcher is pinned for the app's lifetime, so the subscription never needs // launcher is pinned for the app's lifetime, so the subscription never needs
// tearing down. // tearing down.
let lastState = `${getFolderStateFingerprint()}\n${launcherAppsFingerprint(options.apps())}`; let lastState = `${getFolderStateFingerprint()}\n${getLauncherLayoutFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
onAnySettingChanged(() => { onAnySettingChanged(() => {
const state = `${getFolderStateFingerprint()}\n${launcherAppsFingerprint(options.apps())}`; const state = `${getFolderStateFingerprint()}\n${getLauncherLayoutFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
if (state === lastState) return; if (state === lastState) return;
lastState = state; lastState = state;
created.requestRender(); created.requestRender();
+51 -11
View File
@@ -1,14 +1,50 @@
/** /** Launcher assignments keep their legacy format; explicitly created folders may be empty. */
* Launcher folder state: which apps are grouped into which named folder.
* Stored as one JSON string (appId -> folder name) in the settings store, so
* it persists and its changes broadcast to every isolate. An unset value means
* the default grouping; any edit persists the whole map, so clearing out the
* defaults sticks. Folders exist only while at least one app is assigned to
* them — there is no separate create/delete step.
*/
import { getStringSetting, setStringSetting } from "../../native/settings-store"; import { getStringSetting, setStringSetting } from "../../native/settings-store";
import { renameLauncherFolderOrder, removeLauncherFolderOrder } from "./launcher-layout";
const STORAGE_KEY = "launcher.folders"; const STORAGE_KEY = "launcher.folders";
const NAMES_KEY = "launcher.folderNames";
/** Only user-created/renamed folders persist after their last member leaves. */
export function getExplicitFolderNames(): string[] {
try {
const value = JSON.parse(getStringSetting(NAMES_KEY, "[]"));
return Array.isArray(value) ? [...new Set(value.filter((name): name is string =>
typeof name === "string" && !!name.trim()).map(name => name.trim()))] : [];
} catch { return []; }
}
export function folderNameError(input: string, previous?: string): string | null {
const name = input.trim();
if (!name) return "Enter a folder name.";
if (name.length > FOLDER_NAME_MAX_LENGTH) return `Use at most ${FOLDER_NAME_MAX_LENGTH} characters.`;
if (/[\u0000-\u001f\u007f]/.test(name)) return "Use a single-line folder name.";
if (previous !== undefined && !getFolders().has(previous)) return "This folder no longer exists.";
for (const existing of getFolders().keys()) {
if (existing !== previous && existing.toLowerCase() === name.toLowerCase()) return "A folder with this name already exists.";
}
return null;
}
export function createFolder(input: string): boolean {
if (folderNameError(input)) return false;
setStringSetting(NAMES_KEY, JSON.stringify([...getExplicitFolderNames(), input.trim()]));
return true;
}
export function renameFolder(previous: string, input: string): boolean {
if (folderNameError(input, previous)) return false;
const name = input.trim();
if (name === previous) return true;
const assignments = getFolderAssignments();
for (const appId of Object.keys(assignments)) if (assignments[appId] === previous) assignments[appId] = name;
// Preserve position and per-folder order when the visible name changes.
renameLauncherFolderOrder(previous, name);
setStringSetting(NAMES_KEY, JSON.stringify([...getExplicitFolderNames().filter(n => n !== previous), name]));
setStringSetting(STORAGE_KEY, JSON.stringify(assignments));
return true;
}
/** The out-of-the-box grouping, applied only while the setting is unset. */ /** The out-of-the-box grouping, applied only while the setting is unset. */
const DEFAULT_ASSIGNMENTS: Record<string, string> = { const DEFAULT_ASSIGNMENTS: Record<string, string> = {
@@ -32,7 +68,7 @@ export function getFolderAssignments(): Record<string, string> {
try { try {
const parsed = JSON.parse(raw); const parsed = JSON.parse(raw);
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {}; if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
const assignments: Record<string, string> = {}; const assignments: Record<string, string> = Object.create(null);
for (const appId of Object.keys(parsed)) { for (const appId of Object.keys(parsed)) {
const folder = parsed[appId]; const folder = parsed[appId];
if (typeof folder === "string" && folder.trim()) { if (typeof folder === "string" && folder.trim()) {
@@ -58,6 +94,7 @@ export function getFolders(): Map<string, string[]> {
unsorted.set(folder, [appId]); unsorted.set(folder, [appId]);
} }
} }
for (const name of getExplicitFolderNames()) if (!unsorted.has(name)) unsorted.set(name, []);
const folders = new Map<string, string[]>(); const folders = new Map<string, string[]>();
for (const name of Array.from(unsorted.keys()).sort((a, b) => a.localeCompare(b))) { for (const name of Array.from(unsorted.keys()).sort((a, b) => a.localeCompare(b))) {
folders.set(name, unsorted.get(name)!); folders.set(name, unsorted.get(name)!);
@@ -86,6 +123,8 @@ export function disbandFolder(folder: string): number {
moved++; moved++;
} }
} }
setStringSetting(NAMES_KEY, JSON.stringify(getExplicitFolderNames().filter(name => name !== folder)));
removeLauncherFolderOrder(folder);
if (moved > 0) { if (moved > 0) {
setStringSetting(STORAGE_KEY, JSON.stringify(assignments)); setStringSetting(STORAGE_KEY, JSON.stringify(assignments));
} }
@@ -95,7 +134,7 @@ export function disbandFolder(folder: string): number {
/** /**
* An unused name for a ring-created folder ("New folder", "New folder 2", …). * An unused name for a ring-created folder ("New folder", "New folder 2", …).
* Ring input has no text entry, so new folders start with a generated name; * Ring input has no text entry, so new folders start with a generated name;
* the assistant's folder tools can regroup the apps under a better one. * Rename folder uses the existing phone text editor for a custom name.
*/ */
export function unusedNewFolderName(): string { export function unusedNewFolderName(): string {
const existing = new Set(Array.from(getFolders().keys()).map((name) => name.toLowerCase())); const existing = new Set(Array.from(getFolders().keys()).map((name) => name.toLowerCase()));
@@ -119,5 +158,6 @@ export function resolveFolderName(input: string): string {
/** Raw stored value, for cheap change detection by the launcher window. */ /** Raw stored value, for cheap change detection by the launcher window. */
export function getFolderStateFingerprint(): string { export function getFolderStateFingerprint(): string {
return getStringSetting(STORAGE_KEY, ""); return JSON.stringify([getStringSetting(STORAGE_KEY, ""), getStringSetting(NAMES_KEY, ""),
getStringSetting("launcher.folderNameDraft", "")]);
} }
+60
View File
@@ -0,0 +1,60 @@
import { getStringSetting, setStringSetting } from "../../native/settings-store";
const ORDER_KEY = "launcher.order";
const scopeKey = (folder: string | null) => folder === null ? "root" : `folder:${folder}`;
function readOrders(): Record<string, string[]> {
try {
const value = JSON.parse(getStringSetting(ORDER_KEY, "{}"));
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
return Object.fromEntries(Object.entries(value).filter(([, order]) => Array.isArray(order))
.map(([scope, order]) => [scope, [...new Set((order as unknown[]).filter((id): id is string => typeof id === "string"))]]));
} catch { return {}; }
}
export function setLauncherOrder(folder: string | null, ids: readonly string[]): void {
const orders = readOrders();
orders[scopeKey(folder)] = [...new Set(ids)];
setStringSetting(ORDER_KEY, JSON.stringify(orders));
}
/** Unseen apps append alphabetically; changing sort modes never destroys saved order. */
export function orderLauncherEntries<T extends { label: string }>(
entries: T[], key: (entry: T) => string, folder: string | null, custom: boolean,
): T[] {
const order = custom ? readOrders()[scopeKey(folder)] ?? [] : [];
const rank = new Map(order.map((id, index) => [id, index]));
return entries.sort((a, b) => (rank.get(key(a)) ?? Infinity) - (rank.get(key(b)) ?? Infinity) ||
a.label.localeCompare(b.label) || key(a).localeCompare(key(b)));
}
/** Move into the target's position, without moving apps across folders. */
export function moveLauncherEntry(folder: string | null, ids: string[], source: string, target: string): boolean {
const from = ids.indexOf(source), to = ids.indexOf(target);
if (from < 0 || to < 0) return false;
const next = ids.slice();
next.splice(from, 1);
next.splice(to, 0, source);
setLauncherOrder(folder, next);
return true;
}
export function renameLauncherFolderOrder(previous: string, next: string): void {
const orders = readOrders();
const oldScope = scopeKey(previous), newScope = scopeKey(next);
if (orders[oldScope]) orders[newScope] = orders[oldScope];
delete orders[oldScope];
if (orders.root) orders.root = orders.root.map(id => id === `folder:${previous}` ? `folder:${next}` : id);
setStringSetting(ORDER_KEY, JSON.stringify(orders));
}
export function removeLauncherFolderOrder(folder: string): void {
const orders = readOrders();
delete orders[scopeKey(folder)];
if (orders.root) orders.root = orders.root.filter(id => id !== `folder:${folder}`);
setStringSetting(ORDER_KEY, JSON.stringify(orders));
}
export function getLauncherLayoutFingerprint(): string {
return JSON.stringify([getStringSetting("launcher.layout", "alphabetical"), getStringSetting(ORDER_KEY, "")]);
}
+20 -10
View File
@@ -5,11 +5,19 @@ import { GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
import { micSession, type CaptionLine, type MicSessionState } from "./mic-session"; import { micSession, type CaptionLine, type MicSessionState } from "./mic-session";
/** From the title's top to the first caption row. */
const BODY_TOP_OFFSET = 20;
/** Indent of the caption rows under the title. */
const ROW_INDENT = 4;
/** /**
* On-glasses captions: each line is prefixed with the speaker's name (their * On-glasses captions: each line is prefixed with the speaker's name (their
* id until tagged); foreign-language lines show the translation directly * id until tagged); foreign-language lines show the translation directly
* beneath the recognized original. Scroll reviews recent lines; the view * beneath the recognized original. Scroll reviews recent lines; the view
* snaps back to live on new speech. * snaps back to live on new speech.
*
* The title and the hint line stay put, at the padding suggested for the
* window's top and bottom edges; the caption rows scroll between the two.
*/ */
export class CaptionsLayer implements Layer { export class CaptionsLayer implements Layer {
private state: MicSessionState = micSession.getState(); private state: MicSessionState = micSession.getState();
@@ -33,19 +41,21 @@ export class CaptionsLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const state = this.state; const state = this.state;
const left = padding.left;
const rowX = left + ROW_INDENT;
const bodyTop = padding.top + BODY_TOP_OFFSET;
image.drawText(font, 12, 4, "Captions", 220); image.drawText(font, left, padding.top, "Captions", 220);
if (!state.captionsActive) { if (!state.captionsActive) {
image.drawText(font, 12, 26, state.captionsNote, 130); image.drawText(font, left, bodyTop + 2, state.captionsNote, 130);
} }
const rows = this.buildRows(font, width - 36, state.captionLines); const rows = this.buildRows(font, Math.max(0, width - padding.right - rowX), state.captionLines);
const step = lineStep(font) + 1; const step = lineStep(font) + 1;
const bodyTop = 24; const footerY = height - padding.bottom - font.lineHeight;
const footerY = height - font.lineHeight - 4;
const visibleRows = Math.max(1, Math.floor((footerY - bodyTop) / step)); const visibleRows = Math.max(1, Math.floor((footerY - bodyTop) / step));
const maxScrollback = Math.max(0, rows.length - visibleRows); const maxScrollback = Math.max(0, rows.length - visibleRows);
this.scrollback = Math.min(this.scrollback, maxScrollback); this.scrollback = Math.min(this.scrollback, maxScrollback);
@@ -54,16 +64,16 @@ export class CaptionsLayer implements Layer {
const row = rows[index]!; const row = rows[index]!;
const y = bodyTop + (index - firstRow) * step; const y = bodyTop + (index - firstRow) * step;
if (row.prefix) { if (row.prefix) {
image.drawText(font, 16, y, row.prefix, row.prefixValue); image.drawText(font, rowX, y, row.prefix, row.prefixValue);
image.drawText(font, 16 + font.measureText(row.prefix), y, row.text, row.value); image.drawText(font, rowX + font.measureText(row.prefix), y, row.text, row.value);
} else { } else {
image.drawText(font, 16 + row.indent, y, row.text, row.value); image.drawText(font, rowX + row.indent, y, row.text, row.value);
} }
} }
image.drawText( image.drawText(
font, font,
12, left,
footerY, footerY,
`${GESTURE_SCROLL} history ${GESTURE_DOUBLE_CLICK} back` + `${GESTURE_SCROLL} history ${GESTURE_DOUBLE_CLICK} back` +
(this.scrollback > 0 ? ` (${this.scrollback} back)` : ""), (this.scrollback > 0 ? ` (${this.scrollback} back)` : ""),
+21 -12
View File
@@ -4,6 +4,12 @@ import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
import { micSession, type MicSessionState } from "./mic-session"; import { micSession, type MicSessionState } from "./mic-session";
/** From the title's top to the status line, and to the first meter row. */
const STATUS_OFFSET_Y = 18;
const METERS_OFFSET_Y = 42;
/** Width of the mic-name column left of the meters. */
const LABEL_COLUMN_WIDTH = 118;
/** /**
* Live level meters, one per active microphone (a single mixed channel on * Live level meters, one per active microphone (a single mixed channel on
* stock firmware; up to four mics with the mic-control firmware), plus the * stock firmware; up to four mics with the mic-control firmware), plus the
@@ -22,24 +28,27 @@ export class LevelsLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const state = this.state; const state = this.state;
// Text starts at the padding suggested for the window's left edge, and
// the meters run to the right edge's.
const left = padding.left;
image.drawText(font, 12, 6, "Microphone Levels", 220); image.drawText(font, left, padding.top, "Microphone Levels", 220);
image.drawText(font, 12, 24, state.statusText, 110); image.drawText(font, left, padding.top + STATUS_OFFSET_Y, state.statusText, 110);
const barX = 130; const barX = left + LABEL_COLUMN_WIDTH;
const barWidth = width - barX - 40; const barWidth = Math.max(0, width - padding.right - barX);
const rowHeight = 26; const rowHeight = 26;
let y = 48; let y = padding.top + METERS_OFFSET_Y;
const labels = state.levelLabels.length ? state.levelLabels : ["Glasses mic"]; const labels = state.levelLabels.length ? state.levelLabels : ["Glasses mic"];
labels.forEach((label, index) => { labels.forEach((label, index) => {
const level = state.levels[index] ?? 0; const level = state.levels[index] ?? 0;
const enabled = state.levelsEnabled[index] ?? true; const enabled = state.levelsEnabled[index] ?? true;
image.drawText(font, 12, y + 3, enabled ? label : `${label} (off)`, enabled ? 190 : 90); image.drawText(font, left, y + 3, enabled ? label : `${label} (off)`, enabled ? 190 : 90);
image.drawRect(barX, y, barWidth, 16, enabled ? 70 : 40); image.drawRect(barX, y, barWidth, 16, enabled ? 70 : 40);
const fill = Math.round((barWidth - 4) * level); const fill = Math.round(Math.max(0, barWidth - 4) * level);
if (fill > 0) { if (fill > 0) {
// A disabled mic still meters (dimly) so its signal can be checked // A disabled mic still meters (dimly) so its signal can be checked
// before switching it back on. // before switching it back on.
@@ -55,15 +64,15 @@ export class LevelsLayer implements Layer {
y += 6; y += 6;
if (state.doaDeviceDeg !== null) { if (state.doaDeviceDeg !== null) {
image.drawText(font, 12, y, `Direction of arrival: ${Math.round(state.doaDeviceDeg)}°`, 160); image.drawText(font, left, y, `Direction of arrival: ${Math.round(state.doaDeviceDeg)}°`, 160);
y += 18; y += 18;
} }
image.drawText(font, 12, y, `Signal-strength ratio: ${state.ssr}`, 130); image.drawText(font, left, y, `Signal-strength ratio: ${state.ssr}`, 130);
y += 18; y += 18;
const ancText = state.ancOn && state.ancEngine ? `on — ${state.ancEngine}` : "off"; const ancText = state.ancOn && state.ancEngine ? `on — ${state.ancEngine}` : "off";
image.drawText(font, 12, y, `Noise cancellation: ${ancText}`, 130); image.drawText(font, left, y, `Noise cancellation: ${ancText}`, 130);
image.drawText(font, 12, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} back`, 110); image.drawText(font, left, height - padding.bottom - font.lineHeight, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image; return image;
} }
+1 -10
View File
@@ -1,6 +1,5 @@
import { imageFromAsciiArt } from "../../graphics/image"; import { imageFromAsciiArt } from "../../graphics/image";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { appViewportSize } from "../../ui/shell/geometry";
import { import {
MenuLayer, MenuLayer,
TextPageLayer, TextPageLayer,
@@ -62,15 +61,7 @@ const TRAY_ICON = imageFromAsciiArt(
{ "#": 220 }, { "#": 220 },
); );
const MENU_LAYOUT = { const MENU_LAYOUT = { page: true, width: 268 } as const;
x: 8,
y: 8,
width: 292,
showBorder: false,
minHeight: 0,
maxHeight: appViewportSize("min").height - 16,
opaque: true,
};
/** Persist a config change; the running session applies it live. */ /** Persist a config change; the running session applies it live. */
function updateMicConfig(mutate: (config: MicConfig) => MicConfig): void { function updateMicConfig(mutate: (config: MicConfig) => MicConfig): void {
+40 -29
View File
@@ -5,6 +5,16 @@ import { Layer, type LayerContext } from "../../ui/layers";
import { micSession, type MicSessionState } from "./mic-session"; import { micSession, type MicSessionState } from "./mic-session";
import { dotBrightness } from "./radar-dots"; import { dotBrightness } from "./radar-dots";
/** Room above the plot's ring for its "front" label. */
const FRONT_LABEL_BAND = 14;
/** Gap between the ring and the hint line under it. */
const RING_FOOTER_GAP = 10;
/** The least the ring keeps clear of the window's sides, which leaves the readout panel its corner. */
const RING_SIDE_CLEARANCE = 90;
/** The readout panel: the least its column is wide, and its drop below the title's top. */
const PANEL_MIN_WIDTH = 104;
const PANEL_OFFSET_Y = 20;
/** /**
* The Sonic Radar: a top-down view around the wearer's head. The shaded * The Sonic Radar: a top-down view around the wearer's head. The shaded
* wedge is the listening beam (scroll rotates it, click locks it onto the * wedge is the listening beam (scroll rotates it, click locks it onto the
@@ -14,6 +24,10 @@ import { dotBrightness } from "./radar-dots";
* scene is world-anchored (an N tick marks north and dots stay put as the * scene is world-anchored (an N tick marks north and dots stay put as the
* head turns); dots glow full-bright while their speaker is talking and fade * head turns); dots glow full-bright while their speaker is talking and fade
* with the time since they last spoke. * with the time since they last spoke.
*
* The plot is centred on the window, between the title row and the hint
* line; those and the readout panel keep to the padding suggested for the
* window's edges.
*/ */
export class RadarLayer implements Layer { export class RadarLayer implements Layer {
private state: MicSessionState = micSession.getState(); private state: MicSessionState = micSession.getState();
@@ -28,17 +42,20 @@ export class RadarLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const state = this.state; const state = this.state;
const footerY = height - padding.bottom - font.lineHeight;
const ringTop = padding.top + FRONT_LABEL_BAND;
const ringBottom = footerY - RING_FOOTER_GAP;
const centerX = (width / 2) | 0; const centerX = (width / 2) | 0;
const centerY = ((height - 24) / 2 + 6) | 0; const centerY = ((ringTop + ringBottom) / 2) | 0;
const radius = Math.min(centerX - 90, ((height - 40) / 2) | 0); const radius = Math.max(0, Math.min(centerX - RING_SIDE_CLEARANCE, ((ringBottom - ringTop) / 2) | 0));
image.drawText(font, 12, 6, "Sonic Radar", 220); image.drawText(font, padding.left, padding.top, "Sonic Radar", 220);
const modeText = state.mode === "extended" ? "4-mic array" : "firmware DoA"; const modeText = state.mode === "extended" ? "4-mic array" : "firmware DoA";
image.drawText(font, width - font.measureText(modeText) - 12, 6, modeText, 110); image.drawText(font, width - padding.right - font.measureText(modeText), padding.top, modeText, 110);
// Beam wedge (device frame; the head is the reference for display). // Beam wedge (device frame; the head is the reference for display).
const beamDeviceDeg = this.deviceBeamDeg(state); const beamDeviceDeg = this.deviceBeamDeg(state);
@@ -70,7 +87,7 @@ export class RadarLayer implements Layer {
// Radar rings. // Radar rings.
drawCircle(image, centerX, centerY, radius, 60); drawCircle(image, centerX, centerY, radius, 60);
drawCircle(image, centerX, centerY, (radius / 2) | 0, 30); drawCircle(image, centerX, centerY, (radius / 2) | 0, 30);
image.drawText(font, centerX - (font.measureText("front") / 2) | 0, centerY - radius - 14, "front", 90); image.drawText(font, centerX - (font.measureText("front") / 2) | 0, centerY - radius - FRONT_LABEL_BAND, "front", 90);
// Compass north tick: anchors the world frame visually as the head turns. // Compass north tick: anchors the world frame visually as the head turns.
if (state.headingDeg !== null) { if (state.headingDeg !== null) {
@@ -127,37 +144,31 @@ export class RadarLayer implements Layer {
} }
const label = dot.name; const label = dot.name;
const labelValue = Math.max(90, value - 50); const labelValue = Math.max(90, value - 50);
const labelX = dotX + 8 + font.measureText(label) > width ? dotX - font.measureText(label) - 8 : dotX + 8; const labelX = dotX + 8 + font.measureText(label) > width - padding.right ? dotX - font.measureText(label) - 8 : dotX + 8;
image.drawText(font, labelX, dotY - 6, label, labelValue); image.drawText(font, labelX, dotY - 6, label, labelValue);
} }
// Side panel: beam + level readouts. // Side panel: beam + level readouts, in a column that ends at the right
const panelX = width - 116; // edge's padding and is wide enough for its longest line.
let panelY = 26; const panelLines: Array<[text: string, value: number]> = [
image.drawText( state.headingDeg !== null ? [`Heading ${Math.round(state.headingDeg)}°`, 150] : ["No compass", 90],
font, [`Beam ${Math.round(state.beamWorldDeg)}°`, 170],
panelX, [`Width ${Math.round(state.beamWidthDeg)}°`, 130],
panelY, [state.beamLocked ? "Locked on talker" : "Manual aim", 130],
state.headingDeg !== null ? `Heading ${Math.round(state.headingDeg)}°` : "No compass", ];
state.headingDeg !== null ? 150 : 90, if (state.doaDeviceDeg !== null) panelLines.push([`Heard ${Math.round(state.doaDeviceDeg)}°`, 200]);
); panelLines.push([state.beamFilterOn ? "Filter: beam only" : "Filter: off", 130]);
panelY += 16; const panelWidth = Math.max(PANEL_MIN_WIDTH, ...panelLines.map(([text]) => Math.ceil(font.measureText(text))));
image.drawText(font, panelX, panelY, `Beam ${Math.round(state.beamWorldDeg)}°`, 170); const panelX = width - padding.right - panelWidth;
panelY += 16; let panelY = padding.top + PANEL_OFFSET_Y;
image.drawText(font, panelX, panelY, `Width ${Math.round(state.beamWidthDeg)}°`, 130); for (const [text, value] of panelLines) {
panelY += 16; image.drawText(font, panelX, panelY, text, value);
image.drawText(font, panelX, panelY, state.beamLocked ? "Locked on talker" : "Manual aim", 130);
panelY += 16;
if (state.doaDeviceDeg !== null) {
image.drawText(font, panelX, panelY, `Heard ${Math.round(state.doaDeviceDeg)}°`, 200);
panelY += 16; panelY += 16;
} }
image.drawText(font, panelX, panelY, state.beamFilterOn ? "Filter: beam only" : "Filter: off", 130);
const footerY = height - font.lineHeight - 4;
image.drawText( image.drawText(
font, font,
12, padding.left,
footerY, footerY,
`${GESTURE_SCROLL} aim ${GESTURE_CLICK} lock ${GESTURE_DOUBLE_CLICK} back`, `${GESTURE_SCROLL} aim ${GESTURE_CLICK} lock ${GESTURE_DOUBLE_CLICK} back`,
110, 110,
+64 -31
View File
@@ -33,6 +33,7 @@ import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting";
import { type MenuItem } from "../../ui/menu"; import { type MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { Viewport } from "../../ui/viewport";
import { import {
directionalFallback, directionalFallback,
GESTURE_CLICK, GESTURE_CLICK,
@@ -53,9 +54,10 @@ const smallFont = getDefaultSmallFont();
const COLS = 12; const COLS = 12;
const ROWS = 9; const ROWS = 9;
const CELL = 26; const CELL = 26;
const BOARD_X = 14; /** How far outside its cells the board's frame is drawn. */
const BOARD_Y = 14; const BOARD_FRAME = 2;
const PANEL_X = BOARD_X + COLS * CELL + 28; /** Gap between the board's cells and the panel to their right. */
const PANEL_GAP = 28;
const DIFFICULTIES = [ const DIFFICULTIES = [
{ name: "Easy", mines: 14 }, { name: "Easy", mines: 14 },
@@ -107,6 +109,12 @@ type MinesweeperWindow = {
title: string; title: string;
viewportWidth: number; viewportWidth: number;
viewportHeight: number; viewportHeight: number;
/**
* The viewport as the shell last sent it: besides the size above, what each
* edge touches and the padding suggested there, which places the board
* (see boardOrigin).
*/
viewport: Viewport;
foreground: boolean; foreground: boolean;
/** Whether this window is the shell's input target (pushed with each message). */ /** Whether this window is the shell's input target (pushed with each message). */
focused: boolean; focused: boolean;
@@ -166,6 +174,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
title: message.title, title: message.title,
viewportWidth: message.viewport.width, viewportWidth: message.viewport.width,
viewportHeight: message.viewport.height, viewportHeight: message.viewport.height,
viewport: message.viewport,
foreground: false, foreground: false,
focused: false, focused: false,
menu: null, menu: null,
@@ -255,7 +264,8 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
if (!window) break; if (!window) break;
window.viewportWidth = message.viewport.width; window.viewportWidth = message.viewport.width;
window.viewportHeight = message.viewport.height; window.viewportHeight = message.viewport.height;
window.menu?.resize({ width: window.viewportWidth, height: window.viewportHeight }); window.viewport = message.viewport;
window.menu?.resize(message.viewport);
window.lastSubmittedFingerprint = ""; window.lastSubmittedFingerprint = "";
if (window.foreground) renderAndSubmit(window, 0); if (window.foreground) renderAndSubmit(window, 0);
break; break;
@@ -352,7 +362,7 @@ function windowMenu(window: MinesweeperWindow): WindowMenu {
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window), items: () => windowMenuItems(window),
claimsLongPress: () => window.phase === "playing", claimsLongPress: () => window.phase === "playing",
size: { width: window.viewportWidth, height: window.viewportHeight }, size: window.viewport,
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
}); });
@@ -666,46 +676,67 @@ function paint(window: MinesweeperWindow): Plane[] {
return windowMenu(window).paint(); return windowMenu(window).paint();
} }
/** Top-left corner of the board's cells, in viewport coordinates. */
type BoardOrigin = { x: number; y: number };
/**
* Where the board goes: its frame, the outermost thing drawn toward the
* window's top and left edges, sits at the padding suggested for them. The
* board is a fixed size and the panel hangs off its right side, so the whole
* layout moves with it and nothing is placed from the other two edges.
*/
function boardOrigin(window: MinesweeperWindow): BoardOrigin {
const { padding } = window.viewport;
return { x: padding.left + BOARD_FRAME, y: padding.top + BOARD_FRAME };
}
function paintContent(window: MinesweeperWindow): GrayImage { function paintContent(window: MinesweeperWindow): GrayImage {
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0); const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
image.drawRect(BOARD_X - 2, BOARD_Y - 2, COLS * CELL + 4, ROWS * CELL + 4, 120); const board = boardOrigin(window);
image.drawRect(
board.x - BOARD_FRAME,
board.y - BOARD_FRAME,
COLS * CELL + 2 * BOARD_FRAME,
ROWS * CELL + 2 * BOARD_FRAME,
120,
);
if (window.phase === "paused") { if (window.phase === "paused") {
// Hide the board so pausing can't be used to study it off the clock. // Hide the board so pausing can't be used to study it off the clock.
drawCenteredIn(image, mediumFont, BOARD_X, COLS * CELL, BOARD_Y + 80, "PAUSED", 230); drawCenteredIn(image, mediumFont, board.x, COLS * CELL, board.y + 80, "PAUSED", 230);
drawCenteredIn(image, smallFont, BOARD_X, COLS * CELL, BOARD_Y + 120, `${GESTURE_CLICK} resume`, 150); drawCenteredIn(image, smallFont, board.x, COLS * CELL, board.y + 120, `${GESTURE_CLICK} resume`, 150);
drawCenteredIn(image, smallFont, BOARD_X, COLS * CELL, BOARD_Y + 140, `${GESTURE_DOUBLE_CLICK} leave`, 150); drawCenteredIn(image, smallFont, board.x, COLS * CELL, board.y + 140, `${GESTURE_DOUBLE_CLICK} leave`, 150);
} else { } else {
paintBoard(image, window); paintBoard(image, window, board);
} }
paintPanel(image, window); paintPanel(image, window, board);
return image; return image;
} }
function paintBoard(image: GrayImage, window: MinesweeperWindow): void { function paintBoard(image: GrayImage, window: MinesweeperWindow, board: BoardOrigin): void {
for (let y = 0; y < ROWS; y++) { for (let y = 0; y < ROWS; y++) {
for (let x = 0; x < COLS; x++) { for (let x = 0; x < COLS; x++) {
paintCell(image, window, x, y); paintCell(image, window, board, x, y);
} }
} }
// Cursor: a double bright outline so it stays visible over any cell. In // Cursor: a double bright outline so it stays visible over any cell. In
// row-select it spans the whole selected row; in column-select it marks the // row-select it spans the whole selected row; in column-select it marks the
// cell (games over show neither). // cell (games over show neither).
if (window.phase !== "playing") return; if (window.phase !== "playing") return;
const cx = BOARD_X + window.cursorX * CELL; const cx = board.x + window.cursorX * CELL;
const cy = BOARD_Y + window.cursorY * CELL; const cy = board.y + window.cursorY * CELL;
if (window.selectMode === "row") { if (window.selectMode === "row") {
image.drawRect(BOARD_X - 1, cy - 1, COLS * CELL + 1, CELL + 1, 255); image.drawRect(board.x - 1, cy - 1, COLS * CELL + 1, CELL + 1, 255);
image.drawRect(BOARD_X, cy, COLS * CELL - 1, CELL - 1, 255); image.drawRect(board.x, cy, COLS * CELL - 1, CELL - 1, 255);
} else { } else {
image.drawRect(cx - 1, cy - 1, CELL + 1, CELL + 1, 255); image.drawRect(cx - 1, cy - 1, CELL + 1, CELL + 1, 255);
image.drawRect(cx, cy, CELL - 1, CELL - 1, 255); image.drawRect(cx, cy, CELL - 1, CELL - 1, 255);
} }
} }
function paintCell(image: GrayImage, window: MinesweeperWindow, x: number, y: number): void { function paintCell(image: GrayImage, window: MinesweeperWindow, board: BoardOrigin, x: number, y: number): void {
const index = y * COLS + x; const index = y * COLS + x;
const cx = BOARD_X + x * CELL; const cx = board.x + x * CELL;
const cy = BOARD_Y + y * CELL; const cy = board.y + y * CELL;
const state = window.cellState[index]!; const state = window.cellState[index]!;
const isMine = window.mines[index] === 1; const isMine = window.mines[index] === 1;
const gameOver = window.phase === "lost"; const gameOver = window.phase === "lost";
@@ -757,21 +788,23 @@ function drawMine(image: GrayImage, cx: number, cy: number, shade: number): void
image.drawLine(centerX - 7, centerY + 7, centerX + 7, centerY - 7, shade); image.drawLine(centerX - 7, centerY + 7, centerX + 7, centerY - 7, shade);
} }
function paintPanel(image: GrayImage, window: MinesweeperWindow): void { /** The stats and gesture hints beside the board, laid out down from its top. */
drawStat(image, PANEL_X, BOARD_Y, "Mines", String(mineCount(window) - window.flagCount)); function paintPanel(image: GrayImage, window: MinesweeperWindow, board: BoardOrigin): void {
drawStat(image, PANEL_X, BOARD_Y + 62, "Time", formatElapsed(elapsedMs(window))); const x = board.x + COLS * CELL + PANEL_GAP;
image.drawText(smallFont, PANEL_X, BOARD_Y + 126, DIFFICULTIES[window.difficultyIndex]!.name, 140); drawStat(image, x, board.y, "Mines", String(mineCount(window) - window.flagCount));
drawStat(image, x, board.y + 62, "Time", formatElapsed(elapsedMs(window)));
image.drawText(smallFont, x, board.y + 126, DIFFICULTIES[window.difficultyIndex]!.name, 140);
if (window.phase === "won" || window.phase === "lost") { if (window.phase === "won" || window.phase === "lost") {
image.drawText(mediumFont, PANEL_X, BOARD_Y + 152, window.phase === "won" ? "CLEARED!" : "BOOM!", 250); image.drawText(mediumFont, x, board.y + 152, window.phase === "won" ? "CLEARED!" : "BOOM!", 250);
image.drawText(smallFont, PANEL_X, BOARD_Y + 178, `${GESTURE_CLICK} new game`, 150); image.drawText(smallFont, x, board.y + 178, `${GESTURE_CLICK} new game`, 150);
image.drawText(smallFont, PANEL_X, BOARD_Y + 198, `${GESTURE_LONG_PRESS} menu`, 150); image.drawText(smallFont, x, board.y + 198, `${GESTURE_LONG_PRESS} menu`, 150);
} else if (window.selectMode === "row") { } else if (window.selectMode === "row") {
image.drawText(smallFont, PANEL_X, 200, `${GESTURE_SCROLL} row ${GESTURE_CLICK} pick`, 115); image.drawText(smallFont, x, board.y + 186, `${GESTURE_SCROLL} row ${GESTURE_CLICK} pick`, 115);
image.drawText(smallFont, PANEL_X, 222, `${GESTURE_DOUBLE_CLICK} pause`, 115); image.drawText(smallFont, x, board.y + 208, `${GESTURE_DOUBLE_CLICK} pause`, 115);
} else { } else {
image.drawText(smallFont, PANEL_X, 200, `${GESTURE_SCROLL} cell ${GESTURE_CLICK} dig`, 115); image.drawText(smallFont, x, board.y + 186, `${GESTURE_SCROLL} cell ${GESTURE_CLICK} dig`, 115);
image.drawText(smallFont, PANEL_X, 222, `${GESTURE_LONG_PRESS} flag ${GESTURE_DOUBLE_CLICK} rows`, 115); image.drawText(smallFont, x, board.y + 208, `${GESTURE_LONG_PRESS} flag ${GESTURE_DOUBLE_CLICK} rows`, 115);
} }
} }
+51 -27
View File
@@ -11,13 +11,24 @@ import {
} from "../../native/media-browser"; } from "../../native/media-browser";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
/** Header: title line + path line (34px at the 12px bitmap default). */ /** Header: title line + path line (26px at the 12px bitmap default), below the window's top padding. */
function headerHeight(font: UiFont): number { function headerHeight(font: UiFont): number {
return 8 + lineStep(font) + font.lineHeight; return lineStep(font) + font.lineHeight;
} }
const LIST_X = 20; /**
/** The selection box extends this far left and right of the row text. */ * The selection box extends this far left and right of the row text. The
* boxes start at the window's left padding, so the title, path and hint
* line, which line up with the row text, start this far in from it.
*/
const LIST_HIGHLIGHT_PAD = 6; const LIST_HIGHLIGHT_PAD = 6;
/** Status messages (connecting, errors, empty) are indented this far from the title, and sit this far under the header. */
const MESSAGE_INDENT = 4;
const MESSAGE_GAP = 8;
/** Clear rows between the list and the hint line under it. */
const FOOTER_GAP = 7;
/** Width of the bar Menu.drawScrollbar draws, and the room kept for it right of the rows. */
const SCROLLBAR_WIDTH = 3;
const SCROLLBAR_GUTTER = 6;
export type MediaBrowseOptions = { export type MediaBrowseOptions = {
app: MediaBrowserApp; app: MediaBrowserApp;
@@ -59,55 +70,68 @@ export class MediaBrowseLayer implements Layer {
this.startConnect(ctx); this.startConnect(ctx);
} }
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
// The list's selection boxes span the window's side padding, less the
// scrollbar's gutter. The header and the hint line are fixed, inside the
// top and bottom padding, with the list scrolling between them.
const listX = padding.left;
const textX = listX + LIST_HIGHLIGHT_PAD;
const textWidth = width - padding.left - padding.right - 2 * LIST_HIGHLIGHT_PAD;
const headerBottom = padding.top + headerHeight(font);
const messageX = textX + MESSAGE_INDENT;
const messageY = headerBottom + MESSAGE_GAP;
const footerY = height - padding.bottom - font.lineHeight;
image.drawText(font, 20, 8, `Library: ${this.options.app.appName}`, 220); image.drawText(font, textX, padding.top, `Library: ${this.options.app.appName}`, 220);
if (this.phase === "connecting" || this.phase === "idle") { if (this.phase === "connecting" || this.phase === "idle") {
image.drawText(font, 24, headerHeight(font) + 8, `Starting ${this.options.app.appName}...`, 150); image.drawText(font, messageX, messageY, `Starting ${this.options.app.appName}...`, 150);
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} back`, 110); image.drawText(font, textX, footerY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image; return image;
} }
if (this.phase === "failed") { if (this.phase === "failed") {
image.drawText(font, 24, headerHeight(font) + 8, "Could not connect:", 180); image.drawText(font, messageX, messageY, "Could not connect:", 180);
image.drawText(font, 24, headerHeight(font) + 8 + lineStep(font), truncateRight(font, this.connectError, width - 48), 140); image.drawText(font, messageX, messageY + lineStep(font), truncateRight(font, this.connectError, textWidth - 2 * MESSAGE_INDENT), 140);
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_CLICK} retry ${GESTURE_DOUBLE_CLICK} back`, 110); image.drawText(font, textX, footerY, `${GESTURE_CLICK} retry ${GESTURE_DOUBLE_CLICK} back`, 110);
return image; return image;
} }
const level = this.currentLevel(); const level = this.currentLevel();
const path = this.levels.map((entry) => entry.title).join(" / "); const path = this.levels.map((entry) => entry.title).join(" / ");
image.drawText(font, 20, 8 + lineStep(font), truncateLeft(font, path, width - 40), 130); image.drawText(font, textX, padding.top + lineStep(font), truncateLeft(font, path, textWidth), 130);
if (!level || level.items === null) { if (!level || level.items === null) {
image.drawText(font, 24, headerHeight(font) + 8, level?.error ? level.error : "Loading...", level?.error ? 140 : 150); image.drawText(font, messageX, messageY, level?.error ? level.error : "Loading...", level?.error ? 140 : 150);
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} up / back`, 110); image.drawText(font, textX, footerY, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
return image; return image;
} }
const items = level.items; const items = level.items;
if (!items.length) { if (!items.length) {
image.drawText(font, 24, headerHeight(font) + 8, "(empty)", 120); image.drawText(font, messageX, messageY, "(empty)", 120);
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} up / back`, 110); image.drawText(font, textX, footerY, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
return image; return image;
} }
const listTop = headerHeight(font);
const listHeight = height - listTop - font.lineHeight - 10;
const visibleRows = Math.max(1, (listHeight / tightRowHeight(font)) | 0);
// Row boxes start one pixel above the header's bottom edge. // Row boxes start one pixel above the header's bottom edge.
level.menu.paint( const listTop = headerBottom - 1;
image, const listBottom = footerY - FOOTER_GAP;
{ x: LIST_X - LIST_HIGHLIGHT_PAD, y: listTop - 1, width: width - 2 * LIST_X + 2 * LIST_HIGHLIGHT_PAD, height: listHeight }, if (listBottom > listTop) {
ctx.stack.isFocused(), level.menu.paint(
); image,
level.menu.drawScrollbar(image, width - 12, listTop, visibleRows * tightRowHeight(font) - 4); { x: listX, y: listTop, width: width - padding.left - padding.right - SCROLLBAR_GUTTER, height: listBottom - listTop },
ctx.stack.isFocused(),
);
// The bar hugs the window's right padding, a little short of the list's ends.
const trackHeight = listBottom - listTop - 4;
if (trackHeight > 0) level.menu.drawScrollbar(image, width - padding.right - SCROLLBAR_WIDTH, headerBottom, trackHeight);
}
image.drawText( image.drawText(
font, font,
20, textX,
height - 16, footerY,
`${GESTURE_SCROLL} select ${GESTURE_CLICK} open/play ${GESTURE_DOUBLE_CLICK} up / back`, `${GESTURE_SCROLL} select ${GESTURE_CLICK} open/play ${GESTURE_DOUBLE_CLICK} up / back`,
110, 110,
); );
+119 -73
View File
@@ -14,26 +14,41 @@ import { MusicSettingsLayer } from "./music-settings";
import { spotifyMenuItem } from "./spotify-menu"; import { spotifyMenuItem } from "./spotify-menu";
import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers"; import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
import { createInProcessWindow, YieldAtRootLayer, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window"; import { createInProcessWindow, YieldAtRootLayer, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window";
import type { Viewport } from "../../ui/viewport";
export const MUSIC_WINDOW_ID = "music"; export const MUSIC_WINDOW_ID = "music";
export const MUSIC_SURFACE_ID = "window:music"; export const MUSIC_SURFACE_ID = "window:music";
const ART_SIZE = 112; const ART_SIZE = 112;
const ART_X = 8; // left margin matches the top margin /**
const ART_Y = 8; * The outline hugging the album art. It is the outermost thing the
const META_X = ART_X + ART_SIZE + 14; * now-playing page draws toward the window's top and left edges, so it sits
const PROGRESS_BAR_Y = ART_Y + 116; * at the padding suggested for them and the art just inside it.
*/
const ART_FRAME = 1;
/** Gap between the art and the metadata column. */
const META_GAP = 14;
/** The metadata's first line, the progress bar and the lists, down from the art's top. */
const META_OFFSET_Y = 2;
const PROGRESS_BAR_OFFSET_Y = 116;
const LIST_OFFSET_Y = 128;
/** Clear rows between the time labels' baseline (digits have no descenders) and the bar. */ /** Clear rows between the time labels' baseline (digits have no descenders) and the bar. */
const PROGRESS_TIME_GAP = 3; const PROGRESS_TIME_GAP = 3;
const LIST_TOP = 136;
/** Gap between the menus' last row band and the viewport bottom. */
const LIST_BOTTOM_MARGIN = 4;
const ACTION_X = 22;
const ACTION_WIDTH = 154; const ACTION_WIDTH = 154;
const COLUMN_DIVIDER_X = 190;
const QUEUE_X = 204;
/** Horizontal inset of row text from its selection box. */ /** Horizontal inset of row text from its selection box. */
const LIST_TEXT_INSET = 6; const LIST_TEXT_INSET = 6;
/** The actions column's selection boxes, which start at the window's left padding. */
const ACTION_BOX_WIDTH = ACTION_WIDTH + 2 * LIST_TEXT_INSET - 4;
/** The column divider and the queue's selection boxes, right of the actions column's left edge. */
const COLUMN_DIVIDER_OFFSET_X = 174;
const QUEUE_OFFSET_X = 182;
/** Width of the bar Menu.drawScrollbar draws, and the room kept for it right of a list's rows. */
const SCROLLBAR_WIDTH = 3;
const SCROLLBAR_GUTTER = 6;
/** How far the setup prompt's text is indented from its hint line. */
const PROMPT_INDENT = 4;
/** Gap between the no-session page's status line, its prompt and its list. */
const SECTION_GAP = 6;
const PLAYLIST_ACTION_INDEX = 1; const PLAYLIST_ACTION_INDEX = 1;
/** Minimum room for the dim artist after a queue row's title; less and it is left off. */ /** Minimum room for the dim artist after a queue row's title; less and it is left off. */
const QUEUE_SUBTITLE_MIN_WIDTH = 40; const QUEUE_SUBTITLE_MIN_WIDTH = 40;
@@ -102,107 +117,111 @@ class MusicAppLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const { width, height, padding } = viewport;
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const media = mediaControllerBridge.snapshot(); const media = mediaControllerBridge.snapshot();
if (!media.accessEnabled) { if (!media.accessEnabled) {
const lines = wrapText(font, mediaControllerBridge.accessPrompt, width - 48); // The hint line sits at the window's left and bottom padding; the
// prompt is indented from it, as far from the right padding as the left.
const lines = wrapText(font, mediaControllerBridge.accessPrompt, width - padding.left - padding.right - 2 * PROMPT_INDENT);
for (let index = 0; index < lines.length; index++) { for (let index = 0; index < lines.length; index++) {
image.drawText(font, 24, 16 + index * lineStep(font), lines[index]!, 180); image.drawText(font, padding.left + PROMPT_INDENT, padding.top + index * lineStep(font), lines[index]!, 180);
} }
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} ${mediaControllerBridge.accessAction}`, 110); image.drawText(font, padding.left, height - padding.bottom - font.lineHeight, `${GESTURE_CLICK} ${mediaControllerBridge.accessAction}`, 110);
return image; return image;
} }
// Lists' selection boxes start at the window's left padding and stop
// short of the scrollbar, which hugs the right padding.
const listX = padding.left;
const rowsRight = width - padding.right - SCROLLBAR_GUTTER;
const focused = ctx.stack.isFocused();
if (!media.available) { if (!media.available) {
const apps = mediaBrowserBridge.listBrowsableApps(!this.libraryAppsFresh); const apps = mediaBrowserBridge.listBrowsableApps(!this.libraryAppsFresh);
this.libraryAppsFresh = true; this.libraryAppsFresh = true;
this.libraryMenu.setItems(apps); this.libraryMenu.setItems(apps);
image.drawText(font, 24, 16, global.isIOS ? media.status || "Nothing is playing." : "No active media session.", 180); // The text lines up with the picker's row text.
const textX = listX + LIST_TEXT_INSET;
const textWidth = rowsRight - listX - 2 * LIST_TEXT_INSET;
image.drawText(font, textX, padding.top, global.isIOS ? media.status || "Nothing is playing." : "No active media session.", 180);
const prompt = global.isIOS const prompt = global.isIOS
? "Browse your library, or start playback on the phone." ? "Browse your library, or start playback on the phone."
: apps.length : apps.length
? "Browse a music app's library, or start playback on the phone." ? "Browse a music app's library, or start playback on the phone."
: "Start playback in another app on the phone."; : "Start playback in another app on the phone.";
let y = 22 + lineStep(font); let y = padding.top + lineStep(font) + SECTION_GAP;
for (const line of wrapText(font, prompt, width - 48)) { for (const line of wrapText(font, prompt, textWidth)) {
image.drawText(font, 24, y, line, 150); image.drawText(font, textX, y, line, 150);
y += lineStep(font); y += lineStep(font);
} }
// Why the last command failed (e.g. playing from the Spotify library with no device open). // Why the last command failed (e.g. playing from the Spotify library with no device open).
for (const line of media.notice ? wrapText(font, media.notice, width - 48) : []) { for (const line of media.notice ? wrapText(font, media.notice, textWidth) : []) {
image.drawText(font, 24, y, line, 200); image.drawText(font, textX, y, line, 200);
y += lineStep(font); y += lineStep(font);
} }
if (apps.length) { if (apps.length) {
const listTop = y + 6; paintListToBottomEdge(image, this.libraryMenu, { x: listX, top: y + SECTION_GAP, width: rowsRight - listX }, viewport, focused, true);
const listHeight = height - listTop - LIST_BOTTOM_MARGIN;
this.libraryMenu.paint(
image,
{ x: 24 - LIST_TEXT_INSET, y: listTop - 1, width: width - 48 + 2 * LIST_TEXT_INSET - 4, height: listHeight },
ctx.stack.isFocused(),
);
this.libraryMenu.drawScrollbar(image, width - 12, listTop, listHeight - 4);
} }
return image; return image;
} }
this.libraryAppsFresh = false; this.libraryAppsFresh = false;
this.drawArt(image, media); const artX = padding.left + ART_FRAME;
const artY = padding.top + ART_FRAME;
this.drawArt(image, media, artX, artY);
const metaWidth = width - META_X - 24; // The metadata column and the progress bar end at the window's right padding.
const metaX = artX + ART_SIZE + META_GAP;
const metaWidth = width - padding.right - metaX;
const metaStep = lineStep(font) + 1; const metaStep = lineStep(font) + 1;
const metaTop = ART_Y + 2; const metaTop = artY + META_OFFSET_Y;
const progressBarY = artY + PROGRESS_BAR_OFFSET_Y;
// Line budget above the progress-bar time line: the layout is five slots // Line budget above the progress-bar time line: the layout is five slots
// (title, second title line, artist, album, player app); when the font is // (title, second title line, artist, album, player app); when the font is
// too large for all five, the title gets one truncated line instead of // too large for all five, the title gets one truncated line instead of
// wrapping to two, and the rest shift up a slot. // wrapping to two, and the rest shift up a slot.
const maxLines = Math.floor((progressTimeY(font) - metaTop - 4 - font.lineHeight) / metaStep) + 1; const maxLines = Math.floor((progressTimeY(font, progressBarY) - metaTop - 4 - font.lineHeight) / metaStep) + 1;
const titleSlots = maxLines >= 5 ? 2 : 1; const titleSlots = maxLines >= 5 ? 2 : 1;
const title = media.title || "Unknown title"; const title = media.title || "Unknown title";
const titleLines = const titleLines =
titleSlots === 2 ? wrapText(font, title, metaWidth).slice(0, 2) : [truncateText(font, title, metaWidth)]; titleSlots === 2 ? wrapText(font, title, metaWidth).slice(0, 2) : [truncateText(font, title, metaWidth)];
for (let index = 0; index < titleLines.length; index++) { for (let index = 0; index < titleLines.length; index++) {
image.drawText(font, META_X, metaTop + index * metaStep, titleLines[index]!, 230); image.drawText(font, metaX, metaTop + index * metaStep, titleLines[index]!, 230);
} }
image.drawText(font, META_X, metaTop + 4 + titleSlots * metaStep, media.artist || "Unknown artist", 180); image.drawText(font, metaX, metaTop + 4 + titleSlots * metaStep, media.artist || "Unknown artist", 180);
if (media.album) { if (media.album) {
image.drawText(font, META_X, metaTop + 4 + (titleSlots + 1) * metaStep, truncateText(font, media.album, metaWidth), 150); image.drawText(font, metaX, metaTop + 4 + (titleSlots + 1) * metaStep, truncateText(font, media.album, metaWidth), 150);
} }
// The player line, or for a few seconds why a command failed. // The player line, or for a few seconds why a command failed.
image.drawText( image.drawText(
font, font,
META_X, metaX,
metaTop + 4 + (titleSlots + 2) * metaStep, metaTop + 4 + (titleSlots + 2) * metaStep,
truncateText(font, media.notice || media.appName || media.packageName, metaWidth), truncateText(font, media.notice || media.appName || media.packageName, metaWidth),
media.notice ? 200 : 110, media.notice ? 200 : 110,
); );
this.drawProgress(image, media, metaWidth); this.drawProgress(image, media, metaX, progressBarY, metaWidth);
const queue = mediaControllerBridge.getQueue(); const queue = mediaControllerBridge.getQueue();
const actions = this.buildActions(media, queue); const actions = this.buildActions(media, queue);
this.reconcileSelection(actions, queue); this.reconcileSelection(actions, queue);
const listHeight = height - LIST_TOP - LIST_BOTTOM_MARGIN; const listTop = artY + LIST_OFFSET_Y;
const focused = ctx.stack.isFocused(); paintListToBottomEdge(image, this.actionsMenu, { x: listX, top: listTop, width: ACTION_BOX_WIDTH }, viewport,
// Row boxes start one pixel above LIST_TOP, level with the column divider. focused && this.focusColumn === "actions");
this.actionsMenu.paint(
image,
{ x: ACTION_X - LIST_TEXT_INSET, y: LIST_TOP - 1, width: ACTION_WIDTH + 2 * LIST_TEXT_INSET - 4, height: listHeight },
focused && this.focusColumn === "actions",
);
image.drawLine(COLUMN_DIVIDER_X, LIST_TOP - 3, COLUMN_DIVIDER_X, height - LIST_BOTTOM_MARGIN - 3, 45); // The divider is fixed, so it stops at the window's bottom padding.
const dividerX = listX + COLUMN_DIVIDER_OFFSET_X;
const dividerBottom = height - padding.bottom - 1;
if (dividerBottom > listTop) image.drawLine(dividerX, listTop - 3, dividerX, dividerBottom, 45);
const queueX = listX + QUEUE_OFFSET_X;
if (!queue.length) { if (!queue.length) {
image.drawText(font, QUEUE_X, LIST_TOP + 1, "Playlist unavailable", 90); image.drawText(font, queueX + LIST_TEXT_INSET, listTop + 1, "Playlist unavailable", 90);
} else { } else {
const queueWidth = width - QUEUE_X - 20; paintListToBottomEdge(image, this.queueMenu, { x: queueX, top: listTop, width: rowsRight - queueX }, viewport,
this.queueMenu.paint( focused && this.focusColumn === "playlist", true);
image,
{ x: QUEUE_X - LIST_TEXT_INSET, y: LIST_TOP - 1, width: queueWidth + 2 * LIST_TEXT_INSET - 4, height: listHeight },
focused && this.focusColumn === "playlist",
);
this.queueMenu.drawScrollbar(image, width - 12, LIST_TOP, listHeight - 4);
} }
return image; return image;
@@ -386,22 +405,23 @@ class MusicAppLayer implements Layer {
} }
} }
private drawProgress(image: GrayImage, media: MediaControllerState, width: number): void { /** The elapsed/duration labels and, under them, the bar at (x, barY), `width` wide. */
private drawProgress(image: GrayImage, media: MediaControllerState, x: number, barY: number, width: number): void {
if (media.durationMs <= 0 || media.positionMs < 0) return; if (media.durationMs <= 0 || media.positionMs < 0) return;
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const elapsed = formatMediaTime(media.positionMs); const elapsed = formatMediaTime(media.positionMs);
const duration = formatMediaTime(media.durationMs); const duration = formatMediaTime(media.durationMs);
const timeY = progressTimeY(font); const timeY = progressTimeY(font, barY);
image.drawText(font, META_X, timeY, elapsed, 140); image.drawText(font, x, timeY, elapsed, 140);
image.drawText(font, META_X + width - font.measureText(duration), timeY, duration, 140); image.drawText(font, x + width - font.measureText(duration), timeY, duration, 140);
const barY = PROGRESS_BAR_Y; image.drawRect(x, barY, width, 5, 55);
image.drawRect(META_X, barY, width, 5, 55);
const progress = clamp(media.positionMs / media.durationMs, 0, 1); const progress = clamp(media.positionMs / media.durationMs, 0, 1);
image.fillRect(META_X + 1, barY + 1, Math.round((width - 2) * progress), 3, 170); image.fillRect(x + 1, barY + 1, Math.round((width - 2) * progress), 3, 170);
} }
private drawArt(image: GrayImage, media: MediaControllerState): void { /** The album art, or a placeholder, in the ART_SIZE box at (artX, artY), with its outline around it. */
private drawArt(image: GrayImage, media: MediaControllerState, artX: number, artY: number): void {
// Keyed on artVersion, not the strings: players (e.g. Spotify) publish // Keyed on artVersion, not the strings: players (e.g. Spotify) publish
// metadata before the art bitmap is downloaded, or with the previous // metadata before the art bitmap is downloaded, or with the previous
// track's bitmap after a quick double skip, then re-emit the same // track's bitmap after a quick double skip, then re-emit the same
@@ -412,17 +432,18 @@ class MusicAppLayer implements Layer {
} }
if (this.art) { if (this.art) {
// Center within the art box. // Center within the art box.
const dx = ART_X + Math.max(0, ((ART_SIZE - this.art.width) / 2) | 0); const dx = artX + Math.max(0, ((ART_SIZE - this.art.width) / 2) | 0);
const dy = ART_Y + Math.max(0, ((ART_SIZE - this.art.height) / 2) | 0); const dy = artY + Math.max(0, ((ART_SIZE - this.art.height) / 2) | 0);
image.bitBlt(this.art, dx, dy); image.bitBlt(this.art, dx, dy);
image.drawRect(dx - 1, dy - 1, this.art.width + 2, this.art.height + 2, 60); image.drawRect(dx - ART_FRAME, dy - ART_FRAME, this.art.width + 2 * ART_FRAME, this.art.height + 2 * ART_FRAME, 60);
} else { } else {
image.drawRect(ART_X, ART_Y, ART_SIZE, ART_SIZE, 60); // The placeholder's outline is where a full-size cover's would be.
image.drawRect(artX - ART_FRAME, artY - ART_FRAME, ART_SIZE + 2 * ART_FRAME, ART_SIZE + 2 * ART_FRAME, 60);
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
image.drawText( image.drawText(
font, font,
ART_X + Math.round((ART_SIZE - font.measureText("no art")) / 2), artX + Math.round((ART_SIZE - font.measureText("no art")) / 2),
ART_Y + Math.round((ART_SIZE - font.lineHeight) / 2), artY + Math.round((ART_SIZE - font.lineHeight) / 2),
"no art", "no art",
90, 90,
); );
@@ -567,12 +588,37 @@ export function createMusicAppWindow(options: InProcessAppOptions): InProcessWin
} }
/** /**
* Line top of the elapsed/duration labels: their baseline sits a fixed gap * Paint a list that scrolls under fixed content: from `top` down to the
* above the progress bar, so the labels hug the bar whatever the font's * window's bottom edge, where a row cut off for scrolling meets the edge,
* height (a taller face grows upward into the metadata's line budget). * with that edge's padding inside the list after its last row. Selection
* boxes start one pixel above `top`. The scrollbar, when asked for, stays
* inside the window's right and bottom padding.
*/ */
function progressTimeY(font: UiFont): number { function paintListToBottomEdge<T>(
return PROGRESS_BAR_Y - PROGRESS_TIME_GAP - font.ascent; image: GrayImage,
menu: Menu<T>,
rows: { x: number; top: number; width: number },
viewport: Viewport,
focused: boolean,
scrollbar = false,
): void {
const { width, height, padding } = viewport;
const boxTop = rows.top - 1;
if (boxTop >= height || rows.width <= 0) return;
menu.paint(image, { x: rows.x, y: boxTop, width: rows.width, height: height - boxTop, padBottom: padding.bottom }, focused);
const trackHeight = height - padding.bottom - rows.top;
if (scrollbar && trackHeight > 0) {
menu.drawScrollbar(image, width - padding.right - SCROLLBAR_WIDTH, rows.top, trackHeight);
}
}
/**
* Line top of the elapsed/duration labels: their baseline sits a fixed gap
* above the progress bar (at barY), so the labels hug the bar whatever the
* font's height (a taller face grows upward into the metadata's line budget).
*/
function progressTimeY(font: UiFont, barY: number): number {
return barY - PROGRESS_TIME_GAP - font.ascent;
} }
function formatMediaTime(milliseconds: number): string { function formatMediaTime(milliseconds: number): string {
+5 -12
View File
@@ -10,7 +10,6 @@ import { drawToggleMenuItem, MenuLayer, type MenuItem } from "../../ui/menu";
/** Discovered apps stay visible even when ignored or no longer publishing a session. */ /** Discovered apps stay visible even when ignored or no longer publishing a session. */
export class MusicSettingsLayer implements Layer { export class MusicSettingsLayer implements Layer {
private menu: MenuLayer | null = null; private menu: MenuLayer | null = null;
private menuWidth = 0;
/** The package behind each current row, parallel to the menu's items. */ /** The package behind each current row, parallel to the menu's items. */
private packages: string[] = []; private packages: string[] = [];
@@ -20,7 +19,7 @@ export class MusicSettingsLayer implements Layer {
} }
/** Refresh the rows from the remembered apps, keeping the selection on the same package. */ /** Refresh the rows from the remembered apps, keeping the selection on the same package. */
private currentMenu(ctx: LayerContext): MenuLayer { private currentMenu(): MenuLayer {
const apps = readMediaApps().sort((a, b) => const apps = readMediaApps().sort((a, b) =>
a.appName.localeCompare(b.appName) || a.packageName.localeCompare(b.packageName)); a.appName.localeCompare(b.appName) || a.packageName.localeCompare(b.packageName));
const items: MenuItem[] = apps.map((app) => ({ const items: MenuItem[] = apps.map((app) => ({
@@ -39,14 +38,8 @@ export class MusicSettingsLayer implements Layer {
const index = apps.findIndex((app) => app.packageName === selectedPackage); const index = apps.findIndex((app) => app.packageName === selectedPackage);
this.packages = apps.map((app) => app.packageName); this.packages = apps.map((app) => app.packageName);
const width = ctx.stack.getBaseSize().width; if (!this.menu) {
if (!this.menu || width !== this.menuWidth) { this.menu = new MenuLayer("Music settings", items, { page: true, footer: "On = enabled Off = ignored" }).selectItem(Math.max(0, index));
this.menuWidth = width;
this.menu = new MenuLayer("Music settings", items, {
x: 8, y: 8, width: width - 16,
opaque: true, showBorder: false,
footer: "On = enabled Off = ignored",
}).selectItem(Math.max(0, index));
} else { } else {
this.menu.setItems(items, index >= 0 ? index : undefined); this.menu.setItems(items, index >= 0 ? index : undefined);
} }
@@ -54,10 +47,10 @@ export class MusicSettingsLayer implements Layer {
} }
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage { paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
return this.currentMenu(ctx).paint(ctx, paintBelow); return this.currentMenu().paint(ctx, paintBelow);
} }
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> { async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
await this.currentMenu(ctx).handleInput(event, ctx); await this.currentMenu().handleInput(event, ctx);
} }
} }
+156 -58
View File
@@ -59,6 +59,7 @@ import {
type SavedDestination, type SavedDestination,
} from "./destinations"; } from "./destinations";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import { sameViewport, type Viewport } from "../../ui/viewport";
import type { ToolSpec, ToolResult } from "../../assistant/tool-registry"; import type { ToolSpec, ToolResult } from "../../assistant/tool-registry";
import { import {
GESTURE_CLICK, GESTURE_CLICK,
@@ -95,7 +96,11 @@ import { drawManeuverGlyph } from "./maneuver-icons";
declare const global: any; declare const global: any;
const MAP_SIZE = 260; const MAP_SIZE = 260;
/** The guidance panel's region beside the map pane, and how far in its content starts. */
const PANEL_X = MAP_SIZE + 10; const PANEL_X = MAP_SIZE + 10;
const PANEL_INSET = 8;
/** Clear space between the footer hint line and what ends above it (the idle list, the map-mode map). */
const FOOTER_GAP = 8;
/** Map refetch policy knobs (design doc: never per-fix, only when stale). */ /** Map refetch policy knobs (design doc: never per-fix, only when stale). */
const BEARING_BUCKET_DEG = 15; const BEARING_BUCKET_DEG = 15;
const MOVE_REFRESH_FRACTION = 0.15; const MOVE_REFRESH_FRACTION = 0.15;
@@ -132,6 +137,13 @@ type NavWindow = {
title: string; title: string;
viewportWidth: number; viewportWidth: number;
viewportHeight: number; viewportHeight: number;
/**
* The viewport as the shell last sent it: besides the size above, what each
* edge touches and the padding suggested there. The maps fill their panes
* whatever the edges touch; text, the idle list and the footer hints keep
* the padding.
*/
viewport: Viewport;
foreground: boolean; foreground: boolean;
focused: boolean; focused: boolean;
menu: WindowMenu | null; menu: WindowMenu | null;
@@ -306,6 +318,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
title: message.title, title: message.title,
viewportWidth: message.viewport.width, viewportWidth: message.viewport.width,
viewportHeight: message.viewport.height, viewportHeight: message.viewport.height,
viewport: message.viewport,
foreground: false, foreground: false,
focused: false, focused: false,
menu: null, menu: null,
@@ -313,19 +326,29 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
}; };
post({ type: "set-tools", windowId: message.windowId, tools: NAVIGATE_TOOLS }); post({ type: "set-tools", windowId: message.windowId, tools: NAVIGATE_TOOLS });
break; break;
case "resize-window": case "resize-window": {
if (!window || window.windowId !== message.windowId) break; if (!window || window.windowId !== message.windowId) break;
if (window.viewportWidth === message.viewport.width && window.viewportHeight === message.viewport.height) break; // The layout follows the padding as well as the size, so a change to
// what the edges touch alone is laid out and painted again too.
if (sameViewport(window.viewport, message.viewport)) break;
const mapSize = phase === "map" ? mapDimensions() : null;
window.viewportWidth = message.viewport.width; window.viewportWidth = message.viewport.width;
window.viewportHeight = message.viewport.height; window.viewportHeight = message.viewport.height;
window.viewport = message.viewport;
window.menu?.resize(message.viewport); window.menu?.resize(message.viewport);
window.lastSubmittedFingerprint = ""; window.lastSubmittedFingerprint = "";
if (phase === "map") { // The map is fetched at the size it is shown at: only a change to that
resetMapState(); // needs a new one.
maybeRefreshMap(); if (mapSize) {
const resized = mapDimensions();
if (resized.width !== mapSize.width || resized.height !== mapSize.height) {
resetMapState();
maybeRefreshMap();
}
} }
render(); render();
break; break;
}
case "close-window": case "close-window":
if (editing) { if (editing) {
// Window closed mid-edit: shut the phone editor down. // Window closed mid-edit: shut the phone editor down.
@@ -826,9 +849,13 @@ function maybeRefreshMap(): void {
}); });
} }
/**
* The map's size: the pane beside the guidance panel, or in map mode the
* whole window down to the footer hint.
*/
function mapDimensions(): { width: number; height: number } { function mapDimensions(): { width: number; height: number } {
return phase === "map" && window return phase === "map" && window
? { width: window.viewportWidth, height: Math.max(1, window.viewportHeight - 30) } ? { width: window.viewportWidth, height: Math.max(1, footerY(window.viewport) - FOOTER_GAP) }
: { width: MAP_SIZE, height: MAP_SIZE }; : { width: MAP_SIZE, height: MAP_SIZE };
} }
@@ -1212,10 +1239,11 @@ function idleEntries(): IdleEntry[] {
return entries; return entries;
} }
/** Horizontal inset of the idle list's selection boxes. */
const IDLE_LIST_X = 20;
/** Pixels between consecutive idle rows' selection boxes. */ /** Pixels between consecutive idle rows' selection boxes. */
const IDLE_ROW_GAP = 2; const IDLE_ROW_GAP = 2;
/** The idle list's scrollbar, and the gap its rows leave before it. */
const IDLE_SCROLLBAR_WIDTH = 3;
const IDLE_SCROLLBAR_GAP = 4;
function idleList(): Menu<IdleEntry> { function idleList(): Menu<IdleEntry> {
idleMenu ??= new Menu<IdleEntry>({ idleMenu ??= new Menu<IdleEntry>({
@@ -1260,7 +1288,7 @@ function windowMenu(win: NavWindow): WindowMenu {
post, post,
title: () => win.title, title: () => win.title,
items: () => windowMenuItems(), items: () => windowMenuItems(),
size: { width: win.viewportWidth, height: win.viewportHeight }, size: win.viewport,
paintBase: () => paintContent(win), paintBase: () => paintContent(win),
isFocused: () => win.focused, isFocused: () => win.focused,
}); });
@@ -1342,12 +1370,28 @@ function paint(win: NavWindow): Plane[] {
return windowMenu(win).paint(); return windowMenu(win).paint();
} }
/**
* Page text (a title, hints, status messages) starts this far inside the
* padding suggested for the window's sides, which is where the idle list's
* selection boxes and the footer hints start.
*/
const TEXT_INSET = 4;
/** How far below a page's title (at the top padding) its text starts: the idle page's hint, the edit screen's message. */
const IDLE_HINT_DROP = 36;
const EDIT_MESSAGE_DROP = 48;
/** Where a page's text starts and how wide it may run. */
function pageText(viewport: Viewport): { x: number; width: number } {
const { width, padding } = viewport;
return { x: padding.left + TEXT_INSET, width: width - padding.left - padding.right - 2 * TEXT_INSET };
}
function paintContent(win: NavWindow): GrayImage { function paintContent(win: NavWindow): GrayImage {
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0); const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0);
if (editing) { if (editing) {
paintEdit(image, editing); paintEdit(image, win, editing);
} else if (phase === "map") { } else if (phase === "map") {
paintMap(image); paintMap(image, win);
} else if (phase === "idle" || phase === "acquiring" || phase === "routing") { } else if (phase === "idle" || phase === "acquiring" || phase === "routing") {
paintIdle(image, win); paintIdle(image, win);
} else { } else {
@@ -1357,27 +1401,31 @@ function paintContent(win: NavWindow): GrayImage {
} }
/** The "type on the phone" screen for a destination name/address edit. */ /** The "type on the phone" screen for a destination name/address edit. */
function paintEdit(image: GrayImage, edit: DestinationEdit): void { function paintEdit(image: GrayImage, win: NavWindow, edit: DestinationEdit): void {
const { padding } = win.viewport;
const text = pageText(win.viewport);
const step = smallFont.lineHeight + 2; const step = smallFont.lineHeight + 2;
image.drawText(mediumFont, 24, 16, edit.title, 245); image.drawText(mediumFont, text.x, padding.top, edit.title, 245);
const messageY = 64; const messageY = padding.top + EDIT_MESSAGE_DROP;
const lines = wrapText(smallFont, "Type the value in the phone app, or use voice input.", image.width - 48); const lines = wrapText(smallFont, "Type the value in the phone app, or use voice input.", text.width);
for (let index = 0; index < lines.length; index++) { for (let index = 0; index < lines.length; index++) {
image.drawText(smallFont, 24, messageY + index * step, lines[index]!, 190); image.drawText(smallFont, text.x, messageY + index * step, lines[index]!, 190);
} }
const value = edit.setting.get(); const value = edit.setting.get();
image.drawText( image.drawText(
smallFont, smallFont,
24, text.x,
messageY + (lines.length + 1) * step, messageY + (lines.length + 1) * step,
truncateText(smallFont, value || "(empty)", image.width - 48), truncateText(smallFont, value || "(empty)", text.width),
value ? 225 : 130, value ? 225 : 130,
); );
drawFooter(image, `${GESTURE_CLICK} done ${GESTURE_DOUBLE_CLICK} cancel`); drawFooter(image, win.viewport, `${GESTURE_CLICK} done ${GESTURE_DOUBLE_CLICK} cancel`);
} }
function paintIdle(image: GrayImage, win: NavWindow): void { function paintIdle(image: GrayImage, win: NavWindow): void {
image.drawText(mediumFont, 24, 16, "Navigate", 245); const { padding } = win.viewport;
const text = pageText(win.viewport);
image.drawText(mediumFont, text.x, padding.top, "Navigate", 245);
const busy = phase !== "idle"; const busy = phase !== "idle";
const entries = busy ? [] : idleEntries(); const entries = busy ? [] : idleEntries();
const configured = isMapboxConfigured(); const configured = isMapboxConfigured();
@@ -1386,16 +1434,17 @@ function paintIdle(image: GrayImage, win: NavWindow): void {
: entries.length : entries.length
? "View the map or pick a destination below. Use Voice input (system menu, long-press) to say a destination." ? "View the map or pick a destination below. Use Voice input (system menu, long-press) to say a destination."
: "Ask the voice assistant to navigate somewhere, or pick Voice input from the system menu (long-press) to say a destination. Save Home, Work and other places from the app menu."; : "Ask the voice assistant to navigate somewhere, or pick Voice input from the system menu (long-press) to say a destination. Save Home, Work and other places from the app menu.";
const hintLines = wrapText(smallFont, hint, image.width - 48); const hintLines = wrapText(smallFont, hint, text.width);
const hintStep = smallFont.lineHeight + 2; const hintStep = smallFont.lineHeight + 2;
const hintY = padding.top + IDLE_HINT_DROP;
for (let index = 0; index < hintLines.length; index++) { for (let index = 0; index < hintLines.length; index++) {
image.drawText(smallFont, 24, 52 + index * hintStep, hintLines[index]!, 170); image.drawText(smallFont, text.x, hintY + index * hintStep, hintLines[index]!, 170);
} }
let y = 52 + hintLines.length * hintStep + 6; let y = hintY + hintLines.length * hintStep + 6;
if (statusMessage) { if (statusMessage) {
const statusLines = wrapText(smallFont, statusMessage, image.width - 48); const statusLines = wrapText(smallFont, statusMessage, text.width);
for (let index = 0; index < statusLines.length; index++) { for (let index = 0; index < statusLines.length; index++) {
image.drawText(smallFont, 24, y + index * hintStep, statusLines[index]!, busy ? 220 : 190); image.drawText(smallFont, text.x, y + index * hintStep, statusLines[index]!, busy ? 220 : 190);
} }
y += statusLines.length * hintStep + 6; y += statusLines.length * hintStep + 6;
} }
@@ -1403,23 +1452,34 @@ function paintIdle(image: GrayImage, win: NavWindow): void {
paintIdleList(image, win, entries, y); paintIdleList(image, win, entries, y);
drawFooter( drawFooter(
image, image,
win.viewport,
`${GESTURE_SCROLL} select ${GESTURE_CLICK} ${configured ? "go" : "choose"} ${GESTURE_SHORT_THEN_LONG_PRESS} app menu ${GESTURE_DOUBLE_CLICK} back`, `${GESTURE_SCROLL} select ${GESTURE_CLICK} ${configured ? "go" : "choose"} ${GESTURE_SHORT_THEN_LONG_PRESS} app menu ${GESTURE_DOUBLE_CLICK} back`,
); );
} else { } else {
drawFooter(image, `${GESTURE_SHORT_THEN_LONG_PRESS} app menu ${GESTURE_DOUBLE_CLICK} back`); drawFooter(image, win.viewport, `${GESTURE_SHORT_THEN_LONG_PRESS} app menu ${GESTURE_DOUBLE_CLICK} back`);
} }
} }
/** Map action, saved destinations, then recent places, one selectable row each. */ /**
* Map action, saved destinations, then recent places, one selectable row
* each. The list scrolls between the page's text above it and the footer
* hint, both of which stay put, so it needs no padding of its own at its
* top and bottom; its selection boxes span the window between the padding
* suggested for the sides.
*/
function paintIdleList(image: GrayImage, win: NavWindow, entries: IdleEntry[], top: number): void { function paintIdleList(image: GrayImage, win: NavWindow, entries: IdleEntry[], top: number): void {
const { width, padding } = win.viewport;
const rowHeight = listRowHeight(smallFont); const rowHeight = listRowHeight(smallFont);
const listBottom = image.height - 30; const listBottom = footerY(win.viewport) - FOOTER_GAP;
const visibleRows = Math.max(1, Math.floor((listBottom - top) / rowHeight)); const visibleRows = Math.max(1, Math.floor((listBottom - top) / rowHeight));
const rowWidth = image.width - 40 - (entries.length > visibleRows ? 10 : 0); const listHeight = visibleRows * rowHeight - IDLE_ROW_GAP;
// The scrollbar hugs the right padding; the rows give way to it only when there is one.
const right = width - padding.right;
const scrollbar = entries.length > visibleRows ? IDLE_SCROLLBAR_GAP + IDLE_SCROLLBAR_WIDTH : 0;
const list = idleList(); const list = idleList();
list.setItems(entries); list.setItems(entries);
list.paint(image, { x: IDLE_LIST_X, y: top, width: rowWidth, height: visibleRows * rowHeight - IDLE_ROW_GAP }, win.focused); list.paint(image, { x: padding.left, y: top, width: right - scrollbar - padding.left, height: listHeight }, win.focused);
list.drawScrollbar(image, IDLE_LIST_X + rowWidth + 4, top, visibleRows * rowHeight - 2); list.drawScrollbar(image, right - IDLE_SCROLLBAR_WIDTH, top, listHeight);
} }
/** Two columns: the entry's name, then its detail (action hint, address or place). */ /** Two columns: the entry's name, then its detail (action hint, address or place). */
@@ -1444,6 +1504,22 @@ function drawIdleRow({ image, item: entry, x, y, width, selected }: MenuDrawArgs
image.drawText(smallFont, detailX, textY, truncateText(smallFont, detail, x + width - 6 - detailX), selected ? 170 : 130); image.drawText(smallFont, detailX, textY, truncateText(smallFont, detail, x + width - 6 - detailX), selected ? 170 : 130);
} }
// The guidance panel's head, measured from the maneuver glyph's top-left
// corner (the panel's content x, at the window's top padding).
const GLYPH_SIZE = 56;
/** Text beside the glyph: the distance to the maneuver, or "Arrived". */
const GLYPH_CAPTION_X = 68;
const DISTANCE_Y = 10;
const ARRIVED_Y = 12;
/** A roundabout's exit number, inside its glyph. */
const EXIT_NUMBER_X = 22;
const EXIT_NUMBER_Y = 32;
/** The instruction (or the destination's name) under the glyph. */
const INSTRUCTION_Y = 70;
/** Clear space under the panel's status line (above the footer hint) and under its ETA line (above the status). */
const PANEL_STATUS_GAP = 10;
const PANEL_ETA_GAP = 6;
function paintNavigating(image: GrayImage, win: NavWindow): void { function paintNavigating(image: GrayImage, win: NavWindow): void {
// Map pane (left). // Map pane (left).
if (mapImage) { if (mapImage) {
@@ -1460,72 +1536,87 @@ function paintNavigating(image: GrayImage, win: NavWindow): void {
image.drawText(smallFont, 24, MAP_SIZE / 2 - 8, text, 120); image.drawText(smallFont, 24, MAP_SIZE / 2 - 8, text, 120);
} }
// Guidance panel (right) — its own region so text deltas never overlap the map's. // Guidance panel (right) — its own region so text deltas never overlap the
const panelWidth = win.viewportWidth - PANEL_X; // map's. Its left side is placed from the map pane; its top, right and
// bottom keep the padding suggested for the window's edges.
const { padding } = win.viewport;
const x = PANEL_X + PANEL_INSET;
const top = padding.top;
const textWidth = win.viewportWidth - padding.right - x;
if (phase === "arrived") { if (phase === "arrived") {
drawManeuverGlyph(image, PANEL_X + 8, 14, 56, "arrive", "", 245); drawManeuverGlyph(image, x, top, GLYPH_SIZE, "arrive", "", 245);
image.drawText(mediumFont, PANEL_X + 76, 26, "Arrived", 245); image.drawText(mediumFont, x + GLYPH_CAPTION_X, top + ARRIVED_Y, "Arrived", 245);
image.drawTextWrapped({ image.drawTextWrapped({
font: smallFont, font: smallFont,
x: PANEL_X + 8, x,
y: 84, y: top + INSTRUCTION_Y,
width: panelWidth - 16, width: textWidth,
text: destinationName, text: destinationName,
value: 200, value: 200,
}); });
drawFooter(image, `${GESTURE_CLICK} done ${GESTURE_DOUBLE_CLICK} back`); drawFooter(image, win.viewport, `${GESTURE_CLICK} done ${GESTURE_DOUBLE_CLICK} back`);
return; return;
} }
// The status and ETA lines stack above the footer hint.
const statusY = footerY(win.viewport) - smallFont.lineHeight - PANEL_STATUS_GAP;
const step = follower && progress ? follower.route.steps[progress.nextStepIndex] : null; const step = follower && progress ? follower.route.steps[progress.nextStepIndex] : null;
if (step && progress) { if (step && progress) {
drawManeuverGlyph(image, PANEL_X + 8, 14, 56, step.maneuverType, step.maneuverModifier, 245); drawManeuverGlyph(image, x, top, GLYPH_SIZE, step.maneuverType, step.maneuverModifier, 245);
if (step.exit !== null && (step.maneuverType === "roundabout" || step.maneuverType === "rotary")) { if (step.exit !== null && (step.maneuverType === "roundabout" || step.maneuverType === "rotary")) {
image.drawText(smallFont, PANEL_X + 30, 46, String(step.exit), 245); image.drawText(smallFont, x + EXIT_NUMBER_X, top + EXIT_NUMBER_Y, String(step.exit), 245);
} }
image.drawText(largeFont, PANEL_X + 76, 24, formatDistanceShort(progress.metersToNextManeuver), 250); image.drawText(largeFont, x + GLYPH_CAPTION_X, top + DISTANCE_Y, formatDistanceShort(progress.metersToNextManeuver), 250);
image.drawTextWrapped({ image.drawTextWrapped({
font: mediumFont, font: mediumFont,
x: PANEL_X + 8, x,
y: 84, y: top + INSTRUCTION_Y,
width: panelWidth - 16, width: textWidth,
text: step.instruction || step.name || step.maneuverType, text: step.instruction || step.name || step.maneuverType,
value: 220, value: 220,
}); });
const eta = `${formatDistance(progress.remainingMeters)} · ${formatDurationShort(progress.remainingSec)} · ${formatClock( const eta = `${formatDistance(progress.remainingMeters)} · ${formatDurationShort(progress.remainingSec)} · ${formatClock(
Date.now() + progress.remainingSec * 1000, Date.now() + progress.remainingSec * 1000,
)}`; )}`;
image.drawText(smallFont, PANEL_X + 8, win.viewportHeight - 62, eta, 170); image.drawText(smallFont, x, statusY - smallFont.lineHeight - PANEL_ETA_GAP, eta, 170);
} else { } else {
image.drawTextWrapped({ image.drawTextWrapped({
font: mediumFont, font: mediumFont,
x: PANEL_X + 8, x,
y: 24, y: top,
width: panelWidth - 16, width: textWidth,
text: `Waiting for GPS...`, text: `Waiting for GPS...`,
value: 200, value: 200,
}); });
} }
if (statusMessage) { if (statusMessage) {
image.drawText(smallFont, PANEL_X + 8, win.viewportHeight - 44, statusMessage, 200); image.drawText(smallFont, x, statusY, truncateText(smallFont, statusMessage, textWidth), 200);
} }
const modeHint = mapMode === "follow" ? "overview" : "follow"; const modeHint = mapMode === "follow" ? "overview" : "follow";
drawFooter(image, `${GESTURE_SCROLL} zoom ${GESTURE_CLICK} ${modeHint} ${GESTURE_DOUBLE_CLICK} back`, PANEL_X + 8); drawFooter(image, win.viewport, `${GESTURE_SCROLL} zoom ${GESTURE_CLICK} ${modeHint} ${GESTURE_DOUBLE_CLICK} back`, x);
} }
function paintMap(image: GrayImage): void { /** Clear space under the text of the map-mode status banner. */
const STATUS_BANNER_GAP = 4;
function paintMap(image: GrayImage, win: NavWindow): void {
const { padding } = win.viewport;
const { width, height } = mapDimensions(); const { width, height } = mapDimensions();
if (mapImage) { if (mapImage) {
image.bitBlt(mapImage, 0, 0); image.bitBlt(mapImage, 0, 0);
drawChevron(image, width / 2, height / 2, headHeadingDeg ?? 0); drawChevron(image, width / 2, height / 2, headHeadingDeg ?? 0);
} else { } else {
image.drawText(smallFont, 24, height / 2 - 8, mapLastError ? "Map unavailable; retrying..." : "Loading map...", 170); const text = mapLastError ? "Map unavailable; retrying..." : "Loading map...";
image.drawText(smallFont, pageText(win.viewport).x, height / 2 - 8, text, 170);
} }
if (statusMessage) { if (statusMessage) {
image.fillRect(0, 0, width, smallFont.lineHeight + 8, 0); // A banner across the map's top: the strip runs edge to edge, and its
image.drawText(smallFont, 16, 4, truncateText(smallFont, statusMessage, width - 32), 200); // text keeps the padding suggested for the edges it lies along.
image.fillRect(0, 0, width, padding.top + smallFont.lineHeight + STATUS_BANNER_GAP, 0);
image.drawText(smallFont, padding.left, padding.top,
truncateText(smallFont, statusMessage, width - padding.left - padding.right), 200);
} }
drawFooter(image, `${GESTURE_SCROLL} zoom ${GESTURE_CLICK} destinations ${GESTURE_DOUBLE_CLICK} back`); drawFooter(image, win.viewport, `${GESTURE_SCROLL} zoom ${GESTURE_CLICK} destinations ${GESTURE_DOUBLE_CLICK} back`);
} }
/** /**
@@ -1575,8 +1666,15 @@ function fillTriangle(image: GrayImage, x0: number, y0: number, x1: number, y1:
} }
} }
function drawFooter(image: GrayImage, text: string, x = 16): void { /** Top of the footer hint line, which rests on the padding suggested for the window's bottom edge. */
image.drawText(smallFont, x, image.height - 22, text, 115); function footerY(viewport: Viewport): number {
return viewport.height - viewport.padding.bottom - smallFont.lineHeight;
}
/** Draw the footer hint line from `x` (default: the left padding), cut short at the right padding. */
function drawFooter(image: GrayImage, viewport: Viewport, text: string, x = viewport.padding.left): void {
const maxWidth = viewport.width - viewport.padding.right - x;
image.drawText(smallFont, x, footerY(viewport), truncateText(smallFont, text, maxWidth), 115);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -8,11 +8,9 @@ import { type InputEvent } from "../../ui/gestures";
import { type Layer, type LayerContext } from "../../ui/layers"; import { type Layer, type LayerContext } from "../../ui/layers";
import { lineStep } from "../../ui/metrics"; import { lineStep } from "../../ui/metrics";
import { import {
NOTIFICATION_CONTENT_X,
createNotificationActionMenu, createNotificationActionMenu,
drawNotificationHeader, drawNotificationHeader,
notificationActionMenuBox, notificationDetailLayout,
notificationContentWidth,
} from "../../ui/notifications"; } from "../../ui/notifications";
import { type GlucoseRise } from "./missed-bolus-detector"; import { type GlucoseRise } from "./missed-bolus-detector";
import { import {
@@ -25,7 +23,6 @@ import {
const ICON_SIZE = 24; const ICON_SIZE = 24;
const GRAPH_GAP = 6; const GRAPH_GAP = 6;
const GRAPH_BOTTOM_MARGIN = 12;
const MIN_GRAPH_HEIGHT = 32; const MIN_GRAPH_HEIGHT = 32;
type ActionItem = { label: string; run: () => void }; type ActionItem = { label: string; run: () => void };
@@ -56,13 +53,15 @@ export class MissedBolusNotificationLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const step = lineStep(font); const step = lineStep(font);
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(viewport.width, viewport.height, 0);
const contentX = NOTIFICATION_CONTENT_X; // The same columns as a notification's detail view, inside the padding
const contentWidth = notificationContentWidth(width); // suggested for the edges of whatever hosts this (the shell's modal).
const layout = notificationDetailLayout(viewport);
const { contentX, contentWidth } = layout;
const nowMs = Date.now(); const nowMs = Date.now();
let y = drawNotificationHeader(image, font, renderIcon("nightscout", ICON_SIZE), `Nightscout ${formatRelativeTime(this.postedAtMs)}`); let y = drawNotificationHeader(image, font, renderIcon("nightscout", ICON_SIZE), `Nightscout ${formatRelativeTime(this.postedAtMs)}`, layout);
image.drawText(font, contentX, y, "Missed bolus?", 230); image.drawText(font, contentX, y, "Missed bolus?", 230);
y += step; y += step;
const minutes = Math.round((this.rise.latestMs - this.rise.onsetMs) / 60_000); const minutes = Math.round((this.rise.latestMs - this.rise.onsetMs) / 60_000);
@@ -90,12 +89,12 @@ export class MissedBolusNotificationLayer implements Layer {
y += step; y += step;
} }
const graphTop = y + GRAPH_GAP; const graphTop = y + GRAPH_GAP;
const graphHeight = height - GRAPH_BOTTOM_MARGIN - graphTop; const graphHeight = layout.bottom - graphTop;
if (graphHeight >= MIN_GRAPH_HEIGHT) { if (graphHeight >= MIN_GRAPH_HEIGHT) {
drawNightscoutGraph(image, { x: contentX, y: graphTop, width: contentWidth, height: graphHeight }, nightscout, nowMs, font); drawNightscoutGraph(image, { x: contentX, y: graphTop, width: contentWidth, height: graphHeight }, nightscout, nowMs, font);
} }
this.menu.paint(image, notificationActionMenuBox(width, height), ctx.stack.isFocused()); this.menu.paint(image, layout.menuBox, ctx.stack.isFocused());
return image; return image;
} }
+42 -17
View File
@@ -30,6 +30,19 @@ export const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000; const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000; const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000;
/**
* The app page's fixed parts, placed from the title at the window's top and
* left padding: a status message and the graph, down from the title's top,
* and the status lines' column, right of the readout's left edge.
*/
const PAGE_MESSAGE_OFFSET_Y = 28;
const PAGE_GRAPH_OFFSET_Y = 112;
const PAGE_STATUS_OFFSET_X = 148;
/** Gap between the page's graph and the caption under it. */
const PAGE_CAPTION_GAP = 6;
/** The shortest graph the page draws above its caption; with less room the graph takes the caption's. */
const PAGE_MIN_GRAPH_HEIGHT = 40;
/** Draws the trend indicator; returns its width. */ /** Draws the trend indicator; returns its width. */
export function drawDirectionIndicator( export function drawDirectionIndicator(
image: GrayImage, image: GrayImage,
@@ -298,36 +311,44 @@ function drawNightscoutReferenceLine(
export class NightscoutLayer implements Layer { export class NightscoutLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
// Sized to the hosting stack (the Nightscout app viewport). // Sized to the hosting stack (the Nightscout app viewport). Nothing here
const { width, height } = ctx.stack.getBaseSize(); // scrolls, so the page keeps inside the padding suggested for each of
// the viewport's edges: the title, the readout and the graph start at
// the left padding, and the graph and its caption end at the bottom's.
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const nightscout = nightscoutBridge.snapshot(); const nightscout = nightscoutBridge.snapshot();
const nowMs = Date.now(); const nowMs = Date.now();
const step = lineStep(font); const step = lineStep(font);
image.drawText(font, 22, 16, "Nightscout", 220); const left = padding.left;
const top = padding.top;
const right = width - padding.right;
const bottom = height - padding.bottom;
image.drawText(font, left, top, "Nightscout", 220);
const messageY = top + PAGE_MESSAGE_OFFSET_Y;
if (!isNightscoutSettingsConfigured() || nightscout.configurationMissing) { if (!isNightscoutSettingsConfigured() || nightscout.configurationMissing) {
image.drawText(font, 22, 44, "Nightscout needs configuration.", 180); image.drawText(font, left, messageY, "Nightscout needs configuration.", 180);
image.drawText(font, 22, 44 + step, "Long-press for the menu, then pick Settings to set", 140); image.drawText(font, left, messageY + step, "Long-press for the menu, then pick Settings to set", 140);
image.drawText(font, 22, 44 + 2 * step, "the site URL and API token.", 140); image.drawText(font, left, messageY + 2 * step, "the site URL and API token.", 140);
return image; return image;
} }
if (!nightscout.available || !nightscout.latest) { if (!nightscout.available || !nightscout.latest) {
image.drawText(font, 22, 44, "No Nightscout data available.", 180); image.drawText(font, left, messageY, "No Nightscout data available.", 180);
image.drawText(font, 22, 44 + step, truncateLine(nightscout.status, 60), 140); image.drawText(font, left, messageY + step, truncateLine(nightscout.status, 60), 140);
return image; return image;
} }
// Two-column header above the graph: title + current glucose on the // Two-column header above the graph: title + current glucose on the
// left, the status lines bottom-aligned on the right. // left, the status lines bottom-aligned on the right.
const graphTop = 128; const graphTop = top + PAGE_GRAPH_OFFSET_Y;
const latest = nightscout.latest; const latest = nightscout.latest;
const glucoseText = `${latest.sgv}`; const glucoseText = `${latest.sgv}`;
const glucoseX = 22; const glucoseX = left;
const glucoseWidth = nightscoutLargeFont.measureText(glucoseText); const glucoseWidth = nightscoutLargeFont.measureText(glucoseText);
// Glucose value vertically centered between the title and the graph. // Glucose value vertically centered between the title and the graph.
const titleBottom = 16 + font.lineHeight; const titleBottom = top + font.lineHeight;
const glucoseY = Math.round((titleBottom + graphTop - nightscoutLargeFont.lineHeight) / 2); const glucoseY = Math.round((titleBottom + graphTop - nightscoutLargeFont.lineHeight) / 2);
image.drawText(nightscoutLargeFont, glucoseX, glucoseY, glucoseText, 230); image.drawText(nightscoutLargeFont, glucoseX, glucoseY, glucoseText, 230);
if (isNightscoutPointStale(latest, nowMs)) { if (isNightscoutPointStale(latest, nowMs)) {
@@ -335,8 +356,8 @@ export class NightscoutLayer implements Layer {
} }
image.drawText(font, glucoseX + glucoseWidth + 8, glucoseY + nightscoutLargeFont.lineHeight - font.lineHeight, nightscout.units, 140); image.drawText(font, glucoseX + glucoseWidth + 8, glucoseY + nightscoutLargeFont.lineHeight - font.lineHeight, nightscout.units, 140);
const statusX = 170; const statusX = left + PAGE_STATUS_OFFSET_X;
const statusWidth = width - 22 - statusX; const statusWidth = right - statusX;
const alerts = evaluateNightscoutAlerts(nightscout, loadNightscoutThresholds(), nowMs); const alerts = evaluateNightscoutAlerts(nightscout, loadNightscoutThresholds(), nowMs);
const statusLines: { text: string; shade: number; direction?: string; fields?: { text: string; warning?: boolean }[] }[] = [ const statusLines: { text: string; shade: number; direction?: string; fields?: { text: string; warning?: boolean }[] }[] = [
{ text: `Delta ${formatDelta(nightscout.delta)} Trend `, shade: 180, direction: nightscout.direction }, { text: `Delta ${formatDelta(nightscout.delta)} Trend `, shade: 180, direction: nightscout.direction },
@@ -382,10 +403,14 @@ export class NightscoutLayer implements Layer {
statusY += step; statusY += step;
} }
const captionY = height - font.lineHeight - 6; // The graph spans the padded width, down to the caption on the last
const graphHeight = Math.max(40, captionY - 6 - graphTop); // line above the bottom padding. A window too short for both gives the
drawNightscoutGraph(image, { x: 22, y: graphTop, width: width - 44, height: graphHeight }, nightscout, nowMs, font); // caption's room to the graph.
image.drawText(font, 22, captionY, "2-hour glucose history with basal / carbs / boluses", 130); const captionY = bottom - font.lineHeight;
const captioned = captionY - PAGE_CAPTION_GAP - graphTop >= PAGE_MIN_GRAPH_HEIGHT;
const graphBottom = captioned ? captionY - PAGE_CAPTION_GAP : bottom;
drawNightscoutGraph(image, { x: left, y: graphTop, width: right - left, height: graphBottom - graphTop }, nightscout, nowMs, font);
if (captioned) image.drawText(font, left, captionY, "2-hour glucose history with basal / carbs / boluses", 130);
return image; return image;
} }
+10 -1
View File
@@ -1,6 +1,6 @@
import { NotificationsListLayer } from "../../ui/notifications"; import { NotificationsListLayer } from "../../ui/notifications";
import { NOTIFICATIONS_SETTINGS_SECTION } from "../../ui/dashboard/settings-menus"; import { NOTIFICATIONS_SETTINGS_SECTION } from "../../ui/dashboard/settings-menus";
import { onAndroidNotificationsChanged } from "../../native/notification-icons"; import { ALL_NOTIFICATIONS, dismissAllNotifications, onAndroidNotificationsChanged, readActiveNotifications } from "../../native/notification-icons";
import { import {
createInProcessWindow, createInProcessWindow,
YieldAtRootLayer, YieldAtRootLayer,
@@ -36,6 +36,15 @@ export function createNotificationsAppWindow(
ctx.stack.pop(); ctx.stack.pop();
openSettings(NOTIFICATIONS_SETTINGS_SECTION); openSettings(NOTIFICATIONS_SETTINGS_SECTION);
}, },
}, {
label: "Dismiss all notifications",
description: "Dismiss notifications on the phone and glasses. System-protected notifications may remain.",
disabled: () => readActiveNotifications(ALL_NOTIFICATIONS).length === 0,
onSelect: (ctx) => {
ctx.stack.pop();
dismissAllNotifications();
created.requestRender();
},
}], }],
actions: options.actions, actions: options.actions,
baseLayer: new YieldAtRootLayer(new NotificationsListLayer()), baseLayer: new YieldAtRootLayer(new NotificationsListLayer()),
+16 -10
View File
@@ -4,11 +4,11 @@ import { dataCollectionSetting, dataCollectionSummary, type DataCollectionLevel
import type { InputEvent } from "../../ui/gestures"; import type { InputEvent } from "../../ui/gestures";
import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics"; import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
import type { Edges } from "../../ui/viewport";
import { onboardingFont } from "./onboarding-fonts"; import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page"; import { drawPageHeading, PAGE_TEXT_INSET, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const CONTENT_GAP = 10; const CONTENT_GAP = 10;
const BOTTOM_MARGIN = 8;
const LABEL_GAP = 24; const LABEL_GAP = 24;
/** None / Minimal / Full, each with a one-line summary; a tap saves the selected level. */ /** None / Minimal / Full, each with a one-line summary; a tap saves the selected level. */
@@ -29,21 +29,27 @@ export class DataCollectionPage implements OnboardingPage {
this.menu.select(dataCollectionSetting.values.indexOf(dataCollectionSetting.get())); this.menu.select(dataCollectionSetting.values.indexOf(dataCollectionSetting.get()));
} }
paint(image: GrayImage, focused: boolean): void { paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
const top = drawPageHeading( const top = drawPageHeading(
image, image,
"Data Sharing", padding,
(global.isIOS ? "If using TestFlight, crash/usage reports cannot be disabled here. " : "") + "Faceclaw Statistics",
"Choose how much data you want to share. Change later in Settings > Privacy.", (global.isIOS ? "TestFlight reports are separate. " : "Google ML Kit diagnostics are separate. ") +
"Choose Faceclaw statistics below. Details and controls: Settings > Privacy.",
3, 3,
) + CONTENT_GAP; ) + CONTENT_GAP;
const body = onboardingFont("body"); const body = onboardingFont("body");
this.labelColumnWidth = this.labelColumnWidth =
Math.max(...dataCollectionSetting.values.map((level) => body.measureText(dataCollectionSetting.displayValue(level)))) + Math.max(...dataCollectionSetting.values.map((level) => body.measureText(dataCollectionSetting.displayValue(level)))) +
LABEL_GAP; LABEL_GAP;
// The list scrolls, so it runs to the window's bottom edge, with that
// edge's padding after its last row.
this.menu.paint( this.menu.paint(
image, image,
{ x: PAGE_X - 10, y: top, width: image.width - 2 * (PAGE_X - 10), height: image.height - top - BOTTOM_MARGIN }, {
x: padding.left, y: top, width: Math.max(0, image.width - padding.left - padding.right), height: Math.max(0, image.height - top),
padBottom: padding.bottom,
},
focused, focused,
); );
} }
@@ -68,9 +74,9 @@ export class DataCollectionPage implements OnboardingPage {
private drawRow({ image, item: level, x, y, width, height, selected }: MenuDrawArgs<DataCollectionLevel>): void { private drawRow({ image, item: level, x, y, width, height, selected }: MenuDrawArgs<DataCollectionLevel>): void {
const body = onboardingFont("body"); const body = onboardingFont("body");
const detail = onboardingFont("detail"); const detail = onboardingFont("detail");
image.drawText(body, x + 10, y + LIST_ROW_TEXT_INSET, dataCollectionSetting.displayValue(level), selected ? 255 : 200); image.drawText(body, x + PAGE_TEXT_INSET, y + LIST_ROW_TEXT_INSET, dataCollectionSetting.displayValue(level), selected ? 255 : 200);
const summaryX = x + 10 + this.labelColumnWidth; const summaryX = x + PAGE_TEXT_INSET + this.labelColumnWidth;
const summary = truncateText(detail, dataCollectionSummary(level), x + width - 10 - summaryX); const summary = truncateText(detail, dataCollectionSummary(level), x + width - PAGE_TEXT_INSET - summaryX);
image.drawText(detail, summaryX, y + Math.round((height - detail.lineHeight) / 2), summary, selected ? 210 : 150); image.drawText(detail, summaryX, y + Math.round((height - detail.lineHeight) / 2), summary, selected ? 210 : 150);
} }
} }
+11 -5
View File
@@ -3,12 +3,12 @@ import { appSwitcherPositionSetting, uiDepthSetting, type UiDepth } from "../../
import type { InputEvent } from "../../ui/gestures"; import type { InputEvent } from "../../ui/gestures";
import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics"; import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
import type { Edges } from "../../ui/viewport";
import { layoutHasDepth } from "./layout-page"; import { layoutHasDepth } from "./layout-page";
import { onboardingFont } from "./onboarding-fonts"; import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page"; import { drawPageHeading, PAGE_TEXT_INSET, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const CONTENT_GAP = 10; const CONTENT_GAP = 10;
const BOTTOM_MARGIN = 8;
const COLUMN_WIDTH = 220; const COLUMN_WIDTH = 220;
/** /**
@@ -35,15 +35,21 @@ export class DepthPage implements OnboardingPage {
this.menu.select(uiDepthSetting.values.indexOf(uiDepthSetting.get())); this.menu.select(uiDepthSetting.values.indexOf(uiDepthSetting.get()));
} }
paint(image: GrayImage, focused: boolean): void { paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
const top = drawPageHeading( const top = drawPageHeading(
image, image,
padding,
"Depth", "Depth",
"Swipe to move the display nearer or farther away, then tap to continue. Change later in Settings > Customization.", "Swipe to move the display nearer or farther away, then tap to continue. Change later in Settings > Customization.",
) + CONTENT_GAP; ) + CONTENT_GAP;
// The list scrolls, so it runs to the window's bottom edge, with that
// edge's padding after its last row.
this.menu.paint( this.menu.paint(
image, image,
{ x: PAGE_X - 10, y: top, width: COLUMN_WIDTH, height: image.height - top - BOTTOM_MARGIN }, {
x: padding.left, y: top, width: Math.min(COLUMN_WIDTH, Math.max(0, image.width - padding.left - padding.right)),
height: Math.max(0, image.height - top), padBottom: padding.bottom,
},
focused, focused,
); );
} }
@@ -66,6 +72,6 @@ export class DepthPage implements OnboardingPage {
} }
private drawRow({ image, item: depth, x, y, selected }: MenuDrawArgs<UiDepth>): void { private drawRow({ image, item: depth, x, y, selected }: MenuDrawArgs<UiDepth>): void {
image.drawText(onboardingFont("body"), x + 10, y + LIST_ROW_TEXT_INSET, uiDepthSetting.displayValue(depth), selected ? 255 : 190); image.drawText(onboardingFont("body"), x + PAGE_TEXT_INSET, y + LIST_ROW_TEXT_INSET, uiDepthSetting.displayValue(depth), selected ? 255 : 190);
} }
} }
+13 -8
View File
@@ -4,11 +4,11 @@ import { displayLayoutSetting, type DisplayLayout } from "../../ui/dashboard-set
import type { InputEvent } from "../../ui/gestures"; import type { InputEvent } from "../../ui/gestures";
import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics"; import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
import type { Edges } from "../../ui/viewport";
import { onboardingFont } from "./onboarding-fonts"; import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page"; import { drawPageHeading, PAGE_TEXT_INSET, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const CONTENT_GAP = 10; const CONTENT_GAP = 10;
const BOTTOM_MARGIN = 8;
const COLUMN_GAP = 16; const COLUMN_GAP = 16;
const DESCRIPTIONS = { const DESCRIPTIONS = {
@@ -41,24 +41,29 @@ export class DisplayModePage implements OnboardingPage {
this.menu.setItems(values, index >= 0 ? index : values.indexOf("tall")); this.menu.setItems(values, index >= 0 ? index : values.indexOf("tall"));
} }
paint(image: GrayImage, focused: boolean): void { paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
const top = drawPageHeading( const top = drawPageHeading(
image, image,
padding,
"Display mode", "Display mode",
"Swipe to choose how much of the display windows use; it changes as you go. Tap to continue.", "Swipe to choose how much of the display windows use; it changes as you go. Tap to continue.",
) + CONTENT_GAP; ) + CONTENT_GAP;
const body = onboardingFont("body"); const body = onboardingFont("body");
// TTF widths are fractional; the menu's row images need whole pixels. // TTF widths are fractional; the menu's row images need whole pixels.
const columnWidth = Math.ceil(20 + Math.max(...this.menu.items.map((value) => body.measureText(displayLayoutSetting.displayValue(value))))); const columnWidth = Math.ceil(2 * PAGE_TEXT_INSET +
const menuBox = { x: PAGE_X - 10, y: top, width: columnWidth, height: image.height - top - BOTTOM_MARGIN }; Math.max(...this.menu.items.map((value) => body.measureText(displayLayoutSetting.displayValue(value)))));
// The list scrolls, so it runs to the window's bottom edge, with that
// edge's padding after its last row.
const menuBox = { x: padding.left, y: top, width: columnWidth, height: Math.max(0, image.height - top), padBottom: padding.bottom };
this.menu.paint(image, menuBox, focused); this.menu.paint(image, menuBox, focused);
const layout = this.menu.selectedItem; const layout = this.menu.selectedItem;
if (layout === null) return; if (layout === null) return;
// The description stays put beside the list, inside the right and bottom padding.
const detail = onboardingFont("detail"); const detail = onboardingFont("detail");
const left = menuBox.x + columnWidth + COLUMN_GAP; const left = menuBox.x + columnWidth + COLUMN_GAP;
let y = top + LIST_ROW_TEXT_INSET; let y = top + LIST_ROW_TEXT_INSET;
for (const line of wrapText(detail, description(layout), image.width - PAGE_X - left)) { for (const line of wrapText(detail, description(layout), image.width - padding.right - PAGE_TEXT_INSET - left)) {
if (y + detail.lineHeight > image.height - BOTTOM_MARGIN) break; if (y + detail.lineHeight > image.height - padding.bottom) break;
image.drawText(detail, left, y, line, 170); image.drawText(detail, left, y, line, 170);
y += detail.lineHeight; y += detail.lineHeight;
} }
@@ -86,7 +91,7 @@ export class DisplayModePage implements OnboardingPage {
} }
private drawRow({ image, item: layout, x, y, selected }: MenuDrawArgs<DisplayLayout>): void { private drawRow({ image, item: layout, x, y, selected }: MenuDrawArgs<DisplayLayout>): void {
image.drawText(onboardingFont("body"), x + 10, y + LIST_ROW_TEXT_INSET, displayLayoutSetting.displayValue(layout), selected ? 255 : 190); image.drawText(onboardingFont("body"), x + PAGE_TEXT_INSET, y + LIST_ROW_TEXT_INSET, displayLayoutSetting.displayValue(layout), selected ? 255 : 190);
} }
} }
+16 -12
View File
@@ -3,12 +3,12 @@ import { appSwitcherPositionSetting, glassesTypeSetting, type AppSwitcherPositio
import type { InputEvent } from "../../ui/gestures"; import type { InputEvent } from "../../ui/gestures";
import { MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "../../ui/menu-core"; import { MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "../../ui/menu-core";
import { screenWidth } from "../../ui/shell/geometry"; import { screenWidth } from "../../ui/shell/geometry";
import type { Edges } from "../../ui/viewport";
import { AREA_OUTLINE, Diagram, diagramBandHeight, drawLayout, layoutAreaHeight } from "./layout-diagram"; import { AREA_OUTLINE, Diagram, diagramBandHeight, drawLayout, layoutAreaHeight } from "./layout-diagram";
import { onboardingFont } from "./onboarding-fonts"; import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page"; import { centredX, drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const CONTENT_GAP = 10; const CONTENT_GAP = 10;
const BOTTOM_MARGIN = 8;
/** Diagram width as a fraction of the display's: the most a diagram is drawn at. */ /** Diagram width as a fraction of the display's: the most a diagram is drawn at. */
const DIAGRAM_SCALE = 0.4; const DIAGRAM_SCALE = 0.4;
/** Padding inside a cell's selection box, round the diagram and its caption. */ /** Padding inside a cell's selection box, round the diagram and its caption. */
@@ -37,35 +37,39 @@ export function layoutHasDepth(position: AppSwitcherPosition): boolean {
* layout, Bottom and Popup on top, the recommended one selected at first; * layout, Bottom and Popup on top, the recommended one selected at first;
* swipes move through them in reading order, a tap saves the selected one. * swipes move through them in reading order, a tap saves the selected one.
* The page is immersive, so the diagrams get 40% of the display's width * The page is immersive, so the diagrams get 40% of the display's width
* each. Choosing a layout reflows open windows (the dashboard controller * each. The grid is centred in the window, its cells' selection boxes
* watches the setting). * keeping inside the padding of the window's edges. Choosing a layout
* reflows open windows (the dashboard controller watches the setting).
*/ */
export class LayoutPage implements OnboardingPage { export class LayoutPage implements OnboardingPage {
readonly immersive = true; readonly immersive = true;
/** Kept across visits, so going back returns to the last choice. */ /** Kept across visits, so going back returns to the last choice. */
private selected = LAYOUT_ORDER.indexOf(recommendedLayout()); private selected = LAYOUT_ORDER.indexOf(recommendedLayout());
paint(image: GrayImage, focused: boolean): void { paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
const top = drawPageHeading( const top = drawPageHeading(
image, image,
padding,
"Layout", "Layout",
"Swipe to choose where the app switcher goes, then tap to continue.", "Swipe to choose where the app switcher goes, then tap to continue.",
) + CONTENT_GAP; ) + CONTENT_GAP;
const title = onboardingFont("body"); const title = onboardingFont("body");
const subtitle = onboardingFont("detail"); const subtitle = onboardingFont("detail");
const captionHeight = CAPTION_GAP + title.lineHeight + subtitle.lineHeight; const captionHeight = CAPTION_GAP + title.lineHeight + subtitle.lineHeight;
const available = image.height - top - BOTTOM_MARGIN; const available = image.height - top - padding.bottom;
const availableWidth = image.width - padding.left - padding.right;
// The most a diagram can take for two rows and two columns of cells to
// fit, in whole pixels, so rounding its size can't push the grid past
// the window's padding.
const maxDiagramHeight = Math.floor((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight);
const maxDiagramWidth = Math.floor((availableWidth - COLUMN_GAP) / 2 - 2 * CELL_PADDING);
// Short of DIAGRAM_SCALE only where two rows of cells wouldn't fit. // Short of DIAGRAM_SCALE only where two rows of cells wouldn't fit.
const scale = Math.min( const scale = Math.max(0, Math.min(DIAGRAM_SCALE, maxDiagramHeight / layoutAreaHeight(), maxDiagramWidth / screenWidth()));
DIAGRAM_SCALE,
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / layoutAreaHeight(),
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / screenWidth(),
);
const diagramWidth = Math.round(screenWidth() * scale); const diagramWidth = Math.round(screenWidth() * scale);
const diagramHeight = Math.round(layoutAreaHeight() * scale); const diagramHeight = Math.round(layoutAreaHeight() * scale);
const cellWidth = diagramWidth + 2 * CELL_PADDING; const cellWidth = diagramWidth + 2 * CELL_PADDING;
const cellHeight = diagramHeight + 2 * CELL_PADDING + captionHeight; const cellHeight = diagramHeight + 2 * CELL_PADDING + captionHeight;
const left = Math.round((image.width - 2 * cellWidth - COLUMN_GAP) / 2); const left = centredX(image, padding, 2 * cellWidth + COLUMN_GAP);
const gridTop = top + Math.max(0, Math.round((available - 2 * cellHeight - ROW_GAP) / 2)); const gridTop = top + Math.max(0, Math.round((available - 2 * cellHeight - ROW_GAP) / 2));
LAYOUT_ORDER.forEach((position, index) => { LAYOUT_ORDER.forEach((position, index) => {
const x = left + (index % 2) * (cellWidth + COLUMN_GAP); const x = left + (index % 2) * (cellWidth + COLUMN_GAP);
+2 -2
View File
@@ -84,9 +84,9 @@ export class OnboardingLayer implements Layer {
} }
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
this.pages[this.index]!.paint(image, ctx.stack.isFocused()); this.pages[this.index]!.paint(image, ctx.stack.isFocused(), padding);
return image; return image;
} }
+31 -8
View File
@@ -1,6 +1,7 @@
import type { GrayImage } from "../../graphics/image"; import type { GrayImage } from "../../graphics/image";
import { wrapText } from "../../graphics/textwrap"; import { wrapText } from "../../graphics/textwrap";
import type { InputEvent } from "../../ui/gestures"; import type { InputEvent } from "../../ui/gestures";
import type { Edges } from "../../ui/viewport";
import { onboardingFont } from "./onboarding-fonts"; import { onboardingFont } from "./onboarding-fonts";
/** Page-to-flow navigation, handed to a page's input handler. */ /** Page-to-flow navigation, handed to a page's input handler. */
@@ -25,13 +26,31 @@ export interface OnboardingPage {
applies?(): boolean; applies?(): boolean;
/** The page became current, going forward or back. */ /** The page became current, going forward or back. */
enter?(): void; enter?(): void;
paint(image: GrayImage, focused: boolean): void; /**
* Paint the page over the whole image, the window's viewport. `padding`
* is the padding suggested for each of its edges (viewport.ts): none on an
* immersive page, whose edges are the screen's.
*/
paint(image: GrayImage, focused: boolean, padding: Edges<number>): void;
handleInput(event: InputEvent, nav: OnboardingNav): void | Promise<void>; handleInput(event: InputEvent, nav: OnboardingNav): void | Promise<void>;
} }
/** Left margin and title position shared by the pages (the UI-wide (18, 10) title spot). */ /**
export const PAGE_X = 18; * How far a page's text (its title and explanation, a list row's label)
export const TITLE_Y = 10; * sits inside the side padding. A list's selection boxes start at the
* padding itself, so the title lines up with the rows' text.
*/
export const PAGE_TEXT_INSET = 10;
/** The title's drop below the top padding. */
const TITLE_OFFSET_Y = 2;
/**
* The x that centres something `width` wide in the window, short of
* entering either side's padding.
*/
export function centredX(image: GrayImage, padding: Edges<number>, width: number): number {
return Math.max(padding.left, Math.min(image.width - padding.right - width, Math.round((image.width - width) / 2)));
}
/** /**
* Draw a page's title and its wrapped explanation (at most `maxLines` * Draw a page's title and its wrapped explanation (at most `maxLines`
@@ -39,17 +58,21 @@ export const TITLE_Y = 10;
*/ */
export function drawPageHeading( export function drawPageHeading(
image: GrayImage, image: GrayImage,
padding: Edges<number>,
title: string, title: string,
explanation: string, explanation: string,
maxLines = 2, maxLines = 2,
): number { ): number {
const titleFont = onboardingFont("title"); const titleFont = onboardingFont("title");
const detailFont = onboardingFont("detail"); const detailFont = onboardingFont("detail");
image.drawText(titleFont, PAGE_X, TITLE_Y, title, 230); const x = padding.left + PAGE_TEXT_INSET;
let y = TITLE_Y + titleFont.lineHeight + 2; const textWidth = Math.max(0, image.width - padding.left - padding.right - 2 * PAGE_TEXT_INSET);
const lines = wrapText(detailFont, explanation, image.width - 2 * PAGE_X).slice(0, maxLines); const titleY = padding.top + TITLE_OFFSET_Y;
image.drawText(titleFont, x, titleY, title, 230);
let y = titleY + titleFont.lineHeight + 2;
const lines = wrapText(detailFont, explanation, textWidth).slice(0, maxLines);
for (const line of lines) { for (const line of lines) {
image.drawText(detailFont, PAGE_X, y, line, 160); image.drawText(detailFont, x, y, line, 160);
y += detailFont.lineHeight; y += detailFont.lineHeight;
} }
return y; return y;
+16 -15
View File
@@ -14,11 +14,11 @@ import { FONT_SIZE_CHOICES } from "../../ui/font-picker";
import type { InputEvent } from "../../ui/gestures"; import type { InputEvent } from "../../ui/gestures";
import { Menu, type MenuBox, type MenuDrawArgs } from "../../ui/menu-core"; import { Menu, type MenuBox, type MenuDrawArgs } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics"; import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
import type { Edges } from "../../ui/viewport";
import { onboardingFont } from "./onboarding-fonts"; import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page"; import { drawPageHeading, PAGE_TEXT_INSET, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const CONTENT_GAP = 10; const CONTENT_GAP = 10;
const BOTTOM_MARGIN = 8;
const COLUMN_GAP = 12; const COLUMN_GAP = 12;
const PREVIEW_PADDING = 10; const PREVIEW_PADDING = 10;
const ROW_GAP = 2; const ROW_GAP = 2;
@@ -75,39 +75,40 @@ export class TextSizePage implements OnboardingPage {
this.face = { kind: "fixed", label: selection.kind === "bitmap" ? fontSelectionLabel(selection) : "Terminus" }; this.face = { kind: "fixed", label: selection.kind === "bitmap" ? fontSelectionLabel(selection) : "Terminus" };
} }
paint(image: GrayImage, focused: boolean): void { paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
// The preview's frame keeps inside the padding of the window's edges.
const right = image.width - padding.right;
const bottom = image.height - padding.bottom;
if (this.face.kind === "fixed") { if (this.face.kind === "fixed") {
const top = drawPageHeading( const top = drawPageHeading(
image, image,
padding,
"Text size", "Text size",
`Your UI font, ${this.face.label}, comes in one size. To choose a size, pick a different font in ` + `Your UI font, ${this.face.label}, comes in one size. To choose a size, pick a different font in ` +
"Settings > Customization. Tap to continue.", "Settings > Customization. Tap to continue.",
3, 3,
) + CONTENT_GAP; ) + CONTENT_GAP;
drawPreview(image, getDefaultSmallFont(), { drawPreview(image, getDefaultSmallFont(), { x: padding.left, y: top, width: right - padding.left, height: bottom - top });
x: PAGE_X - 10,
y: top,
width: image.width - 2 * (PAGE_X - 10),
height: image.height - top - BOTTOM_MARGIN,
});
return; return;
} }
const top = drawPageHeading( const top = drawPageHeading(
image, image,
padding,
"Text size", "Text size",
"Swipe to choose a size, then tap to continue. The typeface and weight can be changed in Settings.", "Swipe to choose a size, then tap to continue. The typeface and weight can be changed in Settings.",
) + CONTENT_GAP; ) + CONTENT_GAP;
const height = image.height - top - BOTTOM_MARGIN;
const body = onboardingFont("body"); const body = onboardingFont("body");
// TTF widths are fractional; the menu's row images need whole pixels. // TTF widths are fractional; the menu's row images need whole pixels.
const columnWidth = Math.ceil(20 + Math.max(...this.face.sizes.map((size) => body.measureText(sizeLabel(size)))) + const columnWidth = Math.ceil(2 * PAGE_TEXT_INSET + Math.max(...this.face.sizes.map((size) => body.measureText(sizeLabel(size)))) +
NOTE_GAP + onboardingFont("detail").measureText(RECOMMENDED_NOTE)); NOTE_GAP + onboardingFont("detail").measureText(RECOMMENDED_NOTE));
const menuBox = { x: PAGE_X - 10, y: top, width: columnWidth, height }; // The list scrolls, so it runs to the window's bottom edge, with that
// edge's padding after its last row.
const menuBox = { x: padding.left, y: top, width: columnWidth, height: Math.max(0, image.height - top), padBottom: padding.bottom };
this.sizeMenu.paint(image, menuBox, focused); this.sizeMenu.paint(image, menuBox, focused);
const previewX = menuBox.x + menuBox.width + COLUMN_GAP; const previewX = menuBox.x + menuBox.width + COLUMN_GAP;
const size = this.sizeMenu.selectedItem; const size = this.sizeMenu.selectedItem;
const font = (size !== null ? TtfFont.load(this.face.path, size) : null) ?? getDefaultSmallFont(); const font = (size !== null ? TtfFont.load(this.face.path, size) : null) ?? getDefaultSmallFont();
drawPreview(image, font, { x: previewX, y: top, width: image.width - (PAGE_X - 10) - previewX, height }); drawPreview(image, font, { x: previewX, y: top, width: right - previewX, height: bottom - top });
} }
handleInput(event: InputEvent, nav: OnboardingNav): void { handleInput(event: InputEvent, nav: OnboardingNav): void {
@@ -136,11 +137,11 @@ export class TextSizePage implements OnboardingPage {
private drawSizeRow({ image, item: size, x, y, height, selected }: MenuDrawArgs<number>): void { private drawSizeRow({ image, item: size, x, y, height, selected }: MenuDrawArgs<number>): void {
const body = onboardingFont("body"); const body = onboardingFont("body");
const label = sizeLabel(size); const label = sizeLabel(size);
image.drawText(body, x + 10, y + LIST_ROW_TEXT_INSET, label, selected ? 255 : 190); image.drawText(body, x + PAGE_TEXT_INSET, y + LIST_ROW_TEXT_INSET, label, selected ? 255 : 190);
if (size !== defaultUiFontSize()) return; if (size !== defaultUiFontSize()) return;
const detail = onboardingFont("detail"); const detail = onboardingFont("detail");
const noteY = y + Math.round((height - detail.lineHeight) / 2); const noteY = y + Math.round((height - detail.lineHeight) / 2);
image.drawText(detail, x + 10 + body.measureText(label) + NOTE_GAP, noteY, RECOMMENDED_NOTE, selected ? 210 : 150); image.drawText(detail, x + PAGE_TEXT_INSET + body.measureText(label) + NOTE_GAP, noteY, RECOMMENDED_NOTE, selected ? 210 : 150);
} }
} }
+11 -7
View File
@@ -2,31 +2,35 @@ import type { GrayImage, UiFont } from "../../graphics/image";
import { getFullLogo } from "../../graphics/logo"; import { getFullLogo } from "../../graphics/logo";
import { wrapText } from "../../graphics/textwrap"; import { wrapText } from "../../graphics/textwrap";
import type { InputEvent } from "../../ui/gestures"; import type { InputEvent } from "../../ui/gestures";
import type { Edges } from "../../ui/viewport";
import { FACECLAW_VERSION } from "../../version"; import { FACECLAW_VERSION } from "../../version";
import { onboardingFont } from "./onboarding-fonts"; import { onboardingFont } from "./onboarding-fonts";
import { PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page"; import { centredX, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const LOGO_MAX_HEIGHT = 180; const LOGO_MAX_HEIGHT = 180;
const LOGO_MARGIN = 12;
const LOGO_TEXT_GAP = 28; const LOGO_TEXT_GAP = 28;
const PROMPT_GAP = 22; const PROMPT_GAP = 22;
const PROMPT = "Tap the ring or touchpad to continue"; const PROMPT = "Tap the ring or touchpad to continue";
type TextLine = { font: UiFont; text: string; value: number; spaceBefore: number }; type TextLine = { font: UiFont; text: string; value: number; spaceBefore: number };
/** The splash: logo beside the name, version and how to go on, centred as one group. */ /**
* The splash: logo beside the name, version and how to go on, centred in
* the window as one group, which keeps inside the padding of its edges.
*/
export class WelcomePage implements OnboardingPage { export class WelcomePage implements OnboardingPage {
readonly immersive = true; readonly immersive = true;
paint(image: GrayImage): void { paint(image: GrayImage, _focused: boolean, padding: Edges<number>): void {
const { width, height } = image; const { width, height } = image;
const logo = getFullLogo(Math.min(LOGO_MAX_HEIGHT, height - 2 * LOGO_MARGIN)); const availableWidth = Math.max(0, width - padding.left - padding.right);
const logo = getFullLogo(Math.min(LOGO_MAX_HEIGHT, height - padding.top - padding.bottom));
const logoWidth = logo ? logo.width + LOGO_TEXT_GAP : 0; const logoWidth = logo ? logo.width + LOGO_TEXT_GAP : 0;
const body = onboardingFont("body"); const body = onboardingFont("body");
const lines: TextLine[] = [ const lines: TextLine[] = [
{ font: onboardingFont("hero"), text: "Faceclaw", value: 240, spaceBefore: 0 }, { font: onboardingFont("hero"), text: "Faceclaw", value: 240, spaceBefore: 0 },
{ font: body, text: `Version ${FACECLAW_VERSION}`, value: 150, spaceBefore: 0 }, { font: body, text: `Version ${FACECLAW_VERSION}`, value: 150, spaceBefore: 0 },
...wrapText(body, PROMPT, width - 2 * PAGE_X - logoWidth).map((text, index) => ({ ...wrapText(body, PROMPT, availableWidth - logoWidth).map((text, index) => ({
font: body, font: body,
text, text,
value: 215, value: 215,
@@ -35,7 +39,7 @@ export class WelcomePage implements OnboardingPage {
]; ];
const textWidth = Math.max(...lines.map((line) => line.font.measureText(line.text))); const textWidth = Math.max(...lines.map((line) => line.font.measureText(line.text)));
const textHeight = lines.reduce((total, line) => total + line.spaceBefore + line.font.lineHeight, 0); const textHeight = lines.reduce((total, line) => total + line.spaceBefore + line.font.lineHeight, 0);
const left = Math.max(PAGE_X, Math.round((width - logoWidth - textWidth) / 2)); const left = centredX(image, padding, logoWidth + textWidth);
if (logo) { if (logo) {
image.bitBlt(logo, left, Math.round((height - logo.height) / 2), { transparentZero: true }); image.bitBlt(logo, left, Math.round((height - logo.height) / 2), { transparentZero: true });
} }
+12 -2
View File
@@ -37,6 +37,7 @@ import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting";
import { type MenuItem } from "../../ui/menu"; import { type MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { Viewport } from "../../ui/viewport";
import { import {
directionalFallback, directionalFallback,
GESTURE_CLICK, GESTURE_CLICK,
@@ -250,6 +251,13 @@ type PinballWindow = {
title: string; title: string;
viewportWidth: number; viewportWidth: number;
viewportHeight: number; viewportHeight: number;
/**
* The viewport as the shell last sent it: besides the size above, what each
* edge touches and the padding suggested there. The window menu's layers
* lay out by it; the table and its panel are fixed art, drawn at the
* coordinates the physics runs in (see LAYOUT_HEIGHT).
*/
viewport: Viewport;
foreground: boolean; foreground: boolean;
/** Whether this window is the shell's input target (pushed with each message). */ /** Whether this window is the shell's input target (pushed with each message). */
focused: boolean; focused: boolean;
@@ -314,6 +322,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
title: message.title, title: message.title,
viewportWidth: message.viewport.width, viewportWidth: message.viewport.width,
viewportHeight: message.viewport.height, viewportHeight: message.viewport.height,
viewport: message.viewport,
foreground: false, foreground: false,
focused: false, focused: false,
menu: null, menu: null,
@@ -416,7 +425,8 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
if (!window) break; if (!window) break;
window.viewportWidth = message.viewport.width; window.viewportWidth = message.viewport.width;
window.viewportHeight = message.viewport.height; window.viewportHeight = message.viewport.height;
window.menu?.resize({ width: window.viewportWidth, height: window.viewportHeight }); window.viewport = message.viewport;
window.menu?.resize(message.viewport);
window.lastSubmittedFingerprint = ""; window.lastSubmittedFingerprint = "";
if (window.foreground) renderAndSubmit(window, 0); if (window.foreground) renderAndSubmit(window, 0);
break; break;
@@ -507,7 +517,7 @@ function windowMenu(window: PinballWindow): WindowMenu {
post, post,
title: () => window.title, title: () => window.title,
items: () => (window.phase === "playing" ? [] : windowMenuItems(window)), items: () => (window.phase === "playing" ? [] : windowMenuItems(window)),
size: { width: window.viewportWidth, height: window.viewportHeight }, size: window.viewport,
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
}); });
+88 -41
View File
@@ -22,6 +22,7 @@ import type { MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import { DatePickerLayer } from "../../ui/date-picker"; import { DatePickerLayer } from "../../ui/date-picker";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { Viewport } from "../../ui/viewport";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry"; import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures"; import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
import { import {
@@ -29,7 +30,7 @@ import {
roamGraphNameSetting, roamGraphNameSetting,
type ConfigSettingString, type ConfigSettingString,
} from "../../ui/dashboard-settings"; } from "../../ui/dashboard-settings";
import { DocumentView } from "../../ui/document/document-view"; import { DocumentView, type DocumentViewSize } from "../../ui/document/document-view";
import { docNodePageLink, type DocNode } from "../../ui/document/document-model"; import { docNodePageLink, type DocNode } from "../../ui/document/document-model";
import { import {
createBlock, createBlock,
@@ -56,9 +57,18 @@ import {
declare const global: any; declare const global: any;
const HEADER_HEIGHT = 30; /**
const BOTTOM_MARGIN = 6; * The fixed header, measured down from the padding suggested for the
const DOC_MARGIN = 6; * window's top edge: the rule under its title line, and its bottom, where
* the page's body starts.
*/
const HEADER_RULE_Y = 20;
const HEADER_HEIGHT = 24;
/** The header's title starts this far right of the rule's left end. */
const TITLE_INSET = 2;
/** Message text (the body messages, the setting-edit screen): its indent from the padding at each side, and its drop below the header. */
const MESSAGE_INSET = 12;
const MESSAGE_DROP = 16;
/** Reload the shown page when it is foregrounded and older than this. */ /** Reload the shown page when it is foregrounded and older than this. */
const STALE_AFTER_MS = 60_000; const STALE_AFTER_MS = 60_000;
@@ -70,6 +80,12 @@ type RoamWindow = {
title: string; title: string;
viewportWidth: number; viewportWidth: number;
viewportHeight: number; viewportHeight: number;
/**
* The viewport as the shell last sent it: besides the size above, what each
* edge touches and the padding suggested there, which the header and the
* document are placed by (see documentBox).
*/
viewport: Viewport;
foreground: boolean; foreground: boolean;
focused: boolean; focused: boolean;
menu: WindowMenu | null; menu: WindowMenu | null;
@@ -181,13 +197,11 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
title: message.title, title: message.title,
viewportWidth: message.viewport.width, viewportWidth: message.viewport.width,
viewportHeight: message.viewport.height, viewportHeight: message.viewport.height,
viewport: message.viewport,
foreground: false, foreground: false,
focused: false, focused: false,
menu: null, menu: null,
view: new DocumentView( view: new DocumentView(documentBox(message.viewport)),
message.viewport.width - DOC_MARGIN * 2,
message.viewport.height - HEADER_HEIGHT - BOTTOM_MARGIN,
),
lastSubmittedFingerprint: "", lastSubmittedFingerprint: "",
}; };
post({ type: "set-tools", windowId: message.windowId, tools: ROAM_TOOLS }); post({ type: "set-tools", windowId: message.windowId, tools: ROAM_TOOLS });
@@ -258,7 +272,8 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
if (!window || window.windowId !== message.windowId) break; if (!window || window.windowId !== message.windowId) break;
window.viewportWidth = message.viewport.width; window.viewportWidth = message.viewport.width;
window.viewportHeight = message.viewport.height; window.viewportHeight = message.viewport.height;
window.view.resize(message.viewport.width - DOC_MARGIN * 2, message.viewport.height - HEADER_HEIGHT - BOTTOM_MARGIN); window.viewport = message.viewport;
window.view.resize(documentBox(message.viewport));
window.menu?.resize(message.viewport); window.menu?.resize(message.viewport);
window.lastSubmittedFingerprint = ""; window.lastSubmittedFingerprint = "";
render(); render();
@@ -357,7 +372,7 @@ function windowMenu(win: RoamWindow): WindowMenu {
post, post,
title: () => win.title, title: () => win.title,
items: () => menuItems(), items: () => menuItems(),
size: { width: win.viewportWidth, height: win.viewportHeight }, size: win.viewport,
paintBase: () => paintContent(win), paintBase: () => paintContent(win),
isFocused: () => win.focused, isFocused: () => win.focused,
}); });
@@ -631,65 +646,97 @@ function paint(win: RoamWindow): Plane[] {
); );
} }
/** Bottom of the fixed header, where the page's body starts. */
function headerBottom(viewport: Viewport): number {
return viewport.padding.top + HEADER_HEIGHT;
}
/**
* The document's region: from the header down to the window's bottom edge,
* between the padding suggested for its sides. The document scrolls, so the
* bottom edge's padding goes inside it, after its last line, and lines
* scrolled past use the room right up to the edge.
*/
function documentBox(viewport: Viewport): DocumentViewSize & { x: number; y: number } {
const { width, height, padding } = viewport;
const y = headerBottom(viewport);
return {
x: padding.left,
y,
width: Math.max(0, width - padding.left - padding.right),
height: Math.max(0, height - y),
padBottom: padding.bottom,
};
}
/** Where message text starts and how wide it may run. */
function messageText(viewport: Viewport): { x: number; width: number } {
const { width, padding } = viewport;
return { x: padding.left + MESSAGE_INSET, width: width - padding.left - padding.right - 2 * MESSAGE_INSET };
}
/**
* The header's title, at the padding suggested for the window's top edge,
* and the rule under it, which spans the window between the side padding.
*/
function drawHeader(image: GrayImage, viewport: Viewport, title: string): void {
const { width, padding } = viewport;
image.drawText(smallFont, padding.left + TITLE_INSET, padding.top, title, 225);
const ruleY = padding.top + HEADER_RULE_Y;
image.drawLine(padding.left, ruleY, width - padding.right - 1, ruleY, 40);
}
/** The "type on the phone" screen shown while a Roam setting is being edited. */ /** The "type on the phone" screen shown while a Roam setting is being edited. */
function paintSettingEdit(win: RoamWindow, setting: ConfigSettingString): GrayImage { function paintSettingEdit(win: RoamWindow, setting: ConfigSettingString): GrayImage {
const { height, padding } = win.viewport;
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0); const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0);
const step = smallFont.lineHeight + 2; const step = smallFont.lineHeight + 2;
image.drawText(smallFont, DOC_MARGIN + 2, 6, setting.glassesEditTitle, 225); drawHeader(image, win.viewport, setting.glassesEditTitle);
image.drawLine(DOC_MARGIN, HEADER_HEIGHT - 4, win.viewportWidth - DOC_MARGIN, HEADER_HEIGHT - 4, 40); const text = messageText(win.viewport);
const messageY = HEADER_HEIGHT + 16; const messageY = headerBottom(win.viewport) + MESSAGE_DROP;
const lines = wrapText(smallFont, "Type the value in the phone app, or use voice input.", win.viewportWidth - DOC_MARGIN * 2 - 24); const lines = wrapText(smallFont, "Type the value in the phone app, or use voice input.", text.width);
for (let index = 0; index < lines.length; index++) { for (let index = 0; index < lines.length; index++) {
image.drawText(smallFont, DOC_MARGIN + 12, messageY + index * step, lines[index]!, 190); image.drawText(smallFont, text.x, messageY + index * step, lines[index]!, 190);
} }
// The live value, unmasked so the user can check what they typed. // The live value, unmasked so the user can check what they typed.
const value = setting.get(); const value = setting.get();
const valueY = messageY + (lines.length + 1) * step; const valueY = messageY + (lines.length + 1) * step;
image.drawText( image.drawText(smallFont, text.x, valueY, truncateText(smallFont, value || "(empty)", text.width), value ? 225 : 130);
smallFont, // The hint line rests on the padding suggested for the window's bottom edge.
DOC_MARGIN + 12, image.drawText(smallFont, text.x, height - padding.bottom - smallFont.lineHeight, `${GESTURE_CLICK} done`, 110);
valueY,
truncateText(smallFont, value || "(empty)", win.viewportWidth - DOC_MARGIN * 2 - 24),
value ? 225 : 130,
);
image.drawText(smallFont, DOC_MARGIN + 12, win.viewportHeight - smallFont.lineHeight - 12, `${GESTURE_CLICK} done`, 110);
return image; return image;
} }
function paintContent(win: RoamWindow): GrayImage { function paintContent(win: RoamWindow): GrayImage {
const { width, padding } = win.viewport;
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0); const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0);
const title = currentRef?.title ?? "Roam"; const title = currentRef?.title ?? "Roam";
const status = loading ? "Loading..." : pageMissing ? "(new page)" : ""; const status = loading ? "Loading..." : pageMissing ? "(new page)" : "";
const statusWidth = status ? smallFont.measureText(status) + 12 : 0; const statusWidth = status ? smallFont.measureText(status) + 12 : 0;
image.drawText( const titleWidth = width - padding.left - padding.right - statusWidth - 2 * TITLE_INSET;
smallFont, drawHeader(image, win.viewport, truncateText(smallFont, title, titleWidth));
DOC_MARGIN + 2,
6,
truncateText(smallFont, title, win.viewportWidth - DOC_MARGIN * 2 - statusWidth - 4),
225,
);
if (status) { if (status) {
image.drawText(smallFont, win.viewportWidth - DOC_MARGIN - smallFont.measureText(status), 6, status, 130); image.drawText(smallFont, width - padding.right - smallFont.measureText(status), padding.top, status, 130);
} }
image.drawLine(DOC_MARGIN, HEADER_HEIGHT - 4, win.viewportWidth - DOC_MARGIN, HEADER_HEIGHT - 4, 40);
if (!isRoamConfigured()) { if (!isRoamConfigured()) {
drawBodyMessage(image, win, "Set the Roam graph name and API token: tap, then hold, for the menu; pick Set graph name and Set API token."); drawBodyMessage(image, win.viewport, "Set the Roam graph name and API token: tap, then hold, for the menu; pick Set graph name and Set API token.");
} else if (errorMessage) { } else if (errorMessage) {
drawBodyMessage(image, win, `${errorMessage}\n\n${GESTURE_CLICK} retry`); drawBodyMessage(image, win.viewport, `${errorMessage}\n\n${GESTURE_CLICK} retry`);
} else if (currentPage && currentPage.children.length === 0 && !loading) { } else if (currentPage && currentPage.children.length === 0 && !loading) {
drawBodyMessage(image, win, "Nothing here yet. Use voice input to add a todo."); drawBodyMessage(image, win.viewport, "Nothing here yet. Use voice input to add a todo.");
} else { } else {
win.view.paint(image, DOC_MARGIN, HEADER_HEIGHT, win.focused); const box = documentBox(win.viewport);
win.view.paint(image, box.x, box.y, win.focused);
} }
return image; return image;
} }
function drawBodyMessage(image: GrayImage, win: RoamWindow, message: string): void { function drawBodyMessage(image: GrayImage, viewport: Viewport, message: string): void {
const lines = wrapText(smallFont, message, win.viewportWidth - DOC_MARGIN * 2 - 24); const text = messageText(viewport);
let y = HEADER_HEIGHT + 16; let y = headerBottom(viewport) + MESSAGE_DROP;
for (const line of lines) { for (const line of wrapText(smallFont, message, text.width)) {
image.drawText(smallFont, DOC_MARGIN + 12, y, line, 190); image.drawText(smallFont, text.x, y, line, 190);
y += smallFont.lineHeight + 2; y += smallFont.lineHeight + 2;
} }
} }
+159 -67
View File
@@ -43,6 +43,7 @@ import { drawSubmenuIndicator, submenuItem, type MenuItem } from "../../ui/menu"
import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics"; import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics";
import { WindowMenu, WindowMenuLayer } from "../../ui/window-menu"; import { WindowMenu, WindowMenuLayer } from "../../ui/window-menu";
import type { Viewport } from "../../ui/viewport";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry"; import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures"; import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures";
@@ -131,12 +132,27 @@ const VISIT_THROTTLE_MS = 10_000;
/** How long a transient status ("Sent", an error) stays in a footer. */ /** How long a transient status ("Sent", an error) stays in a footer. */
const NOTICE_MS = 6_000; const NOTICE_MS = 6_000;
const SETTLED_SHOWN = 25; const SETTLED_SHOWN = 25;
const LIST_LEFT = 12; // Every screen lays out inside the padding suggested for its window's edges
const LIST_RIGHT = 20; // (viewport.ts); these are offsets from it.
const TITLE_X = 18; /**
const TITLE_Y = 10; * A list screen's title: how far right of the rows' selection boxes, which
const BODY_LEFT = 14; * start at the left padding (so it lines up with their text), and how far
const BODY_RIGHT = 18; * below the top padding.
*/
const LIST_TITLE_INSET_X = 6;
const LIST_TITLE_OFFSET_Y = 2;
/** Between a title and a status that shares its row. */
const TITLE_STATUS_GAP = 16;
/** Below a title's line: the gap before the list's first text line, and how far above that line its selection box starts. */
const LIST_TITLE_GAP = 8;
const LIST_LEAD = 2;
/** A list's scrollbar (Menu.drawScrollbar's bar), hugging the right padding, and the gap the rows keep from it. */
const LIST_SCROLLBAR_WIDTH = 3;
const LIST_SCROLLBAR_GAP = 10;
/** How far a list's scrollbar track stops short of the rows' span at each end. */
const LIST_SCROLLBAR_INSET = 2;
/** Between a list and lines of text pinned under it. */
const LIST_FOOTER_GAP = 6;
function font(): UiFont { function font(): UiFont {
return getDefaultSmallFont(); return getDefaultSmallFont();
@@ -155,8 +171,8 @@ type Screen =
type AppWindow = { type AppWindow = {
windowId: string; windowId: string;
surfaceId: string; surfaceId: string;
viewportWidth: number; /** The window's size, what its edges touch and their padding, as of the last open or resize message. */
viewportHeight: number; viewport: Viewport;
foreground: boolean; foreground: boolean;
focused: boolean; focused: boolean;
menu: WindowMenu | null; menu: WindowMenu | null;
@@ -365,8 +381,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
window = { window = {
windowId: message.windowId, windowId: message.windowId,
surfaceId: message.surfaceId, surfaceId: message.surfaceId,
viewportWidth: message.viewport.width, viewport: message.viewport,
viewportHeight: message.viewport.height,
foreground: false, foreground: false,
focused: false, focused: false,
menu: null, menu: null,
@@ -379,8 +394,9 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
break; break;
case "resize-window": case "resize-window":
if (!window || window.windowId !== message.windowId) break; if (!window || window.windowId !== message.windowId) break;
window.viewportWidth = message.viewport.width; // A new size, or the same size with different edges (so padding):
window.viewportHeight = message.viewport.height; // either way every screen lays out again.
window.viewport = message.viewport;
window.menu?.resize(message.viewport); window.menu?.resize(message.viewport);
window.lastSubmittedFingerprint = ""; window.lastSubmittedFingerprint = "";
render(); render();
@@ -760,7 +776,7 @@ function windowMenu(win: AppWindow): WindowMenu {
post, post,
title: () => (screen.kind === "thread" ? threadTitle() : APP_TITLE), title: () => (screen.kind === "thread" ? threadTitle() : APP_TITLE),
items: () => menuItems(), items: () => menuItems(),
size: { width: win.viewportWidth, height: win.viewportHeight }, size: win.viewport,
paintBase: () => paintContent(win), paintBase: () => paintContent(win),
isFocused: () => win.focused, isFocused: () => win.focused,
}); });
@@ -1886,49 +1902,110 @@ function listStatusLine(): string {
return glanceSummary({ needsYou: needs, working }); return glanceSummary({ needsYou: needs, working });
} }
/**
* Paint a list screen's title, and a dim status beside it, inside the
* window's top padding. Returns the title's x (other text on the screen
* lines up with it) and the y of the first text line below it.
*/
function paintListTitle(image: GrayImage, viewport: Viewport, title: string, status: string): { x: number; listTop: number } {
const f = font();
const { width, padding } = viewport;
const x = padding.left + LIST_TITLE_INSET_X;
const y = padding.top + LIST_TITLE_OFFSET_Y;
image.drawText(f, x, y, title, 220);
if (status) {
const statusX = x + f.measureText(title) + TITLE_STATUS_GAP;
image.drawText(f, statusX, y, truncateText(f, status, width - padding.right - statusX), 150);
}
return { x, listTop: y + lineStep(f) + LIST_TITLE_GAP };
}
/** Where a list's scrollbar starts: it hugs the window's right padding. */
function listScrollbarX(viewport: Viewport): number {
return viewport.width - viewport.padding.right - LIST_SCROLLBAR_WIDTH;
}
/** Width of a list's rows, from the window's left padding to the scrollbar's gutter. */
function listRowsWidth(viewport: Viewport): number {
return Math.max(0, listScrollbarX(viewport) - LIST_SCROLLBAR_GAP - viewport.padding.left);
}
/**
* Paint the list from just above the text line at `listTop` down to the
* window's bottom edge, or to above the text pinned under it at `footerTop`.
* The list scrolls, so at the window's edge it takes that edge's padding
* inside it, after its last row: the row rests clear of a border there, and
* rows scrolled past the end are cut off at the edge itself.
*/
function paintListRows(win: AppWindow, image: GrayImage, menu: Menu<ListItem>, listTop: number, footerTop?: number): void {
const { height, padding } = win.viewport;
const toEdge = footerTop === undefined;
const boxTop = listTop - LIST_LEAD;
const boxBottom = toEdge ? height : footerTop - LIST_FOOTER_GAP;
// Where the last row ends once scrolled to it.
const rowsBottom = toEdge ? height - padding.bottom : boxBottom;
menu.paint(
image,
{ x: padding.left, y: boxTop, width: listRowsWidth(win.viewport), height: Math.max(0, boxBottom - boxTop), padBottom: toEdge ? padding.bottom : 0 },
win.focused,
);
const trackTop = boxTop + LIST_SCROLLBAR_INSET;
menu.drawScrollbar(image, listScrollbarX(win.viewport), trackTop, Math.max(0, rowsBottom - LIST_SCROLLBAR_INSET - trackTop));
}
function paintList(win: AppWindow, mode: "list" | "environments"): GrayImage { function paintList(win: AppWindow, mode: "list" | "environments"): GrayImage {
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0); const { width, height, padding } = win.viewport;
const image = new GrayImage(width, height, 0);
const f = font(); const f = font();
const step = lineStep(f); const step = lineStep(f);
const title = mode === "environments" ? "T3 Code - Environments" : APP_TITLE; const title = mode === "environments" ? "T3 Code - Environments" : APP_TITLE;
image.drawText(f, TITLE_X, TITLE_Y, title, 220);
const status = mode === "list" ? listStatusLine() : notice?.text ?? ""; const status = mode === "list" ? listStatusLine() : notice?.text ?? "";
if (status) { const header = paintListTitle(image, win.viewport, title, status);
const statusX = TITLE_X + f.measureText(title) + 16; let listTop = header.listTop;
image.drawText(f, statusX, TITLE_Y, truncateText(f, status, win.viewportWidth - statusX - 14), 150);
}
let listTop = TITLE_Y + step + 8;
if (mode === "list" && clients.size === 0) { if (mode === "list" && clients.size === 0) {
const help = wrapText( const help = wrapText(
f, f,
"Run `t3 pair` on the computer running T3 Code (serve it on your network with `t3 serve --host 0.0.0.0`, or use Tailscale), then pick Pair below and paste the link into the phone app.", "Run `t3 pair` on the computer running T3 Code (serve it on your network with `t3 serve --host 0.0.0.0`, or use Tailscale), then pick Pair below and paste the link into the phone app.",
win.viewportWidth - TITLE_X * 2, width - padding.right - header.x,
); );
help.forEach((line, index) => image.drawText(f, TITLE_X, listTop + index * step, line, 160)); help.forEach((line, index) => image.drawText(f, header.x, listTop + index * step, line, 160));
listTop += help.length * step + 8; listTop += help.length * step + 8;
} }
const items = mode === "environments" ? environmentItems() : listItems(); const items = mode === "environments" ? environmentItems() : listItems();
const menu = list(); const menu = list();
menu.setItems(items, selectionIndex(items)); menu.setItems(items, selectionIndex(items));
listSelectionKey = menu.selectedItem?.key ?? listSelectionKey; listSelectionKey = menu.selectedItem?.key ?? listSelectionKey;
const listHeight = win.viewportHeight - 6 - listTop; paintListRows(win, image, menu, listTop);
menu.paint(image, { x: LIST_LEFT, y: listTop - 2, width: win.viewportWidth - LIST_LEFT - LIST_RIGHT, height: listHeight }, win.focused);
menu.drawScrollbar(image, win.viewportWidth - 10, listTop, listHeight - 4);
return image; return image;
} }
const THREAD_HEADER_HEIGHT = 28; /** The thread screen's header, below its title's top: the rule under the title, and the transcript's first line. */
const THREAD_RULE_OFFSET = 18;
const THREAD_BODY_OFFSET = 26;
/** How far the thread screen's text sits inside the ends of its header rule. */
const THREAD_TEXT_INSET = 2;
/** The transcript's scrollbar, hugging the window's right padding, and the gap the header rule keeps from it. */
const THREAD_SCROLLBAR_WIDTH = 2;
const THREAD_SCROLLBAR_GAP = 8;
/** Between the transcript and the footer under it. */
const THREAD_FOOTER_GAP = 4;
/** The transcript's top: its header stays put above it, inside the window's top padding. */
function threadBodyTop(): number { function threadBodyTop(): number {
return THREAD_HEADER_HEIGHT + 4; return (window?.viewport.padding.top ?? 0) + THREAD_BODY_OFFSET;
} }
/** Body height above the footer (hint line, plus a plan line when there is one). */ /**
* Body height above the footer (hint line, plus a plan line when there is
* one), whose last line rests on the window's bottom padding.
*/
function threadBodyHeight(): number { function threadBodyHeight(): number {
if (!window) return 0; if (!window) return 0;
const step = lineStep(font()); const f = font();
const { height, padding } = window.viewport;
const footerLines = threadView?.handle.model.todoList() && currentShellThread() && threadStatus(currentShellThread()!) === "working" ? 2 : 1; const footerLines = threadView?.handle.model.todoList() && currentShellThread() && threadStatus(currentShellThread()!) === "working" ? 2 : 1;
return window.viewportHeight - threadBodyTop() - footerLines * step - 8; const footerTop = height - padding.bottom - f.lineHeight - (footerLines - 1) * lineStep(f);
return footerTop - THREAD_FOOTER_GAP - threadBodyTop();
} }
function threadFooterHint(): { text: string; value: number } { function threadFooterHint(): { text: string; value: number } {
@@ -1948,18 +2025,28 @@ function threadFooterHint(): { text: string; value: number } {
} }
function paintThread(win: AppWindow): GrayImage { function paintThread(win: AppWindow): GrayImage {
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0); const { width: windowWidth, height, padding } = win.viewport;
const image = new GrayImage(windowWidth, height, 0);
const view = threadView; const view = threadView;
const f = font(); const f = font();
const step = lineStep(f); const step = lineStep(f);
const width = win.viewportWidth - BODY_LEFT - BODY_RIGHT; // The header rule runs from the window's left padding to the gutter kept
// for the scrollbar, which hugs the right padding; text sits just inside
// the rule's ends.
const scrollbarX = windowWidth - padding.right - THREAD_SCROLLBAR_WIDTH;
const ruleLeft = padding.left;
const ruleRight = scrollbarX - THREAD_SCROLLBAR_GAP;
const left = ruleLeft + THREAD_TEXT_INSET;
const right = ruleRight - THREAD_TEXT_INSET;
const width = Math.max(0, right - left);
if (!view) return image; if (!view) return image;
const shell = currentShellThread(); const shell = currentShellThread();
const status = shell ? threadStatusLabel(threadStatus(shell)) : ""; const status = shell ? threadStatusLabel(threadStatus(shell)) : "";
const statusWidth = status ? f.measureText(status) + 12 : 0; const statusWidth = status ? f.measureText(status) + 12 : 0;
image.drawText(f, BODY_LEFT, 6, truncateText(f, threadTitle(), width - statusWidth), 225); const titleY = padding.top;
if (status) image.drawText(f, win.viewportWidth - BODY_RIGHT - f.measureText(status), 6, status, 150); image.drawText(f, left, titleY, truncateText(f, threadTitle(), width - statusWidth), 225);
image.drawLine(BODY_LEFT - 2, THREAD_HEADER_HEIGHT - 4, win.viewportWidth - BODY_RIGHT + 2, THREAD_HEADER_HEIGHT - 4, 40); if (status) image.drawText(f, right - f.measureText(status), titleY, status, 150);
image.drawLine(ruleLeft, titleY + THREAD_RULE_OFFSET, ruleRight, titleY + THREAD_RULE_OFFSET, 40);
const model = view.handle.model; const model = view.handle.model;
const bodyTop = threadBodyTop(); const bodyTop = threadBodyTop();
@@ -1967,9 +2054,9 @@ function paintThread(win: AppWindow): GrayImage {
const visible = Math.max(1, Math.floor(bodyHeight / step)); const visible = Math.max(1, Math.floor(bodyHeight / step));
if (model.sequence === null) { if (model.sequence === null) {
const client = clients.get(view.envId); const client = clients.get(view.envId);
image.drawText(f, BODY_LEFT, bodyTop, client?.ready ? "Loading…" : client?.status || "Not connected", 150); image.drawText(f, left, bodyTop, client?.ready ? "Loading…" : client?.status || "Not connected", 150);
} else if (model.deleted) { } else if (model.deleted) {
image.drawText(f, BODY_LEFT, bodyTop, "This thread was deleted.", 150); image.drawText(f, left, bodyTop, "This thread was deleted.", 150);
} else { } else {
const lines = view.layout.layout(timelineEntries(model), f, width); const lines = view.layout.layout(timelineEntries(model), f, width);
if (model.hasMoreHistory) lines.unshift({ text: "(earlier messages on the computer)", value: 90, indent: 0 }, { text: "", value: 0, indent: 0 }); if (model.hasMoreHistory) lines.unshift({ text: "(earlier messages on the computer)", value: 90, indent: 0 }, { text: "", value: 0, indent: 0 });
@@ -1978,21 +2065,22 @@ function paintThread(win: AppWindow): GrayImage {
const first = view.firstLine ?? view.maxFirstLine; const first = view.firstLine ?? view.maxFirstLine;
for (let row = 0; row < visible; row++) { for (let row = 0; row < visible; row++) {
const line = lines[first + row]; const line = lines[first + row];
if (line?.text) image.drawText(f, BODY_LEFT + line.indent, bodyTop + row * step, line.text, line.value); if (line?.text) image.drawText(f, left + line.indent, bodyTop + row * step, line.text, line.value);
} }
if (view.maxFirstLine > 0) { if (view.maxFirstLine > 0) {
const track = visible * step; const track = visible * step;
const thumb = Math.max(8, Math.floor((track * visible) / lines.length)); const thumb = Math.max(8, Math.floor((track * visible) / lines.length));
image.fillRect(win.viewportWidth - 8, bodyTop + Math.floor(((track - thumb) * first) / view.maxFirstLine), 2, thumb, 110); image.fillRect(scrollbarX, bodyTop + Math.floor(((track - thumb) * first) / view.maxFirstLine), THREAD_SCROLLBAR_WIDTH, thumb, 110);
} }
} }
// Footer: the agent's plan progress while it works, then the hint/status line. // Footer: the agent's plan progress while it works, then the hint/status
let footerY = win.viewportHeight - step - 4; // line, resting on the window's bottom padding.
let footerY = height - padding.bottom - f.lineHeight;
const hint = threadFooterHint(); const hint = threadFooterHint();
if (hint.text) { if (hint.text) {
const text = truncateText(f, hint.text, width); const text = truncateText(f, hint.text, width);
image.drawText(f, win.viewportWidth - BODY_RIGHT - f.measureText(text), footerY, text, hint.value); image.drawText(f, right - f.measureText(text), footerY, text, hint.value);
} }
const todo = model.todoList(); const todo = model.todoList();
if (todo && shell && threadStatus(shell) === "working") { if (todo && shell && threadStatus(shell) === "working") {
@@ -2001,28 +2089,38 @@ function paintThread(win: AppWindow): GrayImage {
const done = steps.filter((entry) => entry.status === "completed").length; const done = steps.filter((entry) => entry.status === "completed").length;
const current = steps.find((entry) => entry.status === "running") ?? steps.find((entry) => entry.status === "pending"); const current = steps.find((entry) => entry.status === "running") ?? steps.find((entry) => entry.status === "pending");
const text = `Plan ${done}/${steps.length}${current ? ` · ${plainMarkdown(current.text)}` : ""}`; const text = `Plan ${done}/${steps.length}${current ? ` · ${plainMarkdown(current.text)}` : ""}`;
image.drawText(f, BODY_LEFT, footerY, truncateText(f, text, width), 160); image.drawText(f, left, footerY, truncateText(f, text, width), 160);
} }
return image; return image;
} }
/**
* A screen of text: a title, paragraphs wrapped to the window, and a hint
* line. With no rows to line up with, the text sits right at the window's
* padding on every side.
*/
function paintMessageScreen(win: AppWindow, title: string, paragraphs: Array<{ text: string; value: number }>, footer: string): GrayImage { function paintMessageScreen(win: AppWindow, title: string, paragraphs: Array<{ text: string; value: number }>, footer: string): GrayImage {
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0); const { width: windowWidth, height, padding } = win.viewport;
const image = new GrayImage(windowWidth, height, 0);
const f = font(); const f = font();
const step = lineStep(f); const step = lineStep(f);
const width = win.viewportWidth - TITLE_X * 2; const x = padding.left;
image.drawText(f, TITLE_X, TITLE_Y, title, 220); const width = windowWidth - padding.left - padding.right;
let y = TITLE_Y + step + 10; image.drawText(f, x, padding.top, title, 220);
let y = padding.top + step + 10;
const footerY = height - padding.bottom - f.lineHeight;
// Paragraph lines stop above the hint line, or at the bottom padding when there is none.
const bodyBottom = footer ? footerY : height - padding.bottom;
for (const paragraph of paragraphs) { for (const paragraph of paragraphs) {
if (!paragraph.text) continue; if (!paragraph.text) continue;
for (const line of wrapText(f, paragraph.text, width)) { for (const line of wrapText(f, paragraph.text, width)) {
if (y > win.viewportHeight - 2 * step) break; if (y + f.lineHeight > bodyBottom) break;
image.drawText(f, TITLE_X, y, line, paragraph.value); image.drawText(f, x, y, line, paragraph.value);
y += step; y += step;
} }
y += 6; y += 6;
} }
if (footer) image.drawText(f, TITLE_X, win.viewportHeight - step - 6, footer, 110); if (footer) image.drawText(f, x, footerY, footer, 110);
return image; return image;
} }
@@ -2050,32 +2148,26 @@ function paintPair(win: AppWindow): GrayImage {
function paintCompose(win: AppWindow): GrayImage { function paintCompose(win: AppWindow): GrayImage {
const target = composeTarget(); const target = composeTarget();
if (!target) return paintMessageScreen(win, "New thread", [{ text: "That project is no longer available.", value: 170 }], ""); if (!target) return paintMessageScreen(win, "New thread", [{ text: "That project is no longer available.", value: 170 }], "");
const image = new GrayImage(win.viewportWidth, win.viewportHeight, 0); const { width, height, padding } = win.viewport;
const image = new GrayImage(width, height, 0);
const f = font(); const f = font();
const step = lineStep(f); const step = lineStep(f);
const title = "New thread"; const header = paintListTitle(image, win.viewport, "New thread", busyText || notice?.text || "");
image.drawText(f, TITLE_X, TITLE_Y, title, 220); // Below the list: an error, or why nothing can start here. Its lines stay
const status = busyText || notice?.text || ""; // put, the last resting on the window's bottom padding, and the list ends
if (status) { // above them.
const statusX = TITLE_X + f.measureText(title) + 16;
image.drawText(f, statusX, TITLE_Y, truncateText(f, status, win.viewportWidth - statusX - 14), 150);
}
// Below the list: an error, or why nothing can start here.
const resolved = composeResolved(target); const resolved = composeResolved(target);
const problem = screenError || (resolved.model ? "" : (resolved.blocker ?? "")); const problem = screenError || (resolved.model ? "" : (resolved.blocker ?? ""));
const problemLines = problem ? wrapText(f, problem, win.viewportWidth - TITLE_X * 2).slice(0, 3) : []; const problemLines = problem ? wrapText(f, problem, width - padding.right - header.x).slice(0, 3) : [];
const listTop = TITLE_Y + step + 8; const problemTop = height - padding.bottom - f.lineHeight - (problemLines.length - 1) * step;
const listWidth = win.viewportWidth - LIST_LEFT - LIST_RIGHT;
const listHeight = win.viewportHeight - 6 - listTop - (problemLines.length ? problemLines.length * step + 6 : 0);
const items = composeItems(); const items = composeItems();
const widest = Math.max(0, ...items.filter((item) => item.kind === "field").map((item) => f.measureText(item.label))); const widest = Math.max(0, ...items.filter((item) => item.kind === "field").map((item) => f.measureText(item.label)));
composeValueColumn = Math.min(widest + 16, Math.floor(listWidth * 0.4)); composeValueColumn = Math.min(widest + 16, Math.floor(listRowsWidth(win.viewport) * 0.4));
const menu = list(); const menu = list();
menu.setItems(items, selectionIndex(items)); menu.setItems(items, selectionIndex(items));
composeSelectionKey = menu.selectedItem?.key ?? composeSelectionKey; composeSelectionKey = menu.selectedItem?.key ?? composeSelectionKey;
menu.paint(image, { x: LIST_LEFT, y: listTop - 2, width: listWidth, height: listHeight }, win.focused); paintListRows(win, image, menu, header.listTop, problemLines.length ? problemTop : undefined);
menu.drawScrollbar(image, win.viewportWidth - 10, listTop, listHeight - 4); problemLines.forEach((line, index) => image.drawText(f, header.x, problemTop + index * step, line, 230));
problemLines.forEach((line, index) => image.drawText(f, TITLE_X, listTop + listHeight + 4 + index * step, line, 230));
return image; return image;
} }
+28 -15
View File
@@ -9,8 +9,6 @@ import { lineStep } from "../../ui/metrics";
import { clamp } from "../../util/numeric-util"; import { clamp } from "../../util/numeric-util";
import { ScriptTracker, tokenizeScript, type TokenizedScript } from "./script-tracker"; import { ScriptTracker, tokenizeScript, type TokenizedScript } from "./script-tracker";
const MARGIN_X = 18;
const BODY_TOP = 6;
/** Gap between the last body line and the footer. */ /** Gap between the last body line and the footer. */
const FOOTER_GAP = 4; const FOOTER_GAP = 4;
/** Lines per ring scroll tick. */ /** Lines per ring scroll tick. */
@@ -41,6 +39,11 @@ export type ReaderHooks = {
* and re-anchor the tracker to what is now at the anchor row, so scrolling * and re-anchor the tracker to what is now at the anchor row, so scrolling
* doubles as "I'm here now". Click pauses/resumes tracking; double-click * doubles as "I'm here now". Click pauses/resumes tracking; double-click
* goes back to the file list. * goes back to the file list.
*
* The script's column and the footer line keep inside the padding suggested
* for the window's edges. The lines scroll, so they run from the window's
* top edge itself: only the script's first line keeps that edge's padding
* above it.
*/ */
export class TeleprompterReaderLayer implements Layer { export class TeleprompterReaderLayer implements Layer {
private readonly script: TokenizedScript; private readonly script: TokenizedScript;
@@ -116,13 +119,18 @@ export class TeleprompterReaderLayer implements Layer {
const font = getDefaultMediumFont(); const font = getDefaultMediumFont();
const smallFont = getDefaultSmallFont(); const smallFont = getDefaultSmallFont();
const step = lineStep(font); const step = lineStep(font);
const { width, height } = ctx.stack.getBaseSize(); const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const bodyX = padding.left;
const bodyWidth = Math.max(0, width - padding.left - padding.right);
const footerY = height - smallFont.lineHeight - 4; const footerY = height - padding.bottom - smallFont.lineHeight;
this.visibleRows = Math.max(1, Math.floor((footerY - FOOTER_GAP - BODY_TOP) / step)); const bodyBottom = footerY - FOOTER_GAP;
// Rows that fit wherever the script is scrolled to, which is what
// scrolling and the anchor row go by.
this.visibleRows = Math.max(1, Math.floor((bodyBottom - padding.top) / step));
this.anchorRow = Math.floor(this.visibleRows / 3); this.anchorRow = Math.floor(this.visibleRows / 3);
const lines = this.layout(font, width - 2 * MARGIN_X); const lines = this.layout(font, bodyWidth);
if (this.autoScrollPending) { if (this.autoScrollPending) {
this.autoScrollPending = false; this.autoScrollPending = false;
@@ -133,20 +141,24 @@ export class TeleprompterReaderLayer implements Layer {
const position = this.tracker.position; const position = this.tracker.position;
const nextToken = position < this.script.words.length ? this.script.wordTokens[position]! : this.script.tokens.length; const nextToken = position < this.script.words.length ? this.script.wordTokens[position]! : this.script.tokens.length;
const lastLine = Math.min(lines.length, this.firstLine + this.visibleRows); // Scrolled past the script's start, the lines begin at the window's top
// edge and the top padding's room may hold one more of them.
const bodyTop = this.firstLine === 0 ? padding.top : 0;
const shownRows = Math.max(1, Math.floor((bodyBottom - bodyTop) / step));
const lastLine = Math.min(lines.length, this.firstLine + shownRows);
for (let lineIndex = this.firstLine; lineIndex < lastLine; lineIndex++) { for (let lineIndex = this.firstLine; lineIndex < lastLine; lineIndex++) {
const y = BODY_TOP + (lineIndex - this.firstLine) * step; const y = bodyTop + (lineIndex - this.firstLine) * step;
for (const span of lines[lineIndex]!.spans) { for (const span of lines[lineIndex]!.spans) {
const isNext = span.tokenIndex === nextToken; const isNext = span.tokenIndex === nextToken;
const value = isNext ? NEXT_VALUE : span.tokenIndex < nextToken ? PAST_VALUE : UPCOMING_VALUE; const value = isNext ? NEXT_VALUE : span.tokenIndex < nextToken ? PAST_VALUE : UPCOMING_VALUE;
image.drawText(font, MARGIN_X + span.x, y, span.text, value); image.drawText(font, bodyX + span.x, y, span.text, value);
if (isNext) { if (isNext) {
image.fillRect(MARGIN_X + span.x, y + font.lineHeight - 2, span.width, 2, NEXT_VALUE); image.fillRect(bodyX + span.x, y + font.lineHeight - 2, span.width, 2, NEXT_VALUE);
} }
} }
} }
this.paintFooter(image, smallFont, width, footerY); this.paintFooter(image, smallFont, bodyX, bodyWidth, footerY);
return image; return image;
} }
@@ -169,15 +181,16 @@ export class TeleprompterReaderLayer implements Layer {
} }
} }
private paintFooter(image: GrayImage, font: UiFont, width: number, y: number): void { /** The footer line across [x, x + width): the script's name at its left, status and progress at its right. */
private paintFooter(image: GrayImage, font: UiFont, x: number, width: number, y: number): void {
const total = this.script.words.length; const total = this.script.words.length;
const percent = total === 0 ? 0 : Math.round((100 * this.tracker.position) / total); const percent = total === 0 ? 0 : Math.round((100 * this.tracker.position) / total);
const right = `${this.tracking ? this.status || "Listening" : "Paused"} ${percent}%`; const right = `${this.tracking ? this.status || "Listening" : "Paused"} ${percent}%`;
const rightWidth = font.measureText(right); const rightWidth = font.measureText(right);
image.drawText(font, width - MARGIN_X - rightWidth, y, right, 110); image.drawText(font, x + width - rightWidth, y, right, 110);
const titleMax = width - 2 * MARGIN_X - rightWidth - 12; const titleMax = width - rightWidth - 12;
if (titleMax > 20) { if (titleMax > 20) {
image.drawText(font, MARGIN_X, y, truncateText(font, this.title, titleMax), 110); image.drawText(font, x, y, truncateText(font, this.title, titleMax), 110);
} }
} }
+1 -10
View File
@@ -4,7 +4,6 @@ import { readTextFile, type DirectoryEntry } from "../../native/file-access";
import { LIST_ROW_TEXT_INSET } from "../../ui/metrics"; import { LIST_ROW_TEXT_INSET } from "../../ui/metrics";
import { MenuLayer, type MenuItem } from "../../ui/menu"; import { MenuLayer, type MenuItem } from "../../ui/menu";
import { type Layer, type LayerContext } from "../../ui/layers"; import { type Layer, type LayerContext } from "../../ui/layers";
import { appViewportSize } from "../../ui/shell/geometry";
import { import {
createInProcessWindow, createInProcessWindow,
YieldAtRootLayer, YieldAtRootLayer,
@@ -28,15 +27,7 @@ export const TELEPROMPTER_SURFACE_ID = "window:teleprompter";
const SCRIPT_FILE = /\.(txt|md|markdown|text|log)$/i; const SCRIPT_FILE = /\.(txt|md|markdown|text|log)$/i;
const HOME_LAYOUT = { const HOME_LAYOUT = { page: true, width: 248 } as const;
x: 8,
y: 8,
width: 272,
showBorder: false,
minHeight: 0,
maxHeight: appViewportSize("min").height - 16,
opaque: true,
};
export type TeleprompterAppOptions = InProcessAppOptions & { export type TeleprompterAppOptions = InProcessAppOptions & {
/** Hold continuous mic capture while a script is being tracked. */ /** Hold continuous mic capture while a script is being tracked. */
+37 -10
View File
@@ -1,14 +1,41 @@
import { wrapText, type WrapFont } from '../../graphics/textwrap'; import { wrapText, type WrapFont } from '../../graphics/textwrap';
import type { Edges } from '../../ui/viewport';
/** Left edge of the hub's title line (and of a wrapped status block under it). */ /**
export const HUB_TITLE_X = 12; * Where the hub's title line (and a wrapped status block under it) starts,
* right of the window's left padding: the list's selection boxes start at
* the padding and unindented row text sits this far inside its box, so the
* title lines up with it.
*/
export const HUB_TITLE_INSET_X = 6;
/** The title line's top, below the window's top padding. */
const HUB_TITLE_OFFSET_Y = 2;
/** Between the title and a status that shares its row. */
const HUB_STATUS_GAP = 16;
/** Between the header's last line and the list's first text line. */
const HUB_LIST_GAP = 6;
/** Keep short status on the title row; give long errors their full width. */ /**
export function layoutHubHeader(font: WrapFont, title: string, status: string, width: number, step: number) { * Lay the hub's header out in a window `width` wide with the suggested
const inlineX = HUB_TITLE_X + font.measureText(title) + 16; * `padding` (viewport.ts): the title inside the top and left padding, the
const inline = !/[\r\n]/.test(status) && font.measureText(status) <= Math.max(0, width - inlineX - 12); * status ending at the right padding. Keep short status on the title row;
const lines = inline ? [status] : wrapText(font, status, Math.max(1, width - HUB_TITLE_X - 12)); * give long errors their full width.
const x = inline ? inlineX : HUB_TITLE_X; */
const y = inline ? 10 : 10 + step; export function layoutHubHeader(
return { x, y, lines, listTop: inline ? 16 + step : 16 + step * (1 + lines.length) }; font: WrapFont,
title: string,
status: string,
viewport: { width: number; padding: Edges<number> },
step: number,
) {
const { width, padding } = viewport;
const titleX = padding.left + HUB_TITLE_INSET_X;
const titleY = padding.top + HUB_TITLE_OFFSET_Y;
const right = width - padding.right;
const inlineX = titleX + font.measureText(title) + HUB_STATUS_GAP;
const inline = !/[\r\n]/.test(status) && font.measureText(status) <= Math.max(0, right - inlineX);
const lines = inline ? [status] : wrapText(font, status, Math.max(1, right - titleX));
const x = inline ? inlineX : titleX;
const y = inline ? titleY : titleY + step;
return { titleX, titleY, x, y, lines, listTop: titleY + HUB_LIST_GAP + step * (inline ? 1 : 1 + lines.length) };
} }
+83 -35
View File
@@ -45,7 +45,7 @@ import { GrayImage, type UiFont } from "../../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane";
import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts"; import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts";
import { HUB_TITLE_X, layoutHubHeader } from "./hub-header"; import { HUB_TITLE_INSET_X, layoutHubHeader } from "./hub-header";
import { TERMINAL_ICON_GLYPHS, type IconActivity } from "../../graphics/icons"; import { TERMINAL_ICON_GLYPHS, type IconActivity } from "../../graphics/icons";
import { import {
drawSessionRow, drawSessionRow,
@@ -76,6 +76,7 @@ import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
import { centeredTextY, lineStep, listRowHeight, textInkHeight } from "../../ui/metrics"; import { centeredTextY, lineStep, listRowHeight, textInkHeight } from "../../ui/metrics";
import { WindowMenu, WindowMenuLayer } from "../../ui/window-menu"; import { WindowMenu, WindowMenuLayer } from "../../ui/window-menu";
import { appViewportSize, type WindowHeightMode } from "../../ui/shell/geometry"; import { appViewportSize, type WindowHeightMode } from "../../ui/shell/geometry";
import type { EdgeKind, Edges, Viewport } from "../../ui/viewport";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry"; import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
@@ -123,6 +124,13 @@ type BaseWindow = {
/** Content viewport from the shell's open-window message; grid = viewport / cell. */ /** Content viewport from the shell's open-window message; grid = viewport / cell. */
viewportWidth: number; viewportWidth: number;
viewportHeight: number; viewportHeight: number;
/**
* What the viewport's edges touch and the padding suggested for them
* (viewport.ts), as of the last open or resize message. The hub's pages lay
* out inside the padding; a session's grid fills the window regardless.
*/
edges: Edges<EdgeKind>;
padding: Edges<number>;
gridCols: number; gridCols: number;
gridRows: number; gridRows: number;
foreground: boolean; foreground: boolean;
@@ -216,8 +224,6 @@ type PendingView = {
options: G2MirrorClientOptions; options: G2MirrorClientOptions;
}; };
type Viewport = { width: number; height: number };
const windows = new Map<string, TerminalWindow>(); const windows = new Map<string, TerminalWindow>();
const pendingViews = new Map<string, PendingView>(); const pendingViews = new Map<string, PendingView>();
// Windows waiting on the shell's answer to a set-height-mode, by window id: // Windows waiting on the shell's answer to a set-height-mode, by window id:
@@ -364,11 +370,22 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
break; break;
} }
const window = windows.get(message.windowId); const window = windows.get(message.windowId);
if (!window || (window.viewportWidth === message.viewport.width && window.viewportHeight === message.viewport.height)) break; if (!window) break;
const resized = window.viewportWidth !== message.viewport.width || window.viewportHeight !== message.viewport.height;
window.viewportWidth = message.viewport.width; window.viewportWidth = message.viewport.width;
window.viewportHeight = message.viewport.height; window.viewportHeight = message.viewport.height;
window.edges = message.viewport.edges;
window.padding = message.viewport.padding;
window.menu?.resize(message.viewport); window.menu?.resize(message.viewport);
window.lastSubmittedFingerprint = ""; // A resize at the same size says what the window's edges touch has
// changed. The hub's pages move with their padding; a session's grid
// does not, so it keeps its connection, and only a menu page open over
// it (which lays out in the padding) has anything to repaint.
if (window.kind === "view" && !resized) {
if (window.menu?.isOpen()) scheduleRender(window);
break;
}
if (resized) window.lastSubmittedFingerprint = "";
if (window.kind === "view") { if (window.kind === "view") {
window.gridCols = Math.floor(window.viewportWidth / window.cellWidth); window.gridCols = Math.floor(window.viewportWidth / window.cellWidth);
window.gridRows = Math.floor(window.viewportHeight / window.cellHeight); window.gridRows = Math.floor(window.viewportHeight / window.cellHeight);
@@ -531,7 +548,7 @@ function cancelPendingReconnects(): void {
} }
} }
function openWindow(windowId: string, surfaceId: string, title: string, viewport: { width: number; height: number }): void { function openWindow(windowId: string, surfaceId: string, title: string, viewport: Viewport): void {
const pendingView = pendingViews.get(windowId); const pendingView = pendingViews.get(windowId);
if (pendingView) { if (pendingView) {
pendingViews.delete(windowId); pendingViews.delete(windowId);
@@ -548,6 +565,8 @@ function openWindow(windowId: string, surfaceId: string, title: string, viewport
title, title,
viewportWidth: viewport.width, viewportWidth: viewport.width,
viewportHeight: viewport.height, viewportHeight: viewport.height,
edges: viewport.edges,
padding: viewport.padding,
gridCols: Math.floor(viewport.width / hubCell.cellWidth), gridCols: Math.floor(viewport.width / hubCell.cellWidth),
gridRows: Math.floor(viewport.height / hubCell.cellHeight), gridRows: Math.floor(viewport.height / hubCell.cellHeight),
foreground: false, foreground: false,
@@ -914,7 +933,7 @@ function createViewWindow(
windowId: string, windowId: string,
surfaceId: string, surfaceId: string,
title: string, title: string,
viewport: { width: number; height: number }, viewport: Viewport,
view: PendingView, view: PendingView,
): ViewWindow { ): ViewWindow {
const { connectionId, socket, label, glyph } = view; const { connectionId, socket, label, glyph } = view;
@@ -933,6 +952,8 @@ function createViewWindow(
title, title,
viewportWidth: viewport.width, viewportWidth: viewport.width,
viewportHeight: viewport.height, viewportHeight: viewport.height,
edges: viewport.edges,
padding: viewport.padding,
gridCols, gridCols,
gridRows, gridRows,
font: cell.font, font: cell.font,
@@ -1067,7 +1088,7 @@ function windowMenu(window: TerminalWindow): WindowMenu {
post, post,
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window), items: () => windowMenuItems(window),
size: { width: window.viewportWidth, height: window.viewportHeight }, size: { width: window.viewportWidth, height: window.viewportHeight, edges: window.edges, padding: window.padding },
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
}); });
@@ -1308,12 +1329,20 @@ type HubItem = {
/** Vertical offset of a row's text line from the top of its selection box. */ /** Vertical offset of a row's text line from the top of its selection box. */
const HUB_ROW_TEXT_INSET = 4; const HUB_ROW_TEXT_INSET = 4;
/** Left edge of the list's selection boxes. */ /** How far the first selection box starts above the list's first text line. */
const HUB_LIST_LEFT = 12; const HUB_LIST_LEAD = 2;
/** Right inset of the selection boxes, clear of the scrollbar. */ /** The list's scrollbar (Menu.drawScrollbar's bar), and the gap the selection boxes keep from it. */
const HUB_LIST_RIGHT = 20; const HUB_SCROLLBAR_WIDTH = 3;
/** Left padding of unindented (heading and top-level) row text inside its selection box. */ const HUB_SCROLLBAR_GAP = 10;
const HUB_TOP_LEVEL_TEXT_X = 6; /** How far the scrollbar's track stops short of the rows' span at each end. */
const HUB_SCROLLBAR_INSET = 2;
/**
* Left padding of unindented (heading and top-level) row text inside its
* selection box; the hub's title starts in the same column.
*/
const HUB_TOP_LEVEL_TEXT_X = HUB_TITLE_INSET_X;
/** A page of text's body, indented under its title. */
const PAGE_BODY_INDENT = 6;
/** The hub window's list, created on first use so openWindow stays free of paint dependencies. */ /** The hub window's list, created on first use so openWindow stays free of paint dependencies. */
function hubMenu(window: HubWindow): Menu<HubItem> { function hubMenu(window: HubWindow): Menu<HubItem> {
@@ -1725,6 +1754,8 @@ function returnToHub(view: ViewWindow, then?: () => void): void {
if (activeViewId === view.windowId) activeViewId = null; if (activeViewId === view.windowId) activeViewId = null;
hub.viewportWidth = viewport.width; hub.viewportWidth = viewport.width;
hub.viewportHeight = viewport.height; hub.viewportHeight = viewport.height;
hub.edges = viewport.edges;
hub.padding = viewport.padding;
hub.menu?.resize(viewport); hub.menu?.resize(viewport);
const items = hubItems(hub); const items = hubItems(hub);
const row = items.findIndex( const row = items.findIndex(
@@ -1833,54 +1864,71 @@ function paintHub(window: HubWindow): GrayImage {
if (window.mode === "add") { if (window.mode === "add") {
return paintAddConnection(window); return paintAddConnection(window);
} }
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0); const { viewportWidth: width, viewportHeight: height, padding } = window;
const image = new GrayImage(width, height, 0);
const font = chromeFont(); const font = chromeFont();
const step = lineStep(font); const step = lineStep(font);
// No border box: the shell chrome (top bar + sidebar) already frames the app. // The header stays put inside the window's top padding, its title in line
// Long statuses get a wrapped block and move the list below it. // with the rows' text. Long statuses get a wrapped block and move the list
// below it.
const title = window.mode === "connections" ? "Terminal - Connections" : "Terminal"; const title = window.mode === "connections" ? "Terminal - Connections" : "Terminal";
image.drawText(font, HUB_TITLE_X, 10, title, 220); const header = layoutHubHeader(font, title, hubStatusLine(window), { width, padding }, step);
const header = layoutHubHeader(font, title, hubStatusLine(window), window.viewportWidth, step); image.drawText(font, header.titleX, header.titleY, title, 220);
header.lines.forEach((line, index) => image.drawText(font, header.x, header.y + index * step, line, 170)); header.lines.forEach((line, index) => image.drawText(font, header.x, header.y + index * step, line, 170));
let listTop = header.listTop; let listTop = header.listTop;
if (window.mode === "sessions" && controls.size === 0) { if (window.mode === "sessions" && controls.size === 0) {
image.drawText(font, HUB_TITLE_X + 6, listTop, "Add a g2mirror:// connection to get started, see:", 150); image.drawText(font, header.titleX, listTop, "Add a g2mirror:// connection to get started, see:", 150);
image.drawText(font, HUB_TITLE_X + 6, listTop + step, "https://github.com/jimrandomh/g2mirror", 190); image.drawText(font, header.titleX, listTop + step, "https://github.com/jimrandomh/g2mirror", 190);
listTop += 2 * step + 6; listTop += 2 * step + 6;
} }
const list = hubMenu(window); const list = hubMenu(window);
list.setItems(hubItems(window)); list.setItems(hubItems(window));
// Selection boxes start above the text line; the menu fills the selected // Selection boxes start at the left padding, above the text line; the menu
// box only while this window has focus (an outline alone means the sidebar // fills the selected box only while this window has focus (an outline alone
// owns input), matching the shell convention. // means the sidebar owns input), matching the shell convention. The list
const listHeight = window.viewportHeight - 6 - listTop; // scrolls, so under the header it runs to the window's bottom edge with
// that edge's padding inside it, after the last row: rows scrolled past the
// end are cut off at the edge itself. The scrollbar hugs the right padding.
const boxTop = listTop - HUB_LIST_LEAD;
const scrollbarX = width - padding.right - HUB_SCROLLBAR_WIDTH;
list.paint( list.paint(
image, image,
{ x: HUB_LIST_LEFT, y: listTop - 2, width: window.viewportWidth - HUB_LIST_LEFT - HUB_LIST_RIGHT, height: listHeight }, {
x: padding.left,
y: boxTop,
width: Math.max(0, scrollbarX - HUB_SCROLLBAR_GAP - padding.left),
height: Math.max(0, height - boxTop),
padBottom: padding.bottom,
},
window.focused, window.focused,
); );
list.drawScrollbar(image, window.viewportWidth - 10, listTop, listHeight - 4); const trackTop = boxTop + HUB_SCROLLBAR_INSET;
list.drawScrollbar(image, scrollbarX, trackTop, Math.max(0, height - padding.bottom - HUB_SCROLLBAR_INSET - trackTop));
return image; return image;
} }
function paintAddConnection(window: HubWindow): GrayImage { function paintAddConnection(window: HubWindow): GrayImage {
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0); const { viewportWidth: width, viewportHeight: height, padding } = window;
const image = new GrayImage(width, height, 0);
const font = chromeFont(); const font = chromeFont();
const step = lineStep(font); const step = lineStep(font);
image.drawText(font, 18, 10, "Add connection", 220); // A page of text: its title sits at the window's top and left padding, the
const instructionsY = 20 + step; // body indented under it, and the hint line on the bottom padding.
image.drawText(font, 24, instructionsY, "Type the g2mirror://token@host string in the", 170); image.drawText(font, padding.left, padding.top, "Add connection", 220);
image.drawText(font, 24, instructionsY + step, "phone app (or use voice input from the menu).", 170); const bodyX = padding.left + PAGE_BODY_INDENT;
const instructionsY = padding.top + 10 + step;
image.drawText(font, bodyX, instructionsY, "Type the g2mirror://token@host string in the", 170);
image.drawText(font, bodyX, instructionsY + step, "phone app (or use voice input from the menu).", 170);
const draftY = instructionsY + 3 * step; const draftY = instructionsY + 3 * step;
const draft = terminalNewConnectionSetting.get(); const draft = terminalNewConnectionSetting.get();
image.drawText(font, 24, draftY, truncateLabel(draft || "(empty)", 52), 220); image.drawText(font, bodyX, draftY, truncateLabel(draft || "(empty)", 52), 220);
if (window.addError) { if (window.addError) {
image.drawText(font, 24, draftY + step + 6, window.addError, 150); image.drawText(font, bodyX, draftY + step + 6, window.addError, 150);
} }
image.drawText(font, 24, window.viewportHeight - font.lineHeight - 12, `click save ${GESTURE_DOUBLE_CLICK} cancel`, 110); image.drawText(font, bodyX, height - padding.bottom - font.lineHeight, `click save ${GESTURE_DOUBLE_CLICK} cancel`, 110);
return image; return image;
} }
+100 -43
View File
@@ -40,6 +40,7 @@ import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics"; import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics";
import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window"; import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window";
import { shell, type TrayWidget } from "../../ui/shell/shell"; import { shell, type TrayWidget } from "../../ui/shell/shell";
import type { Viewport } from "../../ui/viewport";
import { WindowMenuLayer } from "../../ui/window-menu"; import { WindowMenuLayer } from "../../ui/window-menu";
import { clamp } from "../../util/numeric-util"; import { clamp } from "../../util/numeric-util";
import { import {
@@ -85,16 +86,27 @@ import {
export const TIMER_WINDOW_ID = "timer"; export const TIMER_WINDOW_ID = "timer";
export const TIMER_SURFACE_ID = "window:timer"; export const TIMER_SURFACE_ID = "window:timer";
/** Width of the list column, as a share of the viewport, and its bounds. */ /**
* Width of the list column (its rows and the scrollbar's gutter), as a share
* of the viewport's width inside its side padding, and its bounds.
*/
const LIST_SHARE = 0.4; const LIST_SHARE = 0.4;
const LIST_MIN_WIDTH = 190; const LIST_MIN_WIDTH = 190;
const LIST_MAX_WIDTH = 240; const LIST_MAX_WIDTH = 240;
const LIST_TOP = 6;
/** Pixels between consecutive list rows' selection boxes. */ /** Pixels between consecutive list rows' selection boxes. */
const LIST_ROW_GAP = 1; const LIST_ROW_GAP = 1;
const STAGE_X = 10; /**
* Room the list column keeps right of its rows for the scrollbar, which
* hugs the column's right edge: the gap before it, and its own 3 columns.
*/
const LIST_SCROLLBAR_GAP = 5;
const LIST_SCROLLBAR_GUTTER = LIST_SCROLLBAR_GAP + 3;
/** Gap between the list's divider and its rows. */
const LIST_DIVIDER_GAP = 7;
/** Gap between the stage's right edge and the list's divider. */ /** Gap between the stage's right edge and the list's divider. */
const STAGE_LIST_GAP = 14; const STAGE_LIST_GAP = 18;
/** How far the stage's small-font content is indented from its title, and ends short of the stage's right edge. */
const STAGE_BODY_INSET = 2;
/** Brightness factor for the list while a picker owns the stage. */ /** Brightness factor for the list while a picker owns the stage. */
const LIST_DIM = 0.4; const LIST_DIM = 0.4;
/** Big-digit sizes tried largest first until the text fits the stage. */ /** Big-digit sizes tried largest first until the text fits the stage. */
@@ -198,8 +210,8 @@ export class TimersLayer implements Layer {
isSelectable: (row) => row.kind !== "header", isSelectable: (row) => row.kind !== "header",
draw: (args) => this.drawListRow(args), draw: (args) => this.drawListRow(args),
}); });
/** Per-paint inputs to drawListRow. */ /** Per-paint inputs to drawListRow, and the padding the last paint put above the list's first row. */
private listPaint = { dim: 1, now: 0 }; private listPaint = { dim: 1, now: 0, padTop: 0 };
private mode: Mode = { kind: "list" }; private mode: Mode = { kind: "list" };
/** Which of the ringing stage's two buttons is highlighted. */ /** Which of the ringing stage's two buttons is highlighted. */
private ringButton = 0; private ringButton = 0;
@@ -247,7 +259,9 @@ export class TimersLayer implements Layer {
let index = rows.findIndex((row) => row.key === this.selectionKey); let index = rows.findIndex((row) => row.key === this.selectionKey);
if (index < 0) { if (index < 0) {
// The row went away (a dismissed timer, a deleted alarm): stay in place. // The row went away (a dismissed timer, a deleted alarm): stay in place.
const firstVisibleRow = Math.floor(this.list.scrollTop / listRowHeight(smallFont())); // Rows start below the list's top padding, which scrolls with them.
const rowsScrolled = Math.max(0, this.list.scrollTop - this.listPaint.padTop) / listRowHeight(smallFont());
const firstVisibleRow = Math.floor(rowsScrolled);
index = clamp(firstVisibleRow, 0, rows.length - 1); index = clamp(firstVisibleRow, 0, rows.length - 1);
while (index < rows.length && rows[index]!.kind === "header") index++; while (index < rows.length && rows[index]!.kind === "header") index++;
if (index >= rows.length) index = rows.findIndex((row) => row.kind !== "header"); if (index >= rows.length) index = rows.findIndex((row) => row.kind !== "header");
@@ -579,9 +593,7 @@ export class TimersLayer implements Layer {
/** A mirror touch: on the list, select the row under it. */ /** A mirror touch: on the list, select the row under it. */
hitTest(x: number, y: number, ctx: LayerContext): boolean { hitTest(x: number, y: number, ctx: LayerContext): boolean {
if (this.mode.kind !== "list") return false; if (this.mode.kind !== "list") return false;
const { width } = ctx.stack.getBaseSize(); if (x < columnsFor(ctx.stack.getBaseSize()).listX) return false;
const listX = width - listWidthFor(width);
if (x < listX) return false;
const rows = this.buildRows(Date.now()); const rows = this.buildRows(Date.now());
this.syncList(rows); this.syncList(rows);
const index = this.list.indexAt(y); const index = this.list.indexAt(y);
@@ -874,18 +886,17 @@ export class TimersLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
timerEngine.check(); timerEngine.check();
const now = Date.now(); const now = Date.now();
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const { width, height, padding } = viewport;
const image = new GrayImage(width, height, 0); const image = new GrayImage(width, height, 0);
const rows = this.buildRows(now); const rows = this.buildRows(now);
const selectedIndex = this.reconcileSelection(rows); const selectedIndex = this.reconcileSelection(rows);
const listWidth = listWidthFor(width); const { dividerX, stage } = columnsFor(viewport);
const listX = width - listWidth;
const picking = this.mode.kind !== "list"; const picking = this.mode.kind !== "list";
this.paintList(image, rows, selectedIndex, listX, listWidth, height, ctx.stack.isFocused(), picking ? LIST_DIM : 1, now); this.paintList(image, rows, selectedIndex, viewport, ctx.stack.isFocused(), picking ? LIST_DIM : 1, now);
image.drawLine(listX - 7, 8, listX - 7, height - 8, picking ? 20 : 40); image.drawLine(dividerX, padding.top, dividerX, height - padding.bottom, picking ? 20 : 40);
const stage = { x: STAGE_X, y: 0, width: listX - 7 - STAGE_LIST_GAP - STAGE_X, height };
switch (this.mode.kind) { switch (this.mode.kind) {
case "dial": case "dial":
this.paintDial(image, stage, this.mode, now); this.paintDial(image, stage, this.mode, now);
@@ -906,21 +917,23 @@ export class TimersLayer implements Layer {
image: GrayImage, image: GrayImage,
rows: Row[], rows: Row[],
selectedIndex: number, selectedIndex: number,
listX: number, viewport: Viewport,
listWidth: number,
height: number,
focused: boolean, focused: boolean,
dim: number, dim: number,
now: number, now: number,
): void { ): void {
const rowHeight = listRowHeight(smallFont()); const { height, padding } = viewport;
const visible = Math.max(1, Math.floor((height - 2 * LIST_TOP) / rowHeight)); const { listX, rowsWidth, scrollbarX } = columnsFor(viewport);
this.listPaint = { dim, now }; this.listPaint = { dim, now, padTop: padding.top };
// While a picker owns the stage the list has no live selection, so no // While a picker owns the stage the list has no live selection, so no
// highlight; drawListRow still brightens the selected row by key. // highlight; drawListRow still brightens the selected row by key.
this.list.setItems(rows, dim === 1 ? selectedIndex : null); this.list.setItems(rows, dim === 1 ? selectedIndex : null);
this.list.paint(image, { x: listX, y: LIST_TOP, width: listWidth - 12, height: visible * rowHeight - LIST_ROW_GAP }, focused); // The list scrolls, so it runs to the window's top and bottom edges,
this.list.drawScrollbar(image, listX + listWidth - 7, LIST_TOP, visible * rowHeight - 4); // with the padding suggested for them inside it (before the first row,
// after the last): rows scrolled past an end are cut off at the edge.
// The scrollbar stays put, so it keeps inside that padding.
this.list.paint(image, { x: listX, y: 0, width: rowsWidth, height, padTop: padding.top, padBottom: padding.bottom }, focused);
this.list.drawScrollbar(image, scrollbarX, padding.top, Math.max(0, height - padding.top - padding.bottom));
} }
private drawListRow({ image, item: row, x, y, width, height }: MenuDrawArgs<Row>): void { private drawListRow({ image, item: row, x, y, width, height }: MenuDrawArgs<Row>): void {
@@ -1137,7 +1150,13 @@ export class TimersLayer implements Layer {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Stage layout helpers // Stage layout helpers
type StageRect = { x: number; y: number; width: number; height: number }; /**
* The stage's box: its title's left edge and top, and the bottom of its
* hints. `centerX` is what its centred content (the big digits, the picker
* fields) centres on: the middle of the stage's column, from the window's
* left edge to the divider, whatever padding the box keeps inside that.
*/
type StageRect = { x: number; y: number; width: number; height: number; centerX: number };
/** /**
* Lays the stage out top to bottom: a title line, the big digits, then * Lays the stage out top to bottom: a title line, the big digits, then
@@ -1149,13 +1168,28 @@ class StageBlock {
private readonly hintsTop: number; private readonly hintsTop: number;
constructor(private readonly rect: StageRect) { constructor(private readonly rect: StageRect) {
this.cursorY = rect.y + 12; this.cursorY = rect.y;
this.hintsTop = rect.y + rect.height - 10 - lineStep(smallFont()); this.hintsTop = rect.y + rect.height - smallFont().lineHeight;
}
/** The stage's small-font content: its left edge and width. */
private get bodyX(): number {
return this.rect.x + STAGE_BODY_INSET;
}
private get bodyWidth(): number {
return this.rect.width - 2 * STAGE_BODY_INSET;
}
/** Where content `width` wide sits to be centred on the stage's column, kept inside the stage. */
private centeredX(width: number): number {
const { x, width: stageWidth, centerX } = this.rect;
return clamp(Math.floor(centerX - width / 2), x, Math.max(x, x + stageWidth - width));
} }
title(image: GrayImage, text: string, value: number): void { title(image: GrayImage, text: string, value: number): void {
const font = mediumFont(); const font = mediumFont();
image.drawText(font, this.rect.x + 4, this.cursorY, truncateText(font, text, this.rect.width - 8), value); image.drawText(font, this.rect.x, this.cursorY, truncateText(font, text, this.rect.width), value);
this.cursorY += font.lineHeight + 10; this.cursorY += font.lineHeight + 10;
} }
@@ -1163,9 +1197,9 @@ class StageBlock {
digits(image: GrayImage, text: string, value: number, suffix = ""): void { digits(image: GrayImage, text: string, value: number, suffix = ""): void {
const suffixFont = mediumFont(); const suffixFont = mediumFont();
const suffixWidth = suffix ? suffixFont.measureText(suffix) + 10 : 0; const suffixWidth = suffix ? suffixFont.measureText(suffix) + 10 : 0;
const font = fittingDigitFont(text, this.rect.width - 8 - suffixWidth); const font = fittingDigitFont(text, this.rect.width - suffixWidth);
const textWidth = font.measureText(text); const textWidth = font.measureText(text);
const x = this.rect.x + Math.max(0, Math.floor((this.rect.width - textWidth - suffixWidth) / 2)); const x = this.centeredX(textWidth + suffixWidth);
image.drawText(font, x, this.cursorY, text, value); image.drawText(font, x, this.cursorY, text, value);
if (suffix) { if (suffix) {
image.drawText(suffixFont, x + textWidth + 10, this.cursorY + font.ascent - suffixFont.ascent, suffix, Math.round(value * 0.8)); image.drawText(suffixFont, x + textWidth + 10, this.cursorY + font.ascent - suffixFont.ascent, suffix, Math.round(value * 0.8));
@@ -1174,8 +1208,8 @@ class StageBlock {
} }
progress(image: GrayImage, fraction: number, value: number): void { progress(image: GrayImage, fraction: number, value: number): void {
const x = this.rect.x + 6; const x = this.bodyX;
const width = this.rect.width - 12; const width = this.bodyWidth;
image.fillRoundedRect(x, this.cursorY, width, 6, 40, 3); image.fillRoundedRect(x, this.cursorY, width, 6, 40, 3);
const filled = Math.round(width * clamp(fraction, 0, 1)); const filled = Math.round(width * clamp(fraction, 0, 1));
if (filled > 0) image.fillRoundedRect(x, this.cursorY, Math.max(6, filled), 6, value, 3); if (filled > 0) image.fillRoundedRect(x, this.cursorY, Math.max(6, filled), 6, value, 3);
@@ -1185,7 +1219,7 @@ class StageBlock {
line(image: GrayImage, text: string, value: number): void { line(image: GrayImage, text: string, value: number): void {
if (!text) return; if (!text) return;
const font = smallFont(); const font = smallFont();
image.drawText(font, this.rect.x + 6, this.cursorY, truncateText(font, text, this.rect.width - 12), value); image.drawText(font, this.bodyX, this.cursorY, truncateText(font, text, this.bodyWidth), value);
this.cursorY += lineStep(font); this.cursorY += lineStep(font);
} }
@@ -1197,8 +1231,8 @@ class StageBlock {
/** A three-column row (lap table). */ /** A three-column row (lap table). */
columns(image: GrayImage, font: UiFont, cells: string[], value: number): void { columns(image: GrayImage, font: UiFont, cells: string[], value: number): void {
if (this.cursorY + font.lineHeight > this.hintsTop - 4) return; if (this.cursorY + font.lineHeight > this.hintsTop - 4) return;
const x = this.rect.x + 6; const x = this.bodyX;
const width = this.rect.width - 12; const width = this.bodyWidth;
const columnWidth = Math.floor(width / cells.length); const columnWidth = Math.floor(width / cells.length);
for (let index = 0; index < cells.length; index++) { for (let index = 0; index < cells.length; index++) {
const text = cells[index]!; const text = cells[index]!;
@@ -1215,8 +1249,8 @@ class StageBlock {
this.line(image, "Once", Math.round(value * 0.7)); this.line(image, "Once", Math.round(value * 0.7));
return; return;
} }
const step = Math.min(26, Math.floor((this.rect.width - 12) / 7)); const step = Math.min(26, Math.floor(this.bodyWidth / 7));
const x = this.rect.x + 6; const x = this.bodyX;
for (let index = 0; index < 7; index++) { for (let index = 0; index < 7; index++) {
const on = (mask & DAY_BITS[index]!) !== 0; const on = (mask & DAY_BITS[index]!) !== 0;
const letter = DAY_LETTERS[index]!; const letter = DAY_LETTERS[index]!;
@@ -1236,7 +1270,7 @@ class StageBlock {
const widths = values.map((value) => font.measureText(value) + 2 * padX); const widths = values.map((value) => font.measureText(value) + 2 * padX);
const sepWidths = separators.map((separator) => (separator ? sepFont.measureText(separator) + 8 : 6)); const sepWidths = separators.map((separator) => (separator ? sepFont.measureText(separator) + 8 : 6));
const total = widths.reduce((sum, width) => sum + width, 0) + sepWidths.reduce((sum, width) => sum + width, 0); const total = widths.reduce((sum, width) => sum + width, 0) + sepWidths.reduce((sum, width) => sum + width, 0);
let x = this.rect.x + Math.max(0, Math.floor((this.rect.width - total) / 2)); let x = this.centeredX(total);
const boxHeight = font.lineHeight + 4; const boxHeight = font.lineHeight + 4;
for (let index = 0; index < values.length; index++) { for (let index = 0; index < values.length; index++) {
const width = widths[index]!; const width = widths[index]!;
@@ -1267,10 +1301,10 @@ class StageBlock {
const font = smallFont(); const font = smallFont();
const gap = 12; const gap = 12;
const height = font.lineHeight + 14; const height = font.lineHeight + 14;
const width = Math.floor((this.rect.width - 12 - gap * (labels.length - 1)) / labels.length); const width = Math.floor((this.bodyWidth - gap * (labels.length - 1)) / labels.length);
const y = Math.max(this.cursorY + 4, this.hintsTop - 10 - height); const y = Math.max(this.cursorY + 4, this.hintsTop - 10 - height);
for (let index = 0; index < labels.length; index++) { for (let index = 0; index < labels.length; index++) {
const x = this.rect.x + 6 + index * (width + gap); const x = this.bodyX + index * (width + gap);
const active = index === selected; const active = index === selected;
if (active) { if (active) {
image.fillRoundedRect(x, y, width, height, focused ? 40 : 15, 8); image.fillRoundedRect(x, y, width, height, focused ? 40 : 15, 8);
@@ -1285,12 +1319,35 @@ class StageBlock {
} }
hints(image: GrayImage, pairs: Array<[string, string]>): void { hints(image: GrayImage, pairs: Array<[string, string]>): void {
image.drawText(smallFont(), this.rect.x + 6, this.hintsTop, gestureHints(pairs), 110); image.drawText(smallFont(), this.bodyX, this.hintsTop, gestureHints(pairs), 110);
} }
} }
function listWidthFor(viewportWidth: number): number { /**
return clamp(Math.round(viewportWidth * LIST_SHARE), LIST_MIN_WIDTH, LIST_MAX_WIDTH); * The screen's columns in a viewport. Fixed content keeps the padding
* suggested for the window's edges: the stage's box sits inside it on the
* left, top and bottom, and the list column (rows, then the scrollbar's
* gutter) ends at it on the right. The divider stands between the two.
*/
function columnsFor(viewport: Viewport): { listX: number; rowsWidth: number; scrollbarX: number; dividerX: number; stage: StageRect } {
const { width, height, padding } = viewport;
const listRight = width - padding.right;
const listWidth = clamp(Math.round((listRight - padding.left) * LIST_SHARE), LIST_MIN_WIDTH, LIST_MAX_WIDTH);
const listX = listRight - listWidth;
const dividerX = listX - LIST_DIVIDER_GAP;
return {
listX,
rowsWidth: listWidth - LIST_SCROLLBAR_GUTTER,
scrollbarX: listRight - LIST_SCROLLBAR_GUTTER + LIST_SCROLLBAR_GAP,
dividerX,
stage: {
x: padding.left,
y: padding.top,
width: Math.max(0, dividerX - STAGE_LIST_GAP - padding.left),
height: Math.max(0, height - padding.top - padding.bottom),
centerX: dividerX / 2,
},
};
} }
function drawPauseMark(image: GrayImage, x: number, y: number, value: number): void { function drawPauseMark(image: GrayImage, x: number, y: number, value: number): void {
+28 -10
View File
@@ -1,4 +1,7 @@
import { imageFromAsciiArt } from "../../graphics/image"; import { imageFromAsciiArt, type GrayImage } from "../../graphics/image";
import { voiceControlBridge } from "../../native/voice-control";
import { saveRecordingSetting, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import { withRecordingIcon } from "../../ui/listening-header";
import { TranscribeLayer, transcriptTimestamp } from "./transcribe"; import { TranscribeLayer, transcriptTimestamp } from "./transcribe";
import { import {
createInProcessWindow, createInProcessWindow,
@@ -13,8 +16,8 @@ export const TRANSCRIBE_SURFACE_ID = "window:transcribe";
const TRAY_ICON_ID = "transcribe"; const TRAY_ICON_ID = "transcribe";
// 16x18 microphone glyph for the top-bar tray (also Translate's). // 14x15 microphone glyph for the top-bar tray (also Translate's).
export const MIC_ICON = imageFromAsciiArt( const MIC_ICON = imageFromAsciiArt(
[ [
" #### ", " #### ",
" ###### ", " ###### ",
@@ -34,6 +37,12 @@ export const MIC_ICON = imageFromAsciiArt(
], ],
{ "#": 220 }, { "#": 220 },
); );
const MIC_RECORDING_ICON = withRecordingIcon(MIC_ICON);
/** The listening apps' tray icon: a microphone, with the recording circle while their audio is saved. */
export function micTrayIcon(recording: boolean): GrayImage {
return recording ? MIC_RECORDING_ICON : MIC_ICON;
}
export type TranscribeAppOptions = InProcessAppOptions & { export type TranscribeAppOptions = InProcessAppOptions & {
/** Begin continuous mic capture (kept on while the window is open). */ /** Begin continuous mic capture (kept on while the window is open). */
@@ -59,18 +68,23 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc
closeable: true, closeable: true,
actions: options.actions, actions: options.actions,
baseLayer: new YieldAtRootLayer(layer), baseLayer: new YieldAtRootLayer(layer),
menuItems: () => [{ menuItems: () => [
label: "Save", {
onSelect: (ctx) => { label: "Save",
ctx.stack.pop(); onSelect: (ctx) => {
layer.saveTranscript(); ctx.stack.pop();
layer.saveTranscript();
},
}, },
}], // The controller starts and stops the recording as the setting changes.
toggleSettingMenuItem(saveRecordingSetting),
],
submitFrame: options.submitFrame, submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible, setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface, removeSurface: options.removeSurface,
onClosed: () => { onClosed: () => {
layer.onRemoved(); layer.onRemoved();
unsubscribeRecording();
options.stopContinuousVoiceCapture(); options.stopContinuousVoiceCapture();
shell.setTrayIcon(TRAY_ICON_ID, null); shell.setTrayIcon(TRAY_ICON_ID, null);
options.onClosed(); options.onClosed();
@@ -79,7 +93,11 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc
// Wire async state changes to this window's renderer, rather than the // Wire async state changes to this window's renderer, rather than the
// controller action from which the window-specific actions were derived. // controller action from which the window-specific actions were derived.
layer.start(app.requestRender, () => shell.isWindowVisible(TRANSCRIBE_WINDOW_ID)); layer.start(app.requestRender, () => shell.isWindowVisible(TRANSCRIBE_WINDOW_ID));
const unsubscribeRecording = voiceControlBridge.onRecordingChange(() => {
shell.setTrayIcon(TRAY_ICON_ID, micTrayIcon(voiceControlBridge.recording));
app.requestRender();
});
options.startContinuousVoiceCapture({ recordAs: `transcribe-${stamp}` }); options.startContinuousVoiceCapture({ recordAs: `transcribe-${stamp}` });
shell.setTrayIcon(TRAY_ICON_ID, MIC_ICON); shell.setTrayIcon(TRAY_ICON_ID, micTrayIcon(voiceControlBridge.recording));
return app; return app;
} }
+22 -17
View File
@@ -1,12 +1,12 @@
import { GrayImage } from "../../graphics/image"; import { GrayImage } from "../../graphics/image";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { lineStep } from "../../ui/metrics"; import { lineStep } from "../../ui/metrics";
import { MicLevelMeter, paintListeningHeader } from "../../ui/listening-header"; import { MicLevelMeter, paintListeningHeader, RECORDING_FAILED_NOTICE } from "../../ui/listening-header";
import { writeTextToDownloads } from "../../native/file-access"; import { writeTextToDownloads } from "../../native/file-access";
import { voiceControlBridge } from "../../native/voice-control"; import { voiceControlBridge } from "../../native/voice-control";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
import { type InputEvent } from "../../ui/gestures"; import { type InputEvent } from "../../ui/gestures";
import { TranscriptModel, TranscriptScroll, wrapTranscribeText } from "./transcript-model"; import { TranscriptModel, TranscriptScroll, transcriptLayout, wrapTranscribeText } from "./transcript-model";
/** /**
* Live transcription view. Continuous mic capture is owned by the app wrapper * Live transcription view. Continuous mic capture is owned by the app wrapper
@@ -47,26 +47,31 @@ export class TranscribeLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(viewport.width, viewport.height, 0);
const text = this.transcript.text || (this.listening ? "Listening..." : this.detail);
const wrapped = wrapTranscribeText((line) => font.measureText(line), text, width - 64);
const bodyTop = paintListeningHeader(image, font, "Transcribe", this.saveNotice || this.status, this.listening ? this.meter : null); const status = voiceControlBridge.recordingFailed ? RECORDING_FAILED_NOTICE : this.status;
const bodyTop = paintListeningHeader(
image, font, "Transcribe", this.saveNotice || status, this.listening ? this.meter : null, viewport.padding,
voiceControlBridge.recording,
);
const step = lineStep(font) + 2; const step = lineStep(font) + 2;
const bodyLines = Math.max(1, Math.floor((height - 6 - bodyTop - font.lineHeight) / step) + 1); const layout = transcriptLayout(viewport, bodyTop, font.lineHeight, step);
const firstLine = this.scroll.layout(wrapped.length, bodyLines); const text = this.transcript.text || (this.listening ? "Listening..." : this.detail);
for (let index = firstLine; index < Math.min(wrapped.length, firstLine + bodyLines); index++) { const wrapped = wrapTranscribeText((line) => font.measureText(line), text, layout.textWidth);
const firstLine = this.scroll.layout(wrapped.length, layout.pageLines);
for (let index = firstLine; index < Math.min(wrapped.length, firstLine + layout.drawnLines); index++) {
const y = bodyTop + (index - firstLine) * step; const y = bodyTop + (index - firstLine) * step;
image.drawText(font, 32, y, wrapped[index]!, 230); image.drawText(font, layout.textX, y, wrapped[index]!, 230);
} }
if (wrapped.length > bodyLines) { if (wrapped.length > layout.pageLines) {
const trackHeight = height - bodyTop - 6; const track = layout.scrollbar;
const thumbHeight = Math.max(8, Math.round(trackHeight * bodyLines / wrapped.length)); const thumbHeight = Math.max(8, Math.round(track.height * layout.pageLines / wrapped.length));
const thumbY = bodyTop + Math.round((trackHeight - thumbHeight) * firstLine / (wrapped.length - bodyLines)); const thumbY = track.y + Math.round((track.height - thumbHeight) * firstLine / (wrapped.length - layout.pageLines));
image.fillRect(width - 14, bodyTop, 2, trackHeight, 45); image.fillRect(track.x, track.y, track.width, track.height, 45);
image.fillRect(width - 14, thumbY, 2, thumbHeight, 140); image.fillRect(track.x, thumbY, track.width, thumbHeight, 140);
} }
return image; return image;
} }
+46
View File
@@ -1,3 +1,5 @@
import type { Viewport } from "../../ui/viewport";
type TranscriptEvent = { type TranscriptEvent = {
text: string; text: string;
isFinal: boolean; isFinal: boolean;
@@ -54,6 +56,50 @@ export class TranscriptScroll {
} }
} }
/** The scrollbar, and the room the transcript's lines leave for it at their right. */
const SCROLLBAR_WIDTH = 2;
const SCROLLBAR_GUTTER = 8;
export type TranscriptLayout = {
/** The text column: its left, and the width its lines wrap to. */
textX: number;
textWidth: number;
/** Lines the view scrolls by: as many as fit above the bottom padding. */
pageLines: number;
/** Lines to draw from the first one shown: as many as fit above the window's bottom edge. */
drawnLines: number;
/** The scrollbar's track, for a transcript longer than a page. */
scrollbar: { x: number; y: number; width: number; height: number };
};
/**
* Where a listening view (Transcribe, Translate) puts its transcript, under
* a fixed header that ends at `top`. The text column starts at the padding
* suggested for the window's left edge (viewport.ts), in line with the
* header's title, and stops short of the right edge's by the scrollbar's
* gutter; the scrollbar stands in that, against the padding. The lines
* scroll, so they run to the window's bottom edge: the view scrolls by the
* lines that fit above that edge's padding, which rests the transcript's
* last line clear of a border there, and while more lines follow it draws
* as many as fit above the edge itself.
*/
export function transcriptLayout(viewport: Viewport, top: number, lineHeight: number, step: number): TranscriptLayout {
const { width, height, padding } = viewport;
const linesAbove = (bottom: number) => Math.max(1, Math.floor((bottom - top - lineHeight) / step) + 1);
return {
textX: padding.left,
textWidth: Math.max(0, width - padding.left - padding.right - SCROLLBAR_GUTTER),
pageLines: linesAbove(height - padding.bottom),
drawnLines: linesAbove(height),
scrollbar: {
x: width - padding.right - SCROLLBAR_WIDTH,
y: top,
width: SCROLLBAR_WIDTH,
height: Math.max(0, height - padding.bottom - top),
},
};
}
export function wrapTranscribeText(measure: (text: string) => number, text: string, maxWidth: number): string[] { export function wrapTranscribeText(measure: (text: string) => number, text: string, maxWidth: number): string[] {
const lines: string[] = []; const lines: string[] = [];
for (const paragraph of text.split("\n")) { for (const paragraph of text.split("\n")) {
+31 -11
View File
@@ -4,14 +4,17 @@ import {
resolveTranslateLanguage, resolveTranslateLanguage,
resolveTranslateProvider, resolveTranslateProvider,
translateLanguageSetting, translateLanguageSetting,
translateModelSetting,
translateTargetLanguageSetting,
translateProviderSetting, translateProviderSetting,
translateShowOriginalSetting, translateShowOriginalSetting,
} from "./translate-settings"; } from "./translate-settings";
import { MIC_ICON } from "../transcribe/transcribe-app"; import { micTrayIcon } from "../transcribe/transcribe-app";
import { transcriptTimestamp } from "../transcribe/transcribe"; import { transcriptTimestamp } from "../transcribe/transcribe";
import { voiceControlBridge } from "../../native/voice-control";
import { type ContinuousCaptureOptions } from "../../ui/layers"; import { type ContinuousCaptureOptions } from "../../ui/layers";
import { openSettingsSubMenu } from "../../ui/dashboard/settings-panel"; import { openSettingsSubMenu } from "../../ui/dashboard/settings-panel";
import { enumSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings"; import { enumSettingMenuItem, saveRecordingSetting, textSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import { import {
createInProcessWindow, createInProcessWindow,
YieldAtRootLayer, YieldAtRootLayer,
@@ -28,8 +31,8 @@ const TRAY_ICON_ID = "translate";
const NO_PROVIDER_PROBLEM = const NO_PROVIDER_PROBLEM =
"Translate needs a transcription provider that understands any language: add an ElevenLabs, OpenAI, or Soniox API key (Settings > API Keys), or a Whisper server URL (Settings > Voice)."; "Translate needs a transcription provider that understands any language: add an ElevenLabs, OpenAI, or Soniox API key (Settings > API Keys), or a Whisper server URL (Settings > Voice).";
const NO_MODEL_PROBLEM = global.isIOS const NO_MODEL_PROBLEM = global.isIOS
? "Translate needs a language model: configure a cloud or OpenAI-compatible model in Settings > Assistant." ? "Translate needs a language model: set an OpenAI model in Translate settings and add its API key, or configure a cloud or OpenAI-compatible model in Settings > Assistant."
: "Translate needs a language model: configure one in Settings > Assistant, or download the on-phone model."; : "Translate needs a language model: set an OpenAI model in Translate settings and add its API key, or configure one in Settings > Assistant, or download the on-phone model.";
export type TranslateAppOptions = InProcessAppOptions & { export type TranslateAppOptions = InProcessAppOptions & {
/** Begin (or retarget) continuous mic capture, kept on while the window is open. */ /** Begin (or retarget) continuous mic capture, kept on while the window is open. */
@@ -38,12 +41,17 @@ export type TranslateAppOptions = InProcessAppOptions & {
}; };
/** /**
* The Translate app: live speech in any language, translated into English by * The Translate app: live speech in any language, translated into the selected output language by
* the assistant's model, in its own window. Like Transcribe it holds * the assistant's model, in its own window. Like Transcribe it holds
* continuous mic capture while open, but always with a multilingual cloud * continuous mic capture while open, but always with a multilingual cloud
* provider (Translate settings), which a shared capture switches to. * provider (Translate settings), which a shared capture switches to.
*/ */
export function createTranslateAppWindow(options: TranslateAppOptions): InProcessWindow { export function createTranslateAppWindow(options: TranslateAppOptions): InProcessWindow {
// One timestamp per session names both the audio recording and a saved transcript.
const stamp = transcriptTimestamp();
// Whether the mic tray icon is up (capture was asked for).
let trayIconShown = false;
const syncTrayIcon = () => shell.setTrayIcon(TRAY_ICON_ID, trayIconShown ? micTrayIcon(voiceControlBridge.recording) : null);
// Checks the setup and (re)starts capture with the chosen provider and // Checks the setup and (re)starts capture with the chosen provider and
// language: at launch, when either setting changes, and on a tap after a // language: at launch, when either setting changes, and on a tap after a
// problem. // problem.
@@ -51,15 +59,18 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
const provider = resolveTranslateProvider(); const provider = resolveTranslateProvider();
const problem = !provider ? NO_PROVIDER_PROBLEM : !resolveTranslationModel() ? NO_MODEL_PROBLEM : null; const problem = !provider ? NO_PROVIDER_PROBLEM : !resolveTranslationModel() ? NO_MODEL_PROBLEM : null;
layer.setProblem(problem); layer.setProblem(problem);
if (!provider || problem) { trayIconShown = Boolean(provider) && !problem;
if (provider && !problem) {
options.startContinuousVoiceCapture({
recordAs: `translate-${stamp}`,
transcription: { provider, language: resolveTranslateLanguage() },
});
} else {
options.stopContinuousVoiceCapture(); options.stopContinuousVoiceCapture();
shell.setTrayIcon(TRAY_ICON_ID, null);
return;
} }
options.startContinuousVoiceCapture({ transcription: { provider, language: resolveTranslateLanguage() } }); syncTrayIcon();
shell.setTrayIcon(TRAY_ICON_ID, MIC_ICON);
}; };
const layer = new TranslateLayer(transcriptTimestamp(), startCapture); const layer = new TranslateLayer(stamp, startCapture);
const app = createInProcessWindow({ const app = createInProcessWindow({
appId: "translate", appId: "translate",
windowId: TRANSLATE_WINDOW_ID, windowId: TRANSLATE_WINDOW_ID,
@@ -77,6 +88,8 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
layer.saveTranscript(); layer.saveTranscript();
}, },
}, },
// The controller starts and stops the recording as the setting changes.
toggleSettingMenuItem(saveRecordingSetting),
{ {
label: "Translate settings", label: "Translate settings",
onSelect: (ctx) => { onSelect: (ctx) => {
@@ -84,6 +97,8 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
openSettingsSubMenu(ctx, "Translate settings", [ openSettingsSubMenu(ctx, "Translate settings", [
enumSettingMenuItem(translateLanguageSetting, { onChange: startCapture }), enumSettingMenuItem(translateLanguageSetting, { onChange: startCapture }),
enumSettingMenuItem(translateProviderSetting, { onChange: startCapture }), enumSettingMenuItem(translateProviderSetting, { onChange: startCapture }),
enumSettingMenuItem(translateTargetLanguageSetting),
textSettingMenuItem(translateModelSetting),
toggleSettingMenuItem(translateShowOriginalSetting), toggleSettingMenuItem(translateShowOriginalSetting),
]); ]);
}, },
@@ -94,6 +109,7 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
removeSurface: options.removeSurface, removeSurface: options.removeSurface,
onClosed: () => { onClosed: () => {
layer.onRemoved(); layer.onRemoved();
unsubscribeRecording();
options.stopContinuousVoiceCapture(); options.stopContinuousVoiceCapture();
shell.setTrayIcon(TRAY_ICON_ID, null); shell.setTrayIcon(TRAY_ICON_ID, null);
options.onClosed(); options.onClosed();
@@ -102,6 +118,10 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
// Wire async state changes to this window's renderer, rather than the // Wire async state changes to this window's renderer, rather than the
// controller action from which the window-specific actions were derived. // controller action from which the window-specific actions were derived.
layer.start(app.requestRender, () => shell.isWindowVisible(TRANSLATE_WINDOW_ID)); layer.start(app.requestRender, () => shell.isWindowVisible(TRANSLATE_WINDOW_ID));
const unsubscribeRecording = voiceControlBridge.onRecordingChange(() => {
syncTrayIcon();
app.requestRender();
});
startCapture(); startCapture();
return app; return app;
} }
+14 -7
View File
@@ -1,6 +1,6 @@
/** /**
* Streamed translation against the assistant's configured model (Settings > * Streamed translation against Translate's OpenAI override, or the assistant's
* Assistant). Each call translates one stretch of speech into English; see * configured model when no override is set. Each call translates one stretch of speech into the selected output language; see
* TranslationModel for how stretches are batched and given context. * TranslationModel for how stretches are batched and given context.
*/ */
import { streamAnthropicMessage } from "../../native/anthropic"; import { streamAnthropicMessage } from "../../native/anthropic";
@@ -13,7 +13,8 @@ import {
anthropicApiKeySetting, assistantModelSetting, assistantOpenAiCompatibleKeySetting, anthropicApiKeySetting, assistantModelSetting, assistantOpenAiCompatibleKeySetting,
assistantOpenAiCompatibleModelSetting, assistantOpenAiCompatibleUrlSetting, openAiApiKeySetting, assistantOpenAiCompatibleModelSetting, assistantOpenAiCompatibleUrlSetting, openAiApiKeySetting,
} from "../../ui/dashboard-settings"; } from "../../ui/dashboard-settings";
import { TRANSLATE_SYSTEM_PROMPT, buildTranslateUserMessage } from "../../prompts"; import { buildTranslateSystemPrompt, buildTranslateUserMessage } from "../../prompts";
import { translateModelSetting, translateTargetLanguageSetting, spokenLanguageName } from "./translate-settings";
import { type TranslationTurn } from "./translation-model"; import { type TranslationTurn } from "./translation-model";
/** /**
@@ -23,6 +24,11 @@ import { type TranslationTurn } from "./translation-model";
* for whichever API key is set, else the on-phone model. * for whichever API key is set, else the on-phone model.
*/ */
export function resolveTranslationModel(): ResolvedAssistantModel | null { export function resolveTranslationModel(): ResolvedAssistantModel | null {
const translationModel = translateModelSetting.get().trim();
if (translationModel) {
const apiKey = openAiApiKeySetting.get().trim();
return apiKey ? { selection: "auto", provider: "openai", model: translationModel, apiKey } : null;
}
const selection = assistantModelSetting.get(); const selection = assistantModelSetting.get();
return resolveAssistantModel(selection === "hermes" ? "auto" : selection, { return resolveAssistantModel(selection === "hermes" ? "auto" : selection, {
anthropic: anthropicApiKeySetting.get(), anthropic: anthropicApiKeySetting.get(),
@@ -44,13 +50,14 @@ export type TranslationRequest = {
}; };
export function streamTranslation(model: ResolvedAssistantModel, request: TranslationRequest): LlmStreamHandle { export function streamTranslation(model: ResolvedAssistantModel, request: TranslationRequest): LlmStreamHandle {
const targetLanguage = spokenLanguageName(translateTargetLanguageSetting.get());
const options: LlmStreamOptions = { const options: LlmStreamOptions = {
apiKey: model.apiKey, apiKey: model.apiKey,
model: model.model, model: model.model,
system: TRANSLATE_SYSTEM_PROMPT, system: buildTranslateSystemPrompt(targetLanguage),
effort: model.effort, effort: model.effort,
maxTokens: 1024, maxTokens: 1024,
messages: [{ role: "user", content: buildTranslateUserMessage(request.speech, request.context, request.language) }], messages: [{ role: "user", content: buildTranslateUserMessage(request.speech, request.context, request.language, targetLanguage) }],
onTextDelta: (_delta, textSoFar) => request.onProgress(cleanTranslation(textSoFar)), onTextDelta: (_delta, textSoFar) => request.onProgress(cleanTranslation(textSoFar)),
onDone: (result) => { onDone: (result) => {
if (result.stopReason === "refusal") request.onError("The model declined to translate this."); if (result.stopReason === "refusal") request.onError("The model declined to translate this.");
@@ -70,7 +77,7 @@ export function streamTranslation(model: ResolvedAssistantModel, request: Transl
} }
} }
/** The context turns are tagged <english>; a model may echo the tag around its reply. */ /** The context turns are tagged <translation>; a model may echo the tag around its reply. */
function cleanTranslation(text: string): string { function cleanTranslation(text: string): string {
return text.replace(/^\s*<english>/i, "").replace(/<\/english>\s*$/i, "").trim(); return text.replace(/^\s*<(?:translation|english)>/i, "").replace(/<\/(?:translation|english)>\s*$/i, "").trim();
} }
+23 -1
View File
@@ -1,4 +1,4 @@
import { ConfigSettingBoolean, ConfigSettingEnum, voiceProviderSetting, type VoiceProvider } from "../../ui/dashboard-settings"; import { ConfigSettingBoolean, ConfigSettingEnum, ConfigSettingString, voiceProviderSetting, type VoiceProvider } from "../../ui/dashboard-settings";
/** /**
* The transcription providers that recognize any spoken language, in picker * The transcription providers that recognize any spoken language, in picker
@@ -52,6 +52,7 @@ export const translateProviderSetting = new ConfigSettingEnum<TranslateProvider>
* form every multilingual provider accepts), in picker order. * form every multilingual provider accepts), in picker order.
*/ */
const SPOKEN_LANGUAGES = { const SPOKEN_LANGUAGES = {
en: "English",
ar: "Arabic", ar: "Arabic",
zh: "Chinese", zh: "Chinese",
nl: "Dutch", nl: "Dutch",
@@ -106,3 +107,24 @@ export const translateShowOriginalSetting = new ConfigSettingBoolean({
defaultValue: false, defaultValue: false,
description: "Show what was said, dimmed, above each translation.", description: "Show what was said, dimmed, above each translation.",
}); });
/** Empty preserves the existing Assistant-based routing. */
export const translateModelSetting = new ConfigSettingString({
id: "translate-model",
label: "Translation model (OpenAI)",
storageKey: "translate.model",
defaultValue: "",
inputKind: "text",
normalize: (value) => value.trim(),
description: "OpenAI model ID used only by Translate, for example gpt-4o-mini. Uses the OpenAI key from Settings > API Keys. Leave empty to use the Assistant model. Changes apply to subsequent translation requests; Assistant settings are unchanged.",
});
export const translateTargetLanguageSetting = new ConfigSettingEnum<SpokenLanguage>({
id: "translate-target-language",
label: "Output language",
storageKey: "translate.targetLanguage",
defaultValue: "en",
values: Object.keys(SPOKEN_LANGUAGES) as SpokenLanguage[],
formatValue: (value) => SPOKEN_LANGUAGES[value],
description: "Language of subsequent translations. Independent of the spoken language and Assistant settings. Existing translations stay unchanged.",
});
+23 -19
View File
@@ -1,13 +1,13 @@
import { GrayImage } from "../../graphics/image"; import { GrayImage } from "../../graphics/image";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { lineStep } from "../../ui/metrics"; import { lineStep } from "../../ui/metrics";
import { MicLevelMeter, paintListeningHeader } from "../../ui/listening-header"; import { MicLevelMeter, paintListeningHeader, RECORDING_FAILED_NOTICE } from "../../ui/listening-header";
import { writeTextToDownloads } from "../../native/file-access"; import { writeTextToDownloads } from "../../native/file-access";
import { voiceControlBridge } from "../../native/voice-control"; import { voiceControlBridge } from "../../native/voice-control";
import { Layer, type LayerContext } from "../../ui/layers"; import { Layer, type LayerContext } from "../../ui/layers";
import { type InputEvent } from "../../ui/gestures"; import { type InputEvent } from "../../ui/gestures";
import { type LlmStreamHandle } from "../../assistant/llm-protocol"; import { type LlmStreamHandle } from "../../assistant/llm-protocol";
import { TranscriptScroll, wrapTranscribeText } from "../transcribe/transcript-model"; import { TranscriptScroll, transcriptLayout, wrapTranscribeText } from "../transcribe/transcript-model";
import { TranslationModel, type TranslationJob, type TranslationLine } from "./translation-model"; import { TranslationModel, type TranslationJob, type TranslationLine } from "./translation-model";
import { resolveTranslationModel, streamTranslation } from "./translate-llm"; import { resolveTranslationModel, streamTranslation } from "./translate-llm";
import { resolveTranslateLanguage, spokenLanguageName, translateShowOriginalSetting } from "./translate-settings"; import { resolveTranslateLanguage, spokenLanguageName, translateShowOriginalSetting } from "./translate-settings";
@@ -18,7 +18,7 @@ const NO_MODEL_NOTICE = "No language model is set up.";
* Live translation view. Continuous mic capture is owned by the app wrapper * Live translation view. Continuous mic capture is owned by the app wrapper
* (createTranslateAppWindow); this layer feeds speech to the assistant's * (createTranslateAppWindow); this layer feeds speech to the assistant's
* model one block at a time (provisionally while a block is still being * model one block at a time (provisionally while a block is still being
* spoken), shows the English as it streams in, and saves the session to * spoken), shows the translation as it streams in, and saves the session to
* Downloads from the app menu. * Downloads from the app menu.
*/ */
export class TranslateLayer implements Layer { export class TranslateLayer implements Layer {
@@ -72,14 +72,20 @@ export class TranslateLayer implements Layer {
paint(ctx: LayerContext): GrayImage { paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont(); const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize(); const viewport = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0); const image = new GrayImage(viewport.width, viewport.height, 0);
const measure = (line: string) => font.measureText(line); const measure = (line: string) => font.measureText(line);
const maxWidth = width - 64;
const status = this.problem ? "Setup needed" : this.translationError || this.status; const status = this.problem
? "Setup needed"
: voiceControlBridge.recordingFailed ? RECORDING_FAILED_NOTICE : this.translationError || this.status;
const meter = this.listening && !this.problem ? this.meter : null; const meter = this.listening && !this.problem ? this.meter : null;
const bodyTop = paintListeningHeader(image, font, "Translate", this.saveNotice || status, meter); const bodyTop = paintListeningHeader(
image, font, "Translate", this.saveNotice || status, meter, viewport.padding, voiceControlBridge.recording,
);
const step = lineStep(font) + 2;
const layout = transcriptLayout(viewport, bodyTop, font.lineHeight, step);
const maxWidth = layout.textWidth;
let lines: TranslationLine[]; let lines: TranslationLine[];
if (this.problem) { if (this.problem) {
@@ -92,20 +98,18 @@ export class TranslateLayer implements Layer {
} }
} }
const step = lineStep(font) + 2; const firstLine = this.scroll.layout(lines.length, layout.pageLines);
const bodyLines = Math.max(1, Math.floor((height - 6 - bodyTop - font.lineHeight) / step) + 1); for (let index = firstLine; index < Math.min(lines.length, firstLine + layout.drawnLines); index++) {
const firstLine = this.scroll.layout(lines.length, bodyLines);
for (let index = firstLine; index < Math.min(lines.length, firstLine + bodyLines); index++) {
const y = bodyTop + (index - firstLine) * step; const y = bodyTop + (index - firstLine) * step;
image.drawText(font, 32, y, lines[index]!.text, lines[index]!.gray); image.drawText(font, layout.textX, y, lines[index]!.text, lines[index]!.gray);
} }
if (lines.length > bodyLines) { if (lines.length > layout.pageLines) {
const trackHeight = height - bodyTop - 6; const track = layout.scrollbar;
const thumbHeight = Math.max(8, Math.round(trackHeight * bodyLines / lines.length)); const thumbHeight = Math.max(8, Math.round(track.height * layout.pageLines / lines.length));
const thumbY = bodyTop + Math.round((trackHeight - thumbHeight) * firstLine / (lines.length - bodyLines)); const thumbY = track.y + Math.round((track.height - thumbHeight) * firstLine / (lines.length - layout.pageLines));
image.fillRect(width - 14, bodyTop, 2, trackHeight, 45); image.fillRect(track.x, track.y, track.width, track.height, 45);
image.fillRect(width - 14, thumbY, 2, thumbHeight, 140); image.fillRect(track.x, thumbY, track.width, thumbHeight, 140);
} }
return image; return image;
} }
Loaded 100 of 284 files, more files were not shown because too many files have changed in this diff. Show more