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
+12
-9
@@ -4,6 +4,7 @@ import { getDefaultSmallFont } from "../graphics/ui-fonts";
|
||||
import { truncateText } from "../graphics/textwrap";
|
||||
import { GrayImage, type UiFont } from "../graphics/image";
|
||||
import { wrapText } from "../graphics/textwrap";
|
||||
import { lineStep, listRowHeight } from "./metrics";
|
||||
import { GESTURE_DOUBLE_CLICK } from "./gestures";
|
||||
import {
|
||||
dismissNotification,
|
||||
@@ -24,7 +25,6 @@ const CARD_X = 20;
|
||||
const ICON_SIZE = 24;
|
||||
const ICON_TEXT_GAP = 8;
|
||||
const CARD_TEXT_X = 10 + ICON_SIZE + ICON_TEXT_GAP;
|
||||
const LINE_HEIGHT = 14;
|
||||
const CARD_GAP = 6;
|
||||
const MAX_NOTIFICATIONS = 50;
|
||||
// Right-hand action menu of the detail view.
|
||||
@@ -88,7 +88,7 @@ export class NotificationsListLayer implements Layer {
|
||||
: "Grant permission on your phone to view notifications on the glasses.";
|
||||
const messageLines = wrapText(font, message, width - 48);
|
||||
for (let index = 0; index < messageLines.length; index++) {
|
||||
image.drawText(font, 24, 72 + index * LINE_HEIGHT, messageLines[index]!, 190);
|
||||
image.drawText(font, 24, 72 + index * lineStep(font), messageLines[index]!, 190);
|
||||
}
|
||||
image.drawText(font, 24, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
@@ -267,7 +267,7 @@ function buildNotificationCardLayout(
|
||||
return {
|
||||
notification,
|
||||
lines,
|
||||
height: Math.max(42, 12 + lines.length * LINE_HEIGHT),
|
||||
height: Math.max(ICON_SIZE + 18, 12 + lines.length * lineStep(font)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ function drawNotificationCard(
|
||||
}
|
||||
for (let index = 0; index < layout.lines.length; index++) {
|
||||
const value = index === 0 ? 140 : selected ? 235 : 185;
|
||||
image.drawText(font, x + CARD_TEXT_X, y + 7 + index * LINE_HEIGHT, layout.lines[index]!, value);
|
||||
image.drawText(font, x + CARD_TEXT_X, y + 7 + index * lineStep(font), layout.lines[index]!, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,10 +343,12 @@ function drawDetailContent(
|
||||
lines.push(...wrapText(font, meta, contentWidth));
|
||||
}
|
||||
|
||||
const maxLines = Math.max(1, ((height - 64 - 14) / LINE_HEIGHT) | 0);
|
||||
const step = lineStep(font);
|
||||
const bodyTop = 48 + font.lineHeight + 4;
|
||||
const maxLines = Math.max(1, ((height - bodyTop - step) / step) | 0);
|
||||
for (let index = 0; index < Math.min(lines.length, maxLines); index++) {
|
||||
const line = lines[index]!;
|
||||
image.drawText(font, contentX, 64 + index * LINE_HEIGHT, line, index === 0 ? 230 : 190);
|
||||
image.drawText(font, contentX, bodyTop + index * step, line, index === 0 ? 230 : 190);
|
||||
}
|
||||
if (lines.length > maxLines) {
|
||||
image.drawText(font, contentX, height - 24, "...", 140);
|
||||
@@ -356,12 +358,13 @@ function drawDetailContent(
|
||||
function drawDetailMenu(image: GrayImage, font: UiFont, menu: DetailMenuItem[], selectedIndex: number, width: number): void {
|
||||
const menuX = width - DETAIL_MENU_WIDTH - 24;
|
||||
const menuY = 24;
|
||||
const rowH = listRowHeight(font);
|
||||
for (let index = 0; index < menu.length; index++) {
|
||||
const y = menuY + index * 22;
|
||||
const y = menuY + index * (rowH + 2);
|
||||
const selected = index === selectedIndex;
|
||||
if (selected) {
|
||||
image.fillRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, 19, 18, 6);
|
||||
image.drawRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, 19, 60, 6);
|
||||
image.fillRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, rowH - 1, 18, 6);
|
||||
image.drawRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, rowH - 1, 60, 6);
|
||||
}
|
||||
const label = truncateText(font, menu[index]!.label, DETAIL_MENU_WIDTH - 12);
|
||||
image.drawText(font, menuX, y + 2, label, selected ? 255 : 185);
|
||||
|
||||
Reference in new issue
Block a user