forked from Blendman974/faceclaw
UI refinement pass
Remove gesture-help bottom-bars from many places in the UI, adjust layouts to be able to handle larger fonts, and other small UI fixes.
This commit is contained in:
1 parent
dc18737dfc
commit
35e6977c6c
17 files changed
+394
-321
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
|
||||
import { drawSelectionHighlight } from "../../ui/menu";
|
||||
import { TextViewerLayer } from "../files/text-viewer";
|
||||
@@ -42,60 +41,71 @@ export class EvenHubStoreDetailLayer implements Layer {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const textWidth = width - X * 2;
|
||||
const step = lineStep(font);
|
||||
const actionRowH = listRowHeight(font) + 4;
|
||||
let y = 8;
|
||||
|
||||
image.drawText(font, X, y, truncateText(font, this.app.name, textWidth), 235);
|
||||
y += step + 2;
|
||||
const creator = this.app.creatorName ? `by ${this.app.creatorName}` : this.app.packageId;
|
||||
image.drawText(font, X, y, truncateText(font, creator, textWidth), 130);
|
||||
y += step + 6;
|
||||
|
||||
const summary = this.app.tagline || this.app.description || "No description supplied.";
|
||||
for (const line of wrapText(font, summary, textWidth).slice(0, 3)) {
|
||||
image.drawText(font, X, y, line, 205);
|
||||
y += step;
|
||||
}
|
||||
y += 4;
|
||||
|
||||
const metadata = [
|
||||
`${formatCount(this.app.installCount)} installs · ${formatCount(this.app.likeCount)} likes`,
|
||||
this.app.version ? `Version ${this.app.version}${this.app.fileSize ? ` · ${formatBytes(this.app.fileSize)}` : ""}` : "",
|
||||
this.app.categories.length ? `Categories: ${this.app.categories.join(", ")}` : "",
|
||||
this.app.firstPublishedAt ? `Published: ${formatDate(this.app.firstPublishedAt)}` : "",
|
||||
].filter(Boolean);
|
||||
for (const line of metadata) {
|
||||
image.drawText(font, X, y, truncateText(font, line, textWidth), 125);
|
||||
y += step;
|
||||
}
|
||||
|
||||
const installed = getInstalledEvenHubApp(this.app.packageId);
|
||||
const actions = ["About", "What's New", this.working ? "Installing..." : installed ? "Launch" : "Install"];
|
||||
const actionTop = height - font.lineHeight - 10 - actions.length * actionRowH;
|
||||
if (installed && !this.status) {
|
||||
image.drawText(font, X, y + 2, `Installed version ${installed.version}`, 155);
|
||||
}
|
||||
if (this.status) {
|
||||
image.drawText(font, X, Math.min(actionTop - step, y + 2), truncateText(font, this.status, textWidth), 180);
|
||||
|
||||
// Detail lines as (text, shade, extra gap below); built per candidate
|
||||
// width so the layout choice below can measure before drawing.
|
||||
const buildLines = (textWidth: number): { text: string; value: number; gapAfter: number }[] => {
|
||||
const lines: { text: string; value: number; gapAfter: number }[] = [];
|
||||
lines.push({ text: truncateText(font, this.app.name, textWidth), value: 235, gapAfter: 2 });
|
||||
const creator = this.app.creatorName ? `by ${this.app.creatorName}` : this.app.packageId;
|
||||
lines.push({ text: truncateText(font, creator, textWidth), value: 130, gapAfter: 6 });
|
||||
const summary = this.app.tagline || this.app.description || "No description supplied.";
|
||||
const summaryLines = wrapText(font, summary, textWidth).slice(0, 3);
|
||||
for (const [index, line] of summaryLines.entries()) {
|
||||
lines.push({ text: line, value: 205, gapAfter: index === summaryLines.length - 1 ? 4 : 0 });
|
||||
}
|
||||
const metadata = [
|
||||
`${formatCount(this.app.installCount)} installs · ${formatCount(this.app.likeCount)} likes`,
|
||||
this.app.version ? `Version ${this.app.version}${this.app.fileSize ? ` · ${formatBytes(this.app.fileSize)}` : ""}` : "",
|
||||
this.app.categories.length ? `Categories: ${this.app.categories.join(", ")}` : "",
|
||||
this.app.firstPublishedAt ? `Published: ${formatDate(this.app.firstPublishedAt)}` : "",
|
||||
].filter(Boolean);
|
||||
for (const line of metadata) {
|
||||
lines.push({ text: truncateText(font, line, textWidth), value: 125, gapAfter: 0 });
|
||||
}
|
||||
if (installed && !this.status) {
|
||||
lines.push({ text: `Installed version ${installed.version}`, value: 155, gapAfter: 0 });
|
||||
}
|
||||
if (this.status) {
|
||||
lines.push({ text: truncateText(font, this.status, textWidth), value: 180, gapAfter: 0 });
|
||||
}
|
||||
return lines;
|
||||
};
|
||||
const linesHeight = (lines: { gapAfter: number }[]): number =>
|
||||
lines.reduce((sum, line) => sum + step + line.gapAfter, 0);
|
||||
|
||||
// Stacked layout (details full-width, actions at the bottom) when it
|
||||
// fits; otherwise the actions become a narrow top-right menu and the
|
||||
// details flow down a left column beside it.
|
||||
const stackedActionTop = height - 6 - actions.length * actionRowH;
|
||||
const stacked = 8 + linesHeight(buildLines(width - X * 2)) + 6 <= stackedActionTop;
|
||||
const menuW = 150;
|
||||
const menuX = width - menuW - 12;
|
||||
const textWidth = stacked ? width - X * 2 : menuX - X - 14;
|
||||
|
||||
let y = 8;
|
||||
for (const line of buildLines(textWidth)) {
|
||||
image.drawText(font, X, y, line.text, line.value);
|
||||
y += step + line.gapAfter;
|
||||
}
|
||||
|
||||
const actionX = stacked ? X : menuX;
|
||||
const actionW = stacked ? textWidth : menuW;
|
||||
const actionTop = stacked ? stackedActionTop : 8;
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
const actionY = actionTop + index * actionRowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, X - 5, actionY, textWidth + 10, actionRowH - 1, ctx.stack.isFocused(), 8);
|
||||
drawSelectionHighlight(image, actionX - 5, actionY, actionW + 10, actionRowH - 1, ctx.stack.isFocused(), 8);
|
||||
}
|
||||
image.drawText(font, X + 6, actionY + 5, actions[index]!, this.working && index === 2 ? 145 : selected ? 245 : 190);
|
||||
const value = this.working && index === 2 ? 145 : selected ? 245 : 190;
|
||||
image.drawText(font, actionX + 6, actionY + 5, truncateText(font, actions[index]!, actionW - 8), value);
|
||||
}
|
||||
image.drawText(
|
||||
font,
|
||||
X,
|
||||
height - font.lineHeight - 4,
|
||||
`${GESTURE_SCROLL} select ${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} back`,
|
||||
105,
|
||||
);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
import { GESTURE_CLICK } from "../../ui/gestures";
|
||||
import { type DashboardInputEvent, type Layer, type LayerActions, type LayerContext } from "../../ui/layers";
|
||||
import {
|
||||
drawListScrollbar,
|
||||
@@ -25,10 +25,13 @@ import {
|
||||
import { EvenHubStoreDetailLayer } from "./store-detail-layer";
|
||||
import { lineStep } from "../../ui/metrics";
|
||||
|
||||
const HEADER_HEIGHT = 34;
|
||||
const FOOTER_HEIGHT = 22;
|
||||
const LIST_X = 18;
|
||||
|
||||
/** Header: title line, then the status/subtitle line, then a small gap. */
|
||||
function headerHeight(font: UiFont): number {
|
||||
return 8 + lineStep(font) + font.lineHeight + 6;
|
||||
}
|
||||
|
||||
export type EvenHubStoreLayerOptions = {
|
||||
launchApp: (appId: string) => Promise<void> | void;
|
||||
appendLog: (message: string) => void;
|
||||
@@ -62,35 +65,30 @@ export class EvenHubStoreLayer implements Layer {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const headerH = headerHeight(font);
|
||||
image.drawText(font, LIST_X, 8, "EvenHub", 220);
|
||||
|
||||
const subtitle = this.status || (this.total ? `${this.apps.length} of ${this.total} public apps` : "Public apps");
|
||||
image.drawText(font, LIST_X, 22, truncateText(font, subtitle, width - LIST_X * 2), 125);
|
||||
image.drawText(font, LIST_X, 8 + lineStep(font), truncateText(font, subtitle, width - LIST_X * 2), 125);
|
||||
|
||||
if (this.showingLogin) {
|
||||
const message = this.loading
|
||||
? "Signing in..."
|
||||
: "Enter your Even account email and password in the phone app.";
|
||||
for (const [index, line] of wrapText(font, message, width - LIST_X * 2).entries()) {
|
||||
image.drawText(font, LIST_X, HEADER_HEIGHT + 22 + index * 15, line, 190);
|
||||
image.drawText(font, LIST_X, headerH + 16 + index * lineStep(font), line, 190);
|
||||
}
|
||||
image.drawText(
|
||||
font,
|
||||
LIST_X,
|
||||
height - 16,
|
||||
truncateText(font, `${GESTURE_CLICK} edit credentials ${GESTURE_DOUBLE_CLICK} back`, width - LIST_X * 2),
|
||||
105,
|
||||
);
|
||||
image.drawText(font, LIST_X, height - font.lineHeight - 4, `${GESTURE_CLICK} edit credentials`, 105);
|
||||
return image;
|
||||
}
|
||||
|
||||
if (this.apps.length === 0) {
|
||||
const message = this.loading ? "Loading apps..." : this.status || "No apps returned.";
|
||||
image.drawText(font, LIST_X, HEADER_HEIGHT + 28, truncateText(font, message, width - LIST_X * 2), 190);
|
||||
image.drawText(font, LIST_X, headerH + 22, truncateText(font, message, width - LIST_X * 2), 190);
|
||||
} else {
|
||||
this.selectedIndex = clamp(this.selectedIndex, 0, this.apps.length - 1);
|
||||
const rowH = Math.max(30, 2 * lineStep(font) + 4);
|
||||
const visibleRows = Math.max(1, Math.floor((height - HEADER_HEIGHT - FOOTER_HEIGHT) / rowH));
|
||||
const visibleRows = Math.max(1, Math.floor((height - headerH - 4) / rowH));
|
||||
this.scrollRow = scrollToKeepSelectionVisible(
|
||||
this.scrollRow,
|
||||
this.selectedIndex,
|
||||
@@ -100,7 +98,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
const last = Math.min(this.apps.length, this.scrollRow + visibleRows);
|
||||
for (let index = this.scrollRow; index < last; index++) {
|
||||
const app = this.apps[index]!;
|
||||
const y = HEADER_HEIGHT + (index - this.scrollRow) * rowH;
|
||||
const y = headerH + (index - this.scrollRow) * rowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, LIST_X - 6, y, width - LIST_X * 2 + 12, rowH - 2, ctx.stack.isFocused(), 5);
|
||||
@@ -110,12 +108,10 @@ export class EvenHubStoreLayer implements Layer {
|
||||
image.drawText(font, LIST_X, y + 2 + lineStep(font), truncateText(font, detail, width - LIST_X * 2), 115);
|
||||
}
|
||||
if (this.apps.length > visibleRows) {
|
||||
drawListScrollbar(image, width - 5, HEADER_HEIGHT, visibleRows * rowH - 3, this.scrollRow, visibleRows, this.apps.length);
|
||||
drawListScrollbar(image, width - 5, headerH, visibleRows * rowH - 3, this.scrollRow, visibleRows, this.apps.length);
|
||||
}
|
||||
}
|
||||
|
||||
const hint = `${GESTURE_SCROLL} select ${GESTURE_CLICK} details ${GESTURE_DOUBLE_CLICK} back`;
|
||||
image.drawText(font, LIST_X, height - font.lineHeight - 4, truncateText(font, hint, width - LIST_X * 2), 105);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user