forked from Blendman974/faceclaw
Modify sidebar size and vertical sizing options to allow 576x288 EvenHub apps to fit cleanly
This commit is contained in:
1 parent
6df7e9bc81
commit
d7d12afcaa
3 files changed
+108
-68
No files matched your search
@@ -12,36 +12,51 @@ import {
|
||||
MIN_WINDOW_HEIGHT,
|
||||
minWindowTop,
|
||||
SHELL_OPAQUE_BLACK,
|
||||
SIDEBAR_COLUMN_WIDTH,
|
||||
SIDEBAR_COLUMNS,
|
||||
SIDEBAR_WIDTH,
|
||||
TOP_BAR_HEIGHT,
|
||||
windowTop,
|
||||
type WindowHeightMode,
|
||||
} from "./geometry";
|
||||
|
||||
const ICON_SIZE = 32;
|
||||
const ICON_MARGIN_X = ((SIDEBAR_COLUMN_WIDTH - ICON_SIZE) / 2) | 0;
|
||||
/** Column index of the rightmost sidebar column (the one that fills first). */
|
||||
const FIRST_COLUMN = SIDEBAR_COLUMNS - 1;
|
||||
/**
|
||||
* Sidebar icon layout comes in two variants. Few enough windows for a single
|
||||
* column keeps the roomy 36px slots (32px icons) right-aligned against the
|
||||
* 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_STRIDE = ICON_SIZE + ICON_SPACING;
|
||||
/** Icon list top/bottom margins within the sidebar band, below the top bar. */
|
||||
const LIST_MARGIN = 10;
|
||||
const LIST_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
|
||||
|
||||
/** Icon rows that fit in one sidebar column. */
|
||||
const ROWS_PER_COLUMN = Math.max(
|
||||
1,
|
||||
((MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN + ICON_SPACING) / ICON_STRIDE) | 0,
|
||||
);
|
||||
function rowsPerColumn(variant: SidebarVariant): number {
|
||||
return Math.max(1, ((LIST_HEIGHT + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 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
|
||||
* the right column first; scrolling never shows fewer than a full right
|
||||
* column, so the left column is populated exactly when there are more
|
||||
* windows than one column holds.
|
||||
* Left edge of the sidebar region that actually holds icons: the one-column
|
||||
* variant leaves a dead strip left of its single right-aligned column.
|
||||
* Screenshot cropping uses this to trim the unused part.
|
||||
*/
|
||||
export function sidebarLeftColumnUsed(windowCount: number): boolean {
|
||||
return windowCount > ROWS_PER_COLUMN;
|
||||
export function sidebarContentLeft(windowCount: number): number {
|
||||
return columnLeft(sidebarVariant(windowCount), 0);
|
||||
}
|
||||
const NOTIFICATION_ICON_SIZE = 24;
|
||||
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
|
||||
// bottom, then overflow into the left one, so a visible slot's column is
|
||||
// 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 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);
|
||||
const lastVisible = Math.min(count, this.scrollRow + visibleCount);
|
||||
const slotOf = (index: number) => {
|
||||
const position = index - this.scrollRow;
|
||||
const columnsFromRight = (position / rowsPerColumn) | 0;
|
||||
const columnsFromRight = (position / rows) | 0;
|
||||
return {
|
||||
column: FIRST_COLUMN - columnsFromRight,
|
||||
y: listTop + (position % rowsPerColumn) * itemStride,
|
||||
column: firstColumn - columnsFromRight,
|
||||
y: listTop + (position % rows) * itemStride,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -171,10 +191,10 @@ export class ShellChromeLayer implements Layer {
|
||||
const sep = SIDEBAR_WIDTH - 1;
|
||||
const selVisible = state.selectedIndex >= this.scrollRow && state.selectedIndex < lastVisible;
|
||||
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) {
|
||||
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 {
|
||||
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++) {
|
||||
const window = state.windows[index]!;
|
||||
const { column, y } = slotOf(index);
|
||||
const columnLeft = column * SIDEBAR_COLUMN_WIDTH;
|
||||
const x = columnLeft + ICON_MARGIN_X;
|
||||
const left = columnLeft(variant, column);
|
||||
const x = left + iconMarginX;
|
||||
const selected = index === state.selectedIndex;
|
||||
const focused = selected && state.focus === "sidebar";
|
||||
if (selected && column === FIRST_COLUMN) {
|
||||
drawSelectionTab(image, columnLeft, y - 2, y + ICON_SIZE + 2, focused);
|
||||
if (selected && column === firstColumn) {
|
||||
drawSelectionTab(image, left, y - 2, y + iconSize + 2, focused);
|
||||
} else if (selected) {
|
||||
// Spans the full column: only 2px of margin flanks a 32px icon in a
|
||||
// 36px column, so anything wider would clip at the screen edge.
|
||||
drawSelectionBox(image, columnLeft, y - 2, SIDEBAR_COLUMN_WIDTH, ICON_SIZE + 4, focused);
|
||||
// Spans the full column: only 2px of margin flanks the icon in its
|
||||
// slot, so anything wider would clip at the screen edge.
|
||||
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) {
|
||||
// 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) {
|
||||
drawChevron(image, SIDEBAR_WIDTH / 2, bandTop + TOP_BAR_HEIGHT + 6, -1);
|
||||
drawChevron(image, chevronX, bandTop + TOP_BAR_HEIGHT + 6, -1);
|
||||
}
|
||||
if (lastVisible < count) {
|
||||
drawChevron(image, SIDEBAR_WIDTH / 2, bandBottom - 6, 1);
|
||||
drawChevron(image, chevronX, bandBottom - 6, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private drawTopBar(image: GrayImage, state: ShellChromeState): void {
|
||||
const font = getDefaultMediumFont();
|
||||
// The bar sits at the top edge of the foreground window: the screen top
|
||||
// for a max-height window, the min-height band otherwise. It moves when
|
||||
// The bar sits at the top edge of the foreground window's band, wherever
|
||||
// its height mode puts that (screen top for max height). It moves when
|
||||
// the foreground switches to a window of a different height.
|
||||
const barTop = windowTop(state.foregroundHeightMode);
|
||||
image.fillRect(SIDEBAR_WIDTH, barTop, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
|
||||
|
||||
+40
-22
@@ -3,15 +3,12 @@ import { verticalPositionSetting } from "../dashboard-settings";
|
||||
|
||||
/** Top bar: 24px notification icons plus a little padding. */
|
||||
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;
|
||||
* windows past that overflow into the left column, so the common few-window
|
||||
* case keeps every icon next to the content it belongs to.
|
||||
* Sidebar width. Leaves the app viewport exactly 576px wide — the surface
|
||||
* width EvenHub apps expect. Icon column layout within the strip (one wide
|
||||
* column vs. two narrow ones) is the chrome layer's business.
|
||||
*/
|
||||
export const SIDEBAR_COLUMNS = 2;
|
||||
export const SIDEBAR_WIDTH = SIDEBAR_COLUMN_WIDTH * SIDEBAR_COLUMNS;
|
||||
export const SIDEBAR_WIDTH = 64;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Windows come in two heights. "min" covers the same 288px band the stock
|
||||
* firmware uses, leaving most of the field of view clear; "max" uses the
|
||||
* whole 480px screen (terminal views). Both include a top bar drawn by the
|
||||
* shell at the window's top edge.
|
||||
* Windows come in three heights. "min" covers the same 288px band the stock
|
||||
* firmware uses, leaving most of the field of view clear; "medium" is one
|
||||
* top bar taller, so the content area below the bar is a full 288px (the
|
||||
* 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. */
|
||||
export const MIN_WINDOW_HEIGHT = 288;
|
||||
/** Farthest down a min-height window can start. */
|
||||
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
|
||||
* setting. The sidebar and shell overlays always align to this band, even
|
||||
* while a max-height window is foreground.
|
||||
* Fraction of the slack above a window band, from the Display > Vertical
|
||||
* position setting: each band height distributes its own free space by the
|
||||
* same fraction, so all heights sit consistently within the screen.
|
||||
*/
|
||||
export function minWindowTop(): number {
|
||||
function verticalPositionFraction(): number {
|
||||
switch (verticalPositionSetting.get()) {
|
||||
case "top":
|
||||
return 0;
|
||||
case "upper":
|
||||
return Math.round(MIN_WINDOW_MAX_TOP * 0.25);
|
||||
return 0.25;
|
||||
case "lower":
|
||||
return Math.round(MIN_WINDOW_MAX_TOP * 0.75);
|
||||
return 0.75;
|
||||
case "bottom":
|
||||
return MIN_WINDOW_MAX_TOP;
|
||||
return 1;
|
||||
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. */
|
||||
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). */
|
||||
export function appViewportSize(mode: WindowHeightMode): { width: number; height: number } {
|
||||
return {
|
||||
width: G2_LENS_WIDTH - SIDEBAR_WIDTH,
|
||||
height: (mode === "max" ? G2_LENS_HEIGHT : MIN_WINDOW_HEIGHT) - TOP_BAR_HEIGHT,
|
||||
height: windowBandHeight(mode) - TOP_BAR_HEIGHT,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -24,16 +24,15 @@ import {
|
||||
timeFormatSetting,
|
||||
wakeWordActionSetting,
|
||||
} 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 { ToolDebugMenuLayer } from "./tool-debug-layer";
|
||||
import { toolRegistry } from "../../assistant/tool-registry";
|
||||
import {
|
||||
MIN_WINDOW_HEIGHT,
|
||||
minWindowTop,
|
||||
SIDEBAR_COLUMN_WIDTH,
|
||||
SIDEBAR_WIDTH,
|
||||
TOP_BAR_HEIGHT,
|
||||
windowBandHeight,
|
||||
windowTop,
|
||||
type WindowHeightMode,
|
||||
} from "./geometry";
|
||||
@@ -584,17 +583,17 @@ class Shell {
|
||||
/**
|
||||
* Screen rect actually occupied by content, for cropping screenshots: the
|
||||
* foreground window's band (full screen for a max-height window, the
|
||||
* vertical-position-dependent 288px band otherwise), minus the sidebar's
|
||||
* left column when no icons have overflowed into it.
|
||||
* vertical-position-dependent 288px band otherwise), minus the sidebar
|
||||
* strip left of the icon columns when the one-column variant is active.
|
||||
*/
|
||||
screenshotCropRect(): { x: number; y: number; width: number; height: number } {
|
||||
const heightMode = this.foregroundWindow()?.heightMode ?? "min";
|
||||
const x = sidebarLeftColumnUsed(this.windows.length) ? 0 : SIDEBAR_COLUMN_WIDTH;
|
||||
const x = sidebarContentLeft(this.windows.length);
|
||||
return {
|
||||
x,
|
||||
y: windowTop(heightMode),
|
||||
width: G2_LENS_WIDTH - x,
|
||||
height: heightMode === "max" ? G2_LENS_HEIGHT : MIN_WINDOW_HEIGHT,
|
||||
height: windowBandHeight(heightMode),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user