diff --git a/app/apps/launcher/launcher-app.ts b/app/apps/launcher/launcher-app.ts index a50ea683..d7cf2ccf 100644 --- a/app/apps/launcher/launcher-app.ts +++ b/app/apps/launcher/launcher-app.ts @@ -4,7 +4,7 @@ import { GrayImage } from "../../graphics/image"; import { type Plane } from "../../graphics/plane"; import { renderIcon, type IconName } from "../../graphics/icons"; import { InputEvent } from "../../ui/gestures"; -import { IconGrid, ICON_GRID_ICON_SIZE } from "../../ui/icon-grid"; +import { IconGrid, ICON_GRID_BAND_INSET_X, ICON_GRID_HIGHLIGHT_INSET_Y, ICON_GRID_ICON_SIZE } from "../../ui/icon-grid"; import { Layer, LayerActions, LayerContext } from "../../ui/layers"; import { MenuLayer, type MenuItem } from "../../ui/menu"; import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu"; @@ -44,6 +44,11 @@ export const LAUNCHER_WINDOW_ID = "launcher"; export const LAUNCHER_SURFACE_ID = "window:launcher"; const GRID_TOP = 6; +/** + * The root grid's top: its first row's highlight band then sits as far + * below the window's top edge as it is from the side edges. + */ +const ROOT_GRID_TOP = ICON_GRID_BAND_INSET_X - ICON_GRID_HIGHLIGHT_INSET_Y; /** One cell of the grid: an app, or a folder holding some of the apps. */ type LauncherGridEntry = @@ -258,12 +263,13 @@ class LauncherGridLayer implements Layer { const { width, height } = ctx.stack.getBaseSize(); const image = new GrayImage(width, height, 0); // The folder-name header band scales with the font. - const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : GRID_TOP; + const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : ROOT_GRID_TOP; if (this.currentFolder !== null) { image.drawText(font, 8, GRID_TOP - 2, truncateText(font, this.currentFolder, width - 16), 160); } - const gridBottom = height - 4; - this.grid.paint(image, { x: 0, y: gridTop, width, height: gridBottom - gridTop }, ctx.stack.isFocused()); + // The grid runs to the window's bottom edge, so a row cut off there for + // scrolling meets the window's border rather than a blank strip. + this.grid.paint(image, { x: 0, y: gridTop, width, height: height - gridTop }, ctx.stack.isFocused()); return image; } diff --git a/app/ui/icon-grid.ts b/app/ui/icon-grid.ts index 512153ec..ba50e892 100644 --- a/app/ui/icon-grid.ts +++ b/app/ui/icon-grid.ts @@ -24,6 +24,10 @@ const DEFAULT_LABEL_VALUE = 210; const WIDE_TEXT_X = 20; /** The scrollbar's columns at the right edge, which animations leave alone. */ const SCROLLBAR_GUTTER = 5; +/** How far a row-mode highlight band is inset from the box's left and right edges. */ +export const ICON_GRID_BAND_INSET_X = 4; +/** How far a grid row's highlight (band or cell) is inset from the row's top and bottom. */ +export const ICON_GRID_HIGHLIGHT_INSET_Y = 2; export type IconGridCell = { label: string; @@ -271,11 +275,13 @@ export class IconGrid { return { key: row.firstIndex, x: box.x + WIDE_TEXT_X - 6, y: textY - 2, width: box.width - 2 * WIDE_TEXT_X + 12, height: font.lineHeight + 4, radius: 4 }; } + const insetY = ICON_GRID_HIGHLIGHT_INSET_Y; if (this.mode === "item" || (!focused && shell.lastInputWasWatch())) { - return { key: row.firstIndex + this.selectedCol, x: Math.round(box.x + this.selectedCol * colW) + 6, y: y + 2, - width: Math.round(colW) - 12, height: rowH - 4, radius: 6 }; + return { key: row.firstIndex + this.selectedCol, x: Math.round(box.x + this.selectedCol * colW) + 6, y: y + insetY, + width: Math.round(colW) - 12, height: rowH - 2 * insetY, radius: 6 }; } - return { key: -1 - this.selectedRow, x: box.x + 4, y: y + 2, width: box.width - 8, height: rowH - 4, radius: 6 }; + return { key: -1 - this.selectedRow, x: box.x + ICON_GRID_BAND_INSET_X, y: y + insetY, + width: box.width - 2 * ICON_GRID_BAND_INSET_X, height: rowH - 2 * insetY, radius: 6 }; } /** diff --git a/app/ui/shell/chrome-layer.ts b/app/ui/shell/chrome-layer.ts index cd50d473..f9a0ce6b 100644 --- a/app/ui/shell/chrome-layer.ts +++ b/app/ui/shell/chrome-layer.ts @@ -1,6 +1,6 @@ import { shellCrop } from "../../graphics/shell-scene"; import type { Plane } from "../../graphics/plane"; -import { DrawOp } from "../../graphics/display-list"; +import { DrawOp, type ListCall, type ListClip } from "../../graphics/display-list"; import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage, grayToNibble } from "../../graphics/image"; import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts"; import { truncateText } from "../../graphics/textwrap"; @@ -128,19 +128,26 @@ type SwitcherLayout = { /** * Switcher geometry for the foreground window (a bottom row sits under it). * `windowsRight` is where a bottom row's window icons must end: short of - * the status bar when it shares the row. + * the status bar when it shares the row. `scrollRow` is the first visible + * window's index. */ -function switcherLayout(windowCount: number, heightMode: WindowHeightMode, appId?: string, windowsRight?: number): SwitcherLayout { +function switcherLayout(windowCount: number, heightMode: WindowHeightMode, appId?: string, windowsRight?: number, scrollRow = 0): SwitcherLayout { const position = switcherPosition(); if (position === "bottom") { const row = switcherRect(heightMode, appId); const width = (windowsRight ?? row.x + row.width) - row.x; + // Under a framed window the first window's cell (the launcher's) starts + // at the frame's left side, one pixel outside the window, so a selection + // tab there carries the side straight down (drawWindowFrame squares that + // corner for it). Scrolled past it, the cells keep the margin the left + // chevron needs. The count of slots stays the same either way. + const first = windowFramed(appId) && scrollRow === 0 ? row.x - 1 : row.x + LIST_MARGIN - 2; return { position, iconSize: ROW_ICON_SIZE, visibleCount: Math.max(1, ((width - 2 * LIST_MARGIN + ICON_SPACING) / ROW_STEP) | 0), cell: (slot) => ({ - x: row.x + LIST_MARGIN - 2 + slot * ROW_STEP, y: row.y, width: ROW_ICON_SIZE + 4, height: SWITCHER_ROW_HEIGHT, + x: first + slot * ROW_STEP, y: row.y, width: ROW_ICON_SIZE + 4, height: SWITCHER_ROW_HEIGHT, atSeparator: true, }), }; @@ -305,6 +312,9 @@ export class ShellChromeLayer implements Layer { private scrollRow = 0; // Where the last paint ended a bottom row's window icons, for hit testing. private rowWindowsRight: number | undefined; + // Whether the last paint's selection tab carries the window frame's left + // side down, so the frame's bottom-left corner is square. + private frameCornerSquare = false; constructor(private readonly getState: () => ShellChromeState) {} @@ -319,7 +329,7 @@ export class ShellChromeLayer implements Layer { } if (!statusInRow) this.drawTopBar(image, state); const frame = windowFrameRect(state); - if (frame) drawWindowFrame(image, frame); + if (frame) drawWindowFrame(image, frame, this.frameCornerSquare); drawAmbientCards(image, topBarSpan(state).right); return image; } @@ -342,9 +352,12 @@ export class ShellChromeLayer implements Layer { // -2, which on top of a -62 screen depth would shift a side off the // screen. (A framed window always has the row on screen.) const frame = windowFrameRect(state); - if (frame) drawWindowFrame(stripCanvas, frame); + if (frame) drawWindowFrame(stripCanvas, frame, this.frameCornerSquare); + // Under a framed window the row's surface spans the frame, whose left + // side the first selection tab continues. const strip = switcherRect(state.foregroundHeightMode, state.foregroundAppId); - parts.push(shellCrop(stripCanvas, strip.x, strip.y, strip.width, strip.height, 1)); + const span = frame ?? strip; + parts.push(shellCrop(stripCanvas, span.x, strip.y, span.width, strip.height, 1)); if (statusLeft !== null) { // The status bar keeps the top bar's surface and its depth, -2, over // the row's right end below its separator line, so the clock ticking @@ -370,7 +383,7 @@ export class ShellChromeLayer implements Layer { windowIndexAt(x: number, y: number, windowCount: number): number | null { if (windowCount === 0) return null; const state = this.getState(); - const layout = switcherLayout(windowCount, state.foregroundHeightMode, state.foregroundAppId, this.rowWindowsRight); + const layout = switcherLayout(windowCount, state.foregroundHeightMode, state.foregroundAppId, this.rowWindowsRight, this.scrollRow); const lastVisible = Math.min(windowCount, this.scrollRow + layout.visibleCount); for (let index = this.scrollRow; index < lastVisible; index++) { const cell = layout.cell(index - this.scrollRow); @@ -404,9 +417,10 @@ export class ShellChromeLayer implements Layer { ? this.drawRowStatus(statusImage, state, strip, count) : null; const windowsRight = statusLeft === null ? strip.x + strip.width : statusLeft - ROW_STATUS_GAP; this.rowWindowsRight = windowsRight; - const layout = switcherLayout(count, state.foregroundHeightMode, state.foregroundAppId, windowsRight); + const visibleCount = switcherLayout(count, state.foregroundHeightMode, state.foregroundAppId, windowsRight).visibleCount; + this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count); + const layout = switcherLayout(count, state.foregroundHeightMode, state.foregroundAppId, windowsRight, this.scrollRow); const { iconSize, position } = layout; - this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, layout.visibleCount, count); const lastVisible = Math.min(count, this.scrollRow + layout.visibleCount); const cellOf = (index: number) => layout.cell(index - this.scrollRow); @@ -420,6 +434,8 @@ export class ShellChromeLayer implements Layer { const selVisible = state.selectedIndex >= this.scrollRow && state.selectedIndex < lastVisible; const selCell = selVisible ? cellOf(state.selectedIndex) : null; drawSeparator(image, state, strip, selCell?.atSeparator ? selCell : null); + const frame = position === "bottom" ? windowFrameRect(state) : null; + this.frameCornerSquare = !!frame && selCell?.x === frame.x; for (let index = this.scrollRow; index < lastVisible; index++) { const window = state.windows[index]!; @@ -799,18 +815,27 @@ function windowFrameRect(state: ShellChromeState): Rect | null { } /** - * Draw the window frame (see windowFrameRect) as one retained firmware - * rounded rect over whatever lies beneath it: no fill, so the window's - * content shows through, and black outside the curve, cutting the content's - * square corners to it. It is clipped short of its bottom row, which - * drawSeparator draws with the selection tab's gap. + * Draw the window frame (see windowFrameRect) as a retained firmware rounded + * rect over whatever lies beneath it: no fill, so the window's content shows + * through, and black outside the curve, cutting the content's square + * corners to it. It is clipped short of its bottom row, which drawSeparator + * draws with the selection tab's gap. With `squareBottomLeft` (a selection + * tab continuing its left side down), the rect is clipped away from that + * corner's box too, and the side runs straight through it as a one-pixel + * clipped clear, leaving the content's corner whole. */ -function drawWindowFrame(image: GrayImage, frame: Rect): void { - image.drawDisplayList({ resources: [], calls: [{ +function drawWindowFrame(image: GrayImage, frame: Rect, squareBottomLeft: boolean): void { + const border = grayToNibble(BORDER_VALUE), above = frame.height - 1; + const rounded = (clip: ListClip): ListCall => ({ op: DrawOp.ROUNDED_RECT, x: 0, y: 0, width: frame.width, height: frame.height, radius: FRAME_RADIUS, - background: 0, border: grayToNibble(BORDER_VALUE), outside: 0, - clip: { x: 0, y: 0, width: frame.width, height: frame.height - 1 }, - }] }, frame.x, frame.y, frame.width, frame.height); + background: 0, border, outside: 0, clip, + }); + const calls = squareBottomLeft ? [ + rounded({ x: FRAME_RADIUS, y: 0, width: frame.width - FRAME_RADIUS, height: above }), + rounded({ x: 0, y: 0, width: FRAME_RADIUS, height: above - FRAME_RADIUS }), + { op: DrawOp.CLEAR, color: border, clip: { x: 0, y: above - FRAME_RADIUS, width: 1, height: FRAME_RADIUS } }, + ] : [rounded({ x: 0, y: 0, width: frame.width, height: above })]; + image.drawDisplayList({ resources: [], calls }, frame.x, frame.y, frame.width, frame.height); } /** @@ -843,8 +868,10 @@ function drawSeparator( if (switcherPosition() === "bottom") { // Along the row's top edge: the full width of the row, or between the // corners of the window frame, whose bottom side this is. + // A selection tab at the frame's left side squares that corner (see + // drawWindowFrame), so the line starts right at the side. const frame = windowFrameRect(state); - const left = frame ? frame.x + frameEdgeInset() : strip.x; + const left = frame ? frame.x + (gap?.x === frame.x ? 0 : frameEdgeInset()) : strip.x; const right = frame ? frame.x + frame.width - 1 - frameEdgeInset() : strip.x + strip.width - 1; const y = strip.y; if (gap) { diff --git a/tests/app-layout.test.cjs b/tests/app-layout.test.cjs index cfdeacec..c43a8e51 100644 --- a/tests/app-layout.test.cjs +++ b/tests/app-layout.test.cjs @@ -171,7 +171,9 @@ function chromeLayer(g, { notifications = 0, phoneBattery = null, windows = 1, t batteryIndicatorVisible: () => true }, '../clock-format': { formatClockDate: () => 'Thu Oct 2', formatClockTime: () => '9:41' }, '../layers': { LayerStack: { allocateShellKey: () => nextKey++ } }, - '../menu': { scrollToKeepSelectionVisible: () => 0 }, + // As in menu.ts. + '../menu': { scrollToKeepSelectionVisible: (scroll, selected, visible, count) => Math.min(Math.max(0, count - visible), + Math.max(0, selected < scroll ? selected : selected >= scroll + visible ? selected - visible + 1 : scroll)) }, './geometry': g, }; const context = { exports: {}, require: (name) => modules[name] ?? {} }; @@ -188,7 +190,10 @@ test('a bottom app switcher frames the foreground window\'s content in a rounded const g = geometry(); g.settings.appSwitcherPositionSetting.value = 'bottom'; g.settings.uiDepthSetting.value = '62'; - const { chrome } = chromeLayer(g); + // The second window is selected: the first's (see the launcher test below) + // would square the bottom-left corner. + const { chrome, state } = chromeLayer(g, { windows: 2 }); + state.selectedIndex = 1; const parts = chrome.paintParts(); // Just the top bar and then the row: the frame is no surface of its own. const part = (key) => parts.find((p) => p.shellKey === key); @@ -226,6 +231,46 @@ test('a bottom app switcher frames the foreground window\'s content in a rounded assert.equal(chrome.paintParts().flatMap((p) => frames(p.image)).length, 0); }); +test('the launcher\'s tab lines up with the window frame, whose corner squares to meet it', () => { + const g = geometry(); + g.settings.appSwitcherPositionSetting.value = 'bottom'; + const paint = (chrome) => { + const [, strip] = chrome.paintParts(); + const [frame] = strip.image.draws.filter((d) => d.presentation?.displayList); + const lit = new Uint8Array(640 * 480).fill(255); + displayList.paintDisplayList(lit, lit.slice(), 640, 480, { displayList: frame.presentation.displayList, + x: strip.x + frame.x, y: strip.y + frame.y, width: frame.source.width, height: frame.source.height, depth: 0 }); + return { strip, px: (x, y) => lit[y * 640 + x], at: (x, y) => strip.image.pixels[(y - strip.y) * strip.image.width + x - strip.x] }; + }; + const { chrome, state } = chromeLayer(g, { windows: 3 }); + // The first cell starts at the frame's left side (x=31), one pixel outside + // the window, so the row's surface spans the frame. + let { strip, px, at } = paint(chrome); + assert.deepEqual([strip.x, strip.image.width], [31, 578]); + assert.deepEqual([chrome.windowIndexAt(31, 380, 3), chrome.windowIndexAt(30, 380, 3), chrome.windowIndexAt(71, 380, 3)], [0, null, 1]); + // Selected, its tab's outline continues the frame's left side straight + // down: the corner is square and the content's corner whole. + assert.deepEqual([px(31, 360), px(31, 365), px(32, 365)], [48, 48, 255]); + assert.deepEqual([at(31, 366), at(31, 370)], [150, 150]); + // Focused, the tab fills from the side. + state.focus = 'sidebar'; + ({ at } = paint(chrome)); + assert.equal(at(31, 370), 255); + // With another window selected the corner rounds again, and the separator + // starts where its curve ends; the launcher's cell stays at the side. + state.focus = 'window'; state.selectedIndex = 1; + ({ px, at } = paint(chrome)); + assert.deepEqual([px(31, 365), px(32, 365), at(35, 366), at(36, 366)], [0, 0, 1, 40]); + assert.equal(chrome.windowIndexAt(31, 380, 3), 0); + // Scrolled past the launcher, the cells keep the left chevron's margin. + const scrolled = chromeLayer(g, { windows: 20 }); + scrolled.state.selectedIndex = 19; + ({ px } = paint(scrolled.chrome)); + assert.equal(scrolled.chrome.windowIndexAt(35, 380, 20), null); + assert.notEqual(scrolled.chrome.windowIndexAt(41, 380, 20), null); + assert.equal(px(31, 365), 0); +}); + test('the status bar can join a bottom app switcher, and windows grow into the top bar', () => { const g = geometry(); g.settings.statusBarPositionSetting.value = 'switcher'; diff --git a/tests/icon-grid.test.cjs b/tests/icon-grid.test.cjs index 79e78324..1b7b00fb 100644 --- a/tests/icon-grid.test.cjs +++ b/tests/icon-grid.test.cjs @@ -122,6 +122,20 @@ function shown(image, at) { return withClock(at, () => Array.from(image.withDrawsBaked().pixels, (v) => Math.min(15, (v + 8) >> 4))); } +test('a box topped at the band inset less the highlight inset pads the first row band evenly', () => { + // The launcher's root grid (launcher-app.ts ROOT_GRID_TOP) relies on this. + const { grid } = makeGrid(); + const { ICON_GRID_BAND_INSET_X: insetX, ICON_GRID_HIGHLIGHT_INSET_Y: insetY } = loadIconGrid(); + const image = paint(grid, 1000, { x: 0, y: insetX - insetY, width: 500, height: 190 }); + const stroke = build('ui/menu-core').MENU_HIGHLIGHT_STROKE; + let left = 500, right = -1, top = 200; + image.pixels.forEach((v, i) => { + if (v !== stroke) return; + left = Math.min(left, i % 500); right = Math.max(right, i % 500); top = Math.min(top, (i / 500) | 0); + }); + assert.deepEqual([top, left, 500 - 1 - right], [insetX, insetX, insetX]); +}); + test('rows keep their content height instead of stretching, and the next row peeks clipped', () => { assert.equal(metrics.iconGridMinRowHeight({ lineHeight: LINE_HEIGHT }, 44, 2), ROW_H); const { grid } = makeGrid({ items: Array.from({ length: 15 }, (_, i) => `item${i}`) });