Modify sidebar size and vertical sizing options to allow 576x288 EvenHub apps to fit cleanly

This commit is contained in:
James Babcock committed 2026-08-11 00:07:14 -07:00
1 parent 6df7e9bc81
commit d7d12afcaa
3 files changed
+108 -68

No files matched your search

+62 -39
View File
@@ -12,36 +12,51 @@ import {
MIN_WINDOW_HEIGHT, MIN_WINDOW_HEIGHT,
minWindowTop, minWindowTop,
SHELL_OPAQUE_BLACK, SHELL_OPAQUE_BLACK,
SIDEBAR_COLUMN_WIDTH,
SIDEBAR_COLUMNS,
SIDEBAR_WIDTH, SIDEBAR_WIDTH,
TOP_BAR_HEIGHT, TOP_BAR_HEIGHT,
windowTop, windowTop,
type WindowHeightMode, type WindowHeightMode,
} from "./geometry"; } from "./geometry";
const ICON_SIZE = 32; /**
const ICON_MARGIN_X = ((SIDEBAR_COLUMN_WIDTH - ICON_SIZE) / 2) | 0; * Sidebar icon layout comes in two variants. Few enough windows for a single
/** Column index of the rightmost sidebar column (the one that fills first). */ * column keeps the roomy 36px slots (32px icons) right-aligned against the
const FIRST_COLUMN = SIDEBAR_COLUMNS - 1; * separator; past one column's worth it switches to two 32px slots (28px
* icons) that exactly fill the 64px sidebar. In the two-column variant the
* right column (against the app area) fills first and windows past that
* overflow into the left column, so the common case keeps every icon next to
* the content it belongs to.
*/
type SidebarVariant = { columns: number; columnWidth: number; iconSize: number };
const ONE_COLUMN: SidebarVariant = { columns: 1, columnWidth: 36, iconSize: 32 };
const TWO_COLUMN: SidebarVariant = { columns: 2, columnWidth: 32, iconSize: 28 };
const ICON_SPACING = 8; const ICON_SPACING = 8;
const ICON_STRIDE = ICON_SIZE + ICON_SPACING;
/** Icon list top/bottom margins within the sidebar band, below the top bar. */ /** Icon list top/bottom margins within the sidebar band, below the top bar. */
const LIST_MARGIN = 10; const LIST_MARGIN = 10;
const LIST_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
/** Icon rows that fit in one sidebar column. */ /** Icon rows that fit in one sidebar column. */
const ROWS_PER_COLUMN = Math.max( function rowsPerColumn(variant: SidebarVariant): number {
1, return Math.max(1, ((LIST_HEIGHT + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 0);
((MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN + ICON_SPACING) / ICON_STRIDE) | 0, }
);
function sidebarVariant(windowCount: number): SidebarVariant {
return windowCount > rowsPerColumn(ONE_COLUMN) ? TWO_COLUMN : ONE_COLUMN;
}
/** Left x of a sidebar column; columns pack rightward against the separator. */
function columnLeft(variant: SidebarVariant, column: number): number {
return SIDEBAR_WIDTH - (variant.columns - column) * variant.columnWidth;
}
/** /**
* Whether the sidebar's left (overflow) column holds any icons. Icons fill * Left edge of the sidebar region that actually holds icons: the one-column
* the right column first; scrolling never shows fewer than a full right * variant leaves a dead strip left of its single right-aligned column.
* column, so the left column is populated exactly when there are more * Screenshot cropping uses this to trim the unused part.
* windows than one column holds.
*/ */
export function sidebarLeftColumnUsed(windowCount: number): boolean { export function sidebarContentLeft(windowCount: number): number {
return windowCount > ROWS_PER_COLUMN; return columnLeft(sidebarVariant(windowCount), 0);
} }
const NOTIFICATION_ICON_SIZE = 24; const NOTIFICATION_ICON_SIZE = 24;
const BORDER_VALUE = 40; const BORDER_VALUE = 40;
@@ -146,19 +161,24 @@ export class ShellChromeLayer implements Layer {
// windows off-screen above/below. Icons fill the right column top to // windows off-screen above/below. Icons fill the right column top to
// bottom, then overflow into the left one, so a visible slot's column is // bottom, then overflow into the left one, so a visible slot's column is
// decided by its position within the scrolled window. // decided by its position within the scrolled window.
const listTop = bandTop + TOP_BAR_HEIGHT + LIST_MARGIN;
const itemStride = ICON_STRIDE;
const rowsPerColumn = ROWS_PER_COLUMN;
const visibleCount = rowsPerColumn * SIDEBAR_COLUMNS;
const count = state.windows.length; const count = state.windows.length;
const variant = sidebarVariant(count);
const iconSize = variant.iconSize;
const iconMarginX = ((variant.columnWidth - iconSize) / 2) | 0;
// Column index of the rightmost column (the one that fills first).
const firstColumn = variant.columns - 1;
const listTop = bandTop + TOP_BAR_HEIGHT + LIST_MARGIN;
const itemStride = iconSize + ICON_SPACING;
const rows = rowsPerColumn(variant);
const visibleCount = rows * variant.columns;
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count); this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count);
const lastVisible = Math.min(count, this.scrollRow + visibleCount); const lastVisible = Math.min(count, this.scrollRow + visibleCount);
const slotOf = (index: number) => { const slotOf = (index: number) => {
const position = index - this.scrollRow; const position = index - this.scrollRow;
const columnsFromRight = (position / rowsPerColumn) | 0; const columnsFromRight = (position / rows) | 0;
return { return {
column: FIRST_COLUMN - columnsFromRight, column: firstColumn - columnsFromRight,
y: listTop + (position % rowsPerColumn) * itemStride, y: listTop + (position % rows) * itemStride,
}; };
}; };
@@ -171,10 +191,10 @@ export class ShellChromeLayer implements Layer {
const sep = SIDEBAR_WIDTH - 1; const sep = SIDEBAR_WIDTH - 1;
const selVisible = state.selectedIndex >= this.scrollRow && state.selectedIndex < lastVisible; const selVisible = state.selectedIndex >= this.scrollRow && state.selectedIndex < lastVisible;
const selSlot = selVisible ? slotOf(state.selectedIndex) : null; const selSlot = selVisible ? slotOf(state.selectedIndex) : null;
const selTabTop = selSlot && selSlot.column === FIRST_COLUMN ? selSlot.y - 2 : null; const selTabTop = selSlot && selSlot.column === firstColumn ? selSlot.y - 2 : null;
if (selTabTop !== null) { if (selTabTop !== null) {
image.drawLine(sep, bandTop, sep, selTabTop, BORDER_VALUE); image.drawLine(sep, bandTop, sep, selTabTop, BORDER_VALUE);
image.drawLine(sep, selTabTop + ICON_SIZE + 4, sep, bandBottom - 1, BORDER_VALUE); image.drawLine(sep, selTabTop + iconSize + 4, sep, bandBottom - 1, BORDER_VALUE);
} else { } else {
image.drawLine(sep, bandTop, sep, bandBottom - 1, BORDER_VALUE); image.drawLine(sep, bandTop, sep, bandBottom - 1, BORDER_VALUE);
} }
@@ -182,36 +202,39 @@ export class ShellChromeLayer implements Layer {
for (let index = this.scrollRow; index < lastVisible; index++) { for (let index = this.scrollRow; index < lastVisible; index++) {
const window = state.windows[index]!; const window = state.windows[index]!;
const { column, y } = slotOf(index); const { column, y } = slotOf(index);
const columnLeft = column * SIDEBAR_COLUMN_WIDTH; const left = columnLeft(variant, column);
const x = columnLeft + ICON_MARGIN_X; const x = left + iconMarginX;
const selected = index === state.selectedIndex; const selected = index === state.selectedIndex;
const focused = selected && state.focus === "sidebar"; const focused = selected && state.focus === "sidebar";
if (selected && column === FIRST_COLUMN) { if (selected && column === firstColumn) {
drawSelectionTab(image, columnLeft, y - 2, y + ICON_SIZE + 2, focused); drawSelectionTab(image, left, y - 2, y + iconSize + 2, focused);
} else if (selected) { } else if (selected) {
// Spans the full column: only 2px of margin flanks a 32px icon in a // Spans the full column: only 2px of margin flanks the icon in its
// 36px column, so anything wider would clip at the screen edge. // slot, so anything wider would clip at the screen edge.
drawSelectionBox(image, columnLeft, y - 2, SIDEBAR_COLUMN_WIDTH, ICON_SIZE + 4, focused); drawSelectionBox(image, left, y - 2, variant.columnWidth, iconSize + 4, focused);
} }
window.drawIcon(image, x, y, ICON_SIZE, focused); window.drawIcon(image, x, y, iconSize, focused);
if (window.attention) { if (window.attention) {
// Black dot on the white focused tab, white dot otherwise. // Black dot on the white focused tab, white dot otherwise.
image.fillRoundedRect(x + ICON_SIZE - 7, y - 1, 8, 8, focused ? SHELL_OPAQUE_BLACK : 255, 4); image.fillRoundedRect(x + iconSize - 7, y - 1, 8, 8, focused ? SHELL_OPAQUE_BLACK : 255, 4);
} }
} }
// Chevrons center over the icon area, which in the one-column variant is
// narrower than the sidebar strip.
const chevronX = ((columnLeft(variant, 0) + SIDEBAR_WIDTH) / 2) | 0;
if (this.scrollRow > 0) { if (this.scrollRow > 0) {
drawChevron(image, SIDEBAR_WIDTH / 2, bandTop + TOP_BAR_HEIGHT + 6, -1); drawChevron(image, chevronX, bandTop + TOP_BAR_HEIGHT + 6, -1);
} }
if (lastVisible < count) { if (lastVisible < count) {
drawChevron(image, SIDEBAR_WIDTH / 2, bandBottom - 6, 1); drawChevron(image, chevronX, bandBottom - 6, 1);
} }
} }
private drawTopBar(image: GrayImage, state: ShellChromeState): void { private drawTopBar(image: GrayImage, state: ShellChromeState): void {
const font = getDefaultMediumFont(); const font = getDefaultMediumFont();
// The bar sits at the top edge of the foreground window: the screen top // The bar sits at the top edge of the foreground window's band, wherever
// for a max-height window, the min-height band otherwise. It moves when // its height mode puts that (screen top for max height). It moves when
// the foreground switches to a window of a different height. // the foreground switches to a window of a different height.
const barTop = windowTop(state.foregroundHeightMode); const barTop = windowTop(state.foregroundHeightMode);
image.fillRect(SIDEBAR_WIDTH, barTop, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK); image.fillRect(SIDEBAR_WIDTH, barTop, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
+40 -22
View File
@@ -3,15 +3,12 @@ import { verticalPositionSetting } from "../dashboard-settings";
/** Top bar: 24px notification icons plus a little padding. */ /** Top bar: 24px notification icons plus a little padding. */
export const TOP_BAR_HEIGHT = 28; export const TOP_BAR_HEIGHT = 28;
/** One sidebar column: 32px window icons plus a little padding. */
export const SIDEBAR_COLUMN_WIDTH = 36;
/** /**
* Sidebar icon columns. The right column (against the app area) fills first; * Sidebar width. Leaves the app viewport exactly 576px wide — the surface
* windows past that overflow into the left column, so the common few-window * width EvenHub apps expect. Icon column layout within the strip (one wide
* case keeps every icon next to the content it belongs to. * column vs. two narrow ones) is the chrome layer's business.
*/ */
export const SIDEBAR_COLUMNS = 2; export const SIDEBAR_WIDTH = 64;
export const SIDEBAR_WIDTH = SIDEBAR_COLUMN_WIDTH * SIDEBAR_COLUMNS;
/** /**
* On the color-key shell surface, pixel value 0 is transparent; 1 is the * On the color-key shell surface, pixel value 0 is transparent; 1 is the
@@ -21,48 +18,69 @@ export const SIDEBAR_WIDTH = SIDEBAR_COLUMN_WIDTH * SIDEBAR_COLUMNS;
export const SHELL_OPAQUE_BLACK = 1; export const SHELL_OPAQUE_BLACK = 1;
/** /**
* Windows come in two heights. "min" covers the same 288px band the stock * Windows come in three heights. "min" covers the same 288px band the stock
* firmware uses, leaving most of the field of view clear; "max" uses the * firmware uses, leaving most of the field of view clear; "medium" is one
* whole 480px screen (terminal views). Both include a top bar drawn by the * top bar taller, so the content area below the bar is a full 288px (the
* shell at the window's top edge. * EvenHub app surface height); "max" uses the whole 480px screen (terminal
* views). All include a top bar drawn by the shell at the window's top edge.
*/ */
export type WindowHeightMode = "min" | "max"; export type WindowHeightMode = "min" | "medium" | "max";
/** Total height (top bar + content) of a min-height window. */ /** Total height (top bar + content) of a min-height window. */
export const MIN_WINDOW_HEIGHT = 288; export const MIN_WINDOW_HEIGHT = 288;
/** Farthest down a min-height window can start. */ /** Farthest down a min-height window can start. */
export const MIN_WINDOW_MAX_TOP = G2_LENS_HEIGHT - MIN_WINDOW_HEIGHT; export const MIN_WINDOW_MAX_TOP = G2_LENS_HEIGHT - MIN_WINDOW_HEIGHT;
/** Total height (top bar + content) of a window's band in the given mode. */
export function windowBandHeight(mode: WindowHeightMode): number {
switch (mode) {
case "max":
return G2_LENS_HEIGHT;
case "medium":
return MIN_WINDOW_HEIGHT + TOP_BAR_HEIGHT;
default:
return MIN_WINDOW_HEIGHT;
}
}
/** /**
* Top edge (y) of a min-height window, from the Display > Vertical position * Fraction of the slack above a window band, from the Display > Vertical
* setting. The sidebar and shell overlays always align to this band, even * position setting: each band height distributes its own free space by the
* while a max-height window is foreground. * same fraction, so all heights sit consistently within the screen.
*/ */
export function minWindowTop(): number { function verticalPositionFraction(): number {
switch (verticalPositionSetting.get()) { switch (verticalPositionSetting.get()) {
case "top": case "top":
return 0; return 0;
case "upper": case "upper":
return Math.round(MIN_WINDOW_MAX_TOP * 0.25); return 0.25;
case "lower": case "lower":
return Math.round(MIN_WINDOW_MAX_TOP * 0.75); return 0.75;
case "bottom": case "bottom":
return MIN_WINDOW_MAX_TOP; return 1;
default: default:
return Math.round(MIN_WINDOW_MAX_TOP * 0.5); return 0.5;
} }
} }
/**
* Top edge (y) of a min-height window. The sidebar and shell overlays always
* align to this band, even while a taller window is foreground.
*/
export function minWindowTop(): number {
return windowTop("min");
}
/** Top edge (y) of a window's top bar; max-height windows pin to the screen top. */ /** Top edge (y) of a window's top bar; max-height windows pin to the screen top. */
export function windowTop(mode: WindowHeightMode): number { export function windowTop(mode: WindowHeightMode): number {
return mode === "max" ? 0 : minWindowTop(); return Math.round((G2_LENS_HEIGHT - windowBandHeight(mode)) * verticalPositionFraction());
} }
/** App-content viewport size for a height mode (independent of vertical position). */ /** App-content viewport size for a height mode (independent of vertical position). */
export function appViewportSize(mode: WindowHeightMode): { width: number; height: number } { export function appViewportSize(mode: WindowHeightMode): { width: number; height: number } {
return { return {
width: G2_LENS_WIDTH - SIDEBAR_WIDTH, width: G2_LENS_WIDTH - SIDEBAR_WIDTH,
height: (mode === "max" ? G2_LENS_HEIGHT : MIN_WINDOW_HEIGHT) - TOP_BAR_HEIGHT, height: windowBandHeight(mode) - TOP_BAR_HEIGHT,
}; };
} }
+6 -7
View File
@@ -24,16 +24,15 @@ import {
timeFormatSetting, timeFormatSetting,
wakeWordActionSetting, wakeWordActionSetting,
} from "../dashboard-settings"; } from "../dashboard-settings";
import { ShellChromeLayer, sidebarLeftColumnUsed, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer"; import { ShellChromeLayer, sidebarContentLeft, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
import { ShellModalLayer } from "./modal-layer"; import { ShellModalLayer } from "./modal-layer";
import { ToolDebugMenuLayer } from "./tool-debug-layer"; import { ToolDebugMenuLayer } from "./tool-debug-layer";
import { toolRegistry } from "../../assistant/tool-registry"; import { toolRegistry } from "../../assistant/tool-registry";
import { import {
MIN_WINDOW_HEIGHT,
minWindowTop, minWindowTop,
SIDEBAR_COLUMN_WIDTH,
SIDEBAR_WIDTH, SIDEBAR_WIDTH,
TOP_BAR_HEIGHT, TOP_BAR_HEIGHT,
windowBandHeight,
windowTop, windowTop,
type WindowHeightMode, type WindowHeightMode,
} from "./geometry"; } from "./geometry";
@@ -584,17 +583,17 @@ class Shell {
/** /**
* Screen rect actually occupied by content, for cropping screenshots: the * Screen rect actually occupied by content, for cropping screenshots: the
* foreground window's band (full screen for a max-height window, the * foreground window's band (full screen for a max-height window, the
* vertical-position-dependent 288px band otherwise), minus the sidebar's * vertical-position-dependent 288px band otherwise), minus the sidebar
* left column when no icons have overflowed into it. * strip left of the icon columns when the one-column variant is active.
*/ */
screenshotCropRect(): { x: number; y: number; width: number; height: number } { screenshotCropRect(): { x: number; y: number; width: number; height: number } {
const heightMode = this.foregroundWindow()?.heightMode ?? "min"; const heightMode = this.foregroundWindow()?.heightMode ?? "min";
const x = sidebarLeftColumnUsed(this.windows.length) ? 0 : SIDEBAR_COLUMN_WIDTH; const x = sidebarContentLeft(this.windows.length);
return { return {
x, x,
y: windowTop(heightMode), y: windowTop(heightMode),
width: G2_LENS_WIDTH - x, width: G2_LENS_WIDTH - x,
height: heightMode === "max" ? G2_LENS_HEIGHT : MIN_WINDOW_HEIGHT, height: windowBandHeight(heightMode),
}; };
} }