forked from Blendman974/faceclaw
Adjust UI to account for user-configured variable font size
This commit is contained in:
1 parent
96842ceb23
commit
eef9fbaab4
25 files changed
+350
-222
No files matched your search
@@ -9,6 +9,7 @@ import {
|
||||
drawSubmenuIndicator,
|
||||
scrollToKeepSelectionVisible,
|
||||
} from "../../ui/menu";
|
||||
import { lineStep, tightRowHeight } from "../../ui/metrics";
|
||||
import {
|
||||
mediaBrowserBridge,
|
||||
type MediaBrowseItem,
|
||||
@@ -16,10 +17,11 @@ import {
|
||||
} from "../../native/media-browser";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
|
||||
const HEADER_HEIGHT = 34;
|
||||
const ROW_HEIGHT = 16;
|
||||
/** Header: title line + path line (34px at the 12px bitmap default). */
|
||||
function headerHeight(font: UiFont): number {
|
||||
return 8 + lineStep(font) + font.lineHeight;
|
||||
}
|
||||
const LIST_X = 20;
|
||||
const FOOTER_HEIGHT = 22;
|
||||
|
||||
export type MediaBrowseOptions = {
|
||||
app: MediaBrowserApp;
|
||||
@@ -67,49 +69,50 @@ export class MediaBrowseLayer implements Layer {
|
||||
image.drawText(font, 20, 8, `Library: ${this.options.app.appName}`, 220);
|
||||
|
||||
if (this.phase === "connecting" || this.phase === "idle") {
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 8, `Starting ${this.options.app.appName}...`, 150);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(font, 24, headerHeight(font) + 8, `Starting ${this.options.app.appName}...`, 150);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
if (this.phase === "failed") {
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 8, "Could not connect:", 180);
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 24, truncateRight(font, this.connectError, width - 48), 140);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} retry ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(font, 24, headerHeight(font) + 8, "Could not connect:", 180);
|
||||
image.drawText(font, 24, headerHeight(font) + 8 + lineStep(font), truncateRight(font, this.connectError, width - 48), 140);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_CLICK} retry ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
const level = this.currentLevel();
|
||||
const path = this.levels.map((entry) => entry.title).join(" / ");
|
||||
image.drawText(font, 20, 22, truncateLeft(font, path, width - 40), 130);
|
||||
image.drawText(font, 20, 8 + lineStep(font), truncateLeft(font, path, width - 40), 130);
|
||||
|
||||
if (!level || level.items === null) {
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 8, level?.error ? level.error : "Loading...", level?.error ? 140 : 150);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
image.drawText(font, 24, headerHeight(font) + 8, level?.error ? level.error : "Loading...", level?.error ? 140 : 150);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
const items = level.items;
|
||||
if (!items.length) {
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 8, "(empty)", 120);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
image.drawText(font, 24, headerHeight(font) + 8, "(empty)", 120);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
level.selectedIndex = clamp(level.selectedIndex, 0, items.length - 1);
|
||||
const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT;
|
||||
const visibleRows = Math.max(1, (listHeight / ROW_HEIGHT) | 0);
|
||||
const listHeight = height - headerHeight(font) - font.lineHeight - 10;
|
||||
const rowH = tightRowHeight(font);
|
||||
const visibleRows = Math.max(1, (listHeight / rowH) | 0);
|
||||
level.scrollRow = scrollToKeepSelectionVisible(level.scrollRow, level.selectedIndex, visibleRows, items.length);
|
||||
|
||||
const rowWidth = width - 2 * LIST_X;
|
||||
const lastVisible = Math.min(items.length, level.scrollRow + visibleRows);
|
||||
for (let index = level.scrollRow; index < lastVisible; index++) {
|
||||
const item = items[index]!;
|
||||
const y = HEADER_HEIGHT + (index - level.scrollRow) * ROW_HEIGHT;
|
||||
const y = headerHeight(font) + (index - level.scrollRow) * rowH;
|
||||
const selected = index === level.selectedIndex;
|
||||
const highlightX = LIST_X - 6;
|
||||
const highlightY = y - 1;
|
||||
const highlightWidth = rowWidth + 12;
|
||||
const highlightHeight = ROW_HEIGHT - 1;
|
||||
const highlightHeight = rowH - 1;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, highlightX, highlightY, highlightWidth, highlightHeight, ctx.stack.isFocused(), 4);
|
||||
}
|
||||
@@ -131,8 +134,8 @@ export class MediaBrowseLayer implements Layer {
|
||||
drawListScrollbar(
|
||||
image,
|
||||
width - 12,
|
||||
HEADER_HEIGHT,
|
||||
visibleRows * ROW_HEIGHT - 4,
|
||||
headerHeight(font),
|
||||
visibleRows * rowH - 4,
|
||||
level.scrollRow,
|
||||
visibleRows,
|
||||
items.length,
|
||||
|
||||
+17
-15
@@ -10,6 +10,7 @@ import {
|
||||
GESTURE_SCROLL_UP,
|
||||
} from "../../ui/gestures";
|
||||
import { MenuLayer, drawSelectionHighlight, drawSubmenuIndicator } from "../../ui/menu";
|
||||
import { lineStep, tightRowHeight } from "../../ui/metrics";
|
||||
import {
|
||||
mediaControllerBridge,
|
||||
type MediaControllerState,
|
||||
@@ -33,7 +34,6 @@ const ART_X = 22;
|
||||
const ART_Y = 8;
|
||||
const META_X = ART_X + ART_SIZE + 14;
|
||||
const LIST_TOP = 120;
|
||||
const ROW_HEIGHT = 16;
|
||||
const ACTION_X = 22;
|
||||
const ACTION_WIDTH = 154;
|
||||
const COLUMN_DIVIDER_X = 190;
|
||||
@@ -81,7 +81,7 @@ class MusicAppLayer implements Layer {
|
||||
width - 48,
|
||||
);
|
||||
for (let index = 0; index < lines.length; index++) {
|
||||
image.drawText(font, 24, 16 + index * 14, lines[index]!, 180);
|
||||
image.drawText(font, 24, 16 + index * lineStep(font), lines[index]!, 180);
|
||||
}
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open settings ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
@@ -90,11 +90,11 @@ class MusicAppLayer implements Layer {
|
||||
if (!media.available) {
|
||||
image.drawText(font, 24, 16, "No active media session.", 180);
|
||||
if (mediaBrowserBridge.listBrowsableApps().length) {
|
||||
image.drawText(font, 24, 34, "Click to browse a music app's library,", 150);
|
||||
image.drawText(font, 24, 48, "or start playback on the phone.", 150);
|
||||
image.drawText(font, 24, 22 + lineStep(font), "Click to browse a music app's library,", 150);
|
||||
image.drawText(font, 24, 22 + 2 * lineStep(font), "or start playback on the phone.", 150);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} browse ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
} else {
|
||||
image.drawText(font, 24, 34, "Start playback in another app on the phone.", 150);
|
||||
image.drawText(font, 24, 22 + lineStep(font), "Start playback in another app on the phone.", 150);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
}
|
||||
return image;
|
||||
@@ -103,22 +103,24 @@ class MusicAppLayer implements Layer {
|
||||
this.drawArt(image, media);
|
||||
|
||||
const metaWidth = width - META_X - 24;
|
||||
const metaStep = lineStep(font) + 1;
|
||||
const titleLines = wrapText(font, media.title || "Unknown title", metaWidth).slice(0, 2);
|
||||
for (let index = 0; index < titleLines.length; index++) {
|
||||
image.drawText(font, META_X, ART_Y + 2 + index * 15, titleLines[index]!, 230);
|
||||
image.drawText(font, META_X, ART_Y + 2 + index * metaStep, titleLines[index]!, 230);
|
||||
}
|
||||
image.drawText(font, META_X, ART_Y + 36, media.artist || "Unknown artist", 180);
|
||||
image.drawText(font, META_X, ART_Y + 6 + 2 * metaStep, media.artist || "Unknown artist", 180);
|
||||
if (media.album) {
|
||||
image.drawText(font, META_X, ART_Y + 52, truncateText(font, media.album, metaWidth), 150);
|
||||
image.drawText(font, META_X, ART_Y + 6 + 3 * metaStep, truncateText(font, media.album, metaWidth), 150);
|
||||
}
|
||||
image.drawText(font, META_X, ART_Y + 68, truncateText(font, media.appName || media.packageName, metaWidth), 110);
|
||||
image.drawText(font, META_X, ART_Y + 6 + 4 * metaStep, truncateText(font, media.appName || media.packageName, metaWidth), 110);
|
||||
this.drawProgress(image, media, metaWidth);
|
||||
|
||||
const queue = mediaControllerBridge.getQueue();
|
||||
const actions = this.buildActions(media, queue);
|
||||
this.reconcileSelection(actions, queue);
|
||||
const listHeight = height - LIST_TOP - FOOTER_HEIGHT;
|
||||
const visibleRows = Math.max(1, (listHeight / ROW_HEIGHT) | 0);
|
||||
const rowH = tightRowHeight(font);
|
||||
const visibleRows = Math.max(1, (listHeight / rowH) | 0);
|
||||
if (this.selectedQueueIndex < this.queueScrollRow) {
|
||||
this.queueScrollRow = this.selectedQueueIndex;
|
||||
} else if (this.selectedQueueIndex >= this.queueScrollRow + visibleRows) {
|
||||
@@ -128,12 +130,12 @@ class MusicAppLayer implements Layer {
|
||||
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
const action = actions[index]!;
|
||||
const y = LIST_TOP + index * ROW_HEIGHT;
|
||||
const y = LIST_TOP + index * rowH;
|
||||
const selected = index === this.selectedActionIndex;
|
||||
const highlightX = ACTION_X - 6;
|
||||
const highlightY = y - 1;
|
||||
const highlightWidth = ACTION_WIDTH + 8;
|
||||
const highlightHeight = ROW_HEIGHT - 1;
|
||||
const highlightHeight = rowH - 1;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(
|
||||
image,
|
||||
@@ -160,7 +162,7 @@ class MusicAppLayer implements Layer {
|
||||
const lastVisible = Math.min(queue.length, this.queueScrollRow + visibleRows);
|
||||
for (let index = this.queueScrollRow; index < lastVisible; index++) {
|
||||
const item = queue[index]!;
|
||||
const y = LIST_TOP + (index - this.queueScrollRow) * ROW_HEIGHT;
|
||||
const y = LIST_TOP + (index - this.queueScrollRow) * rowH;
|
||||
const selected = index === this.selectedQueueIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(
|
||||
@@ -168,7 +170,7 @@ class MusicAppLayer implements Layer {
|
||||
QUEUE_X - 6,
|
||||
y - 1,
|
||||
queueWidth + 8,
|
||||
ROW_HEIGHT - 1,
|
||||
rowH - 1,
|
||||
ctx.stack.isFocused() && this.focusColumn === "playlist",
|
||||
4,
|
||||
);
|
||||
@@ -177,7 +179,7 @@ class MusicAppLayer implements Layer {
|
||||
image.drawText(font, QUEUE_X, y + 1, truncateText(font, label, queueWidth - 4), selected ? 255 : 200);
|
||||
}
|
||||
if (queue.length > visibleRows) {
|
||||
const trackHeight = visibleRows * ROW_HEIGHT - 4;
|
||||
const trackHeight = visibleRows * rowH - 4;
|
||||
const trackX = width - 12;
|
||||
image.fillRect(trackX, LIST_TOP, 3, trackHeight, 30);
|
||||
const thumbHeight = Math.max(8, (trackHeight * visibleRows / queue.length) | 0);
|
||||
|
||||
Reference in new issue
Block a user