mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-29 13:03:11 +00:00
Unify vertical position and display mode settings; add to onboarding
This commit is contained in:
1 parent
6b1e64c5ac
commit
5a9ca08921
36 files changed
+810
-574
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { G2_LENS_WIDTH, type GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { appSwitcherPositionSetting, statusBarPositionSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
|
||||
import { appSwitcherPositionSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
|
||||
import type { InputEvent } from "../../ui/gestures";
|
||||
import { MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "../../ui/menu-core";
|
||||
import { MIN_WINDOW_HEIGHT, SIDEBAR_WIDTH, SWITCHER_ROW_HEIGHT, TOP_BAR_HEIGHT } from "../../ui/shell/geometry";
|
||||
import { MIN_WINDOW_HEIGHT } from "../../ui/shell/geometry";
|
||||
import { AREA_OUTLINE, Diagram, drawLayout, LAYOUT_AREA_HEIGHT } from "./layout-diagram";
|
||||
import { onboardingFont } from "./onboarding-fonts";
|
||||
import { drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
|
||||
@@ -10,8 +11,6 @@ const CONTENT_GAP = 10;
|
||||
const BOTTOM_MARGIN = 8;
|
||||
/** Diagram width as a fraction of the display's: the most a diagram is drawn at. */
|
||||
const DIAGRAM_SCALE = 0.4;
|
||||
/** The real-display area a diagram covers: a 288px window band and a bottom switcher row under it. */
|
||||
const DIAGRAM_AREA_HEIGHT = MIN_WINDOW_HEIGHT + SWITCHER_ROW_HEIGHT;
|
||||
/** Padding inside a cell's selection box, round the diagram and its caption. */
|
||||
const CELL_PADDING = 8;
|
||||
const CAPTION_GAP = 4;
|
||||
@@ -32,12 +31,12 @@ export function layoutHasDepth(position: AppSwitcherPosition): boolean {
|
||||
* The app switcher position, as a 2×2 grid of captioned diagrams of each
|
||||
* layout, Bottom (recommended, and selected at first) and Popup on top;
|
||||
* swipes move through them in reading order, a tap saves the selected one.
|
||||
* The page is fullscreen, so the diagrams get 40% of the display's width
|
||||
* The page is immersive, so the diagrams get 40% of the display's width
|
||||
* each. Choosing a layout reflows open windows (the dashboard controller
|
||||
* watches the setting).
|
||||
*/
|
||||
export class LayoutPage implements OnboardingPage {
|
||||
readonly fullscreen = true;
|
||||
readonly immersive = true;
|
||||
/** Kept across visits, so going back returns to the last choice. */
|
||||
private selected = LAYOUT_ORDER.indexOf(RECOMMENDED_LAYOUT);
|
||||
|
||||
@@ -54,11 +53,11 @@ export class LayoutPage implements OnboardingPage {
|
||||
// Short of DIAGRAM_SCALE only where two rows of cells wouldn't fit.
|
||||
const scale = Math.min(
|
||||
DIAGRAM_SCALE,
|
||||
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / DIAGRAM_AREA_HEIGHT,
|
||||
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / LAYOUT_AREA_HEIGHT,
|
||||
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / G2_LENS_WIDTH,
|
||||
);
|
||||
const diagramWidth = Math.round(G2_LENS_WIDTH * scale);
|
||||
const diagramHeight = Math.round(DIAGRAM_AREA_HEIGHT * scale);
|
||||
const diagramHeight = Math.round(LAYOUT_AREA_HEIGHT * scale);
|
||||
const cellWidth = diagramWidth + 2 * CELL_PADDING;
|
||||
const cellHeight = diagramHeight + 2 * CELL_PADDING + captionHeight;
|
||||
const left = Math.round((image.width - 2 * cellWidth - COLUMN_GAP) / 2);
|
||||
@@ -103,157 +102,13 @@ export class LayoutPage implements OnboardingPage {
|
||||
}
|
||||
}
|
||||
|
||||
// Diagram brightnesses: brighter than the real chrome's, which the diagrams
|
||||
// shrink to a few pixels.
|
||||
const AREA_OUTLINE = 30;
|
||||
const CHROME_LINE = 100;
|
||||
const WINDOW_FRAME = 140;
|
||||
const ICON = 160;
|
||||
const SELECTED_ICON = 230;
|
||||
const STATUS = 140;
|
||||
const CONTENT = 110;
|
||||
const CONTENT_TITLE = 170;
|
||||
/** Window content under a popup switcher, which dims it. */
|
||||
const DIM = 0.5;
|
||||
|
||||
/**
|
||||
* Draws in real-display pixels, scaled into a cell: the DIAGRAM_AREA_HEIGHT
|
||||
* rows from the diagram's top, or from `top` rows down (see from).
|
||||
* A layout's diagram: the 288px band, with the popup switcher open. Only a
|
||||
* bottom switcher row takes rows under the band; without one, the band sits
|
||||
* centred in their place, as the band and row share the screen's slack.
|
||||
*/
|
||||
class Diagram {
|
||||
constructor(
|
||||
private readonly image: GrayImage,
|
||||
private readonly x: number,
|
||||
private readonly y: number,
|
||||
private readonly scale: number,
|
||||
private readonly top = 0,
|
||||
) {}
|
||||
|
||||
/** The same diagram with its row 0 `top` rows down. */
|
||||
from(top: number): Diagram {
|
||||
return new Diagram(this.image, this.x, this.y, this.scale, top);
|
||||
}
|
||||
|
||||
private box(x: number, y: number, width: number, height: number) {
|
||||
y += this.top;
|
||||
const left = this.x + Math.round(x * this.scale), top = this.y + Math.round(y * this.scale);
|
||||
return {
|
||||
x: left,
|
||||
y: top,
|
||||
width: Math.max(1, this.x + Math.round((x + width) * this.scale) - left),
|
||||
height: Math.max(1, this.y + Math.round((y + height) * this.scale) - top),
|
||||
};
|
||||
}
|
||||
|
||||
fill(x: number, y: number, width: number, height: number, value: number, radius = 0): void {
|
||||
const box = this.box(x, y, width, height);
|
||||
if (radius) this.image.fillRoundedRect(box.x, box.y, box.width, box.height, value, Math.max(1, Math.round(radius * this.scale)));
|
||||
else this.image.fillRect(box.x, box.y, box.width, box.height, value);
|
||||
}
|
||||
|
||||
outline(x: number, y: number, width: number, height: number, value: number, radius = 0): void {
|
||||
const box = this.box(x, y, width, height);
|
||||
this.image.drawRoundedRect(box.x, box.y, box.width, box.height, value, Math.max(0, Math.round(radius * this.scale)));
|
||||
}
|
||||
|
||||
/** A one-pixel line along a real-pixel row (horizontal) or column. */
|
||||
hline(x: number, y: number, width: number, value: number): void {
|
||||
const box = this.box(x, y, width, 1);
|
||||
this.image.fillRect(box.x, box.y, box.width, 1, value);
|
||||
}
|
||||
|
||||
vline(x: number, y: number, height: number, value: number): void {
|
||||
const box = this.box(x, y, 1, height);
|
||||
this.image.fillRect(box.x, box.y, 1, box.height, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A layout as the real chrome lays it out (geometry.ts, chrome-layer.ts),
|
||||
* to scale and simplified: the window band with its status bar and frame,
|
||||
* and the switcher with a few icons, the first selected. Status bar
|
||||
* placement follows the current setting. Only a bottom switcher row takes
|
||||
* rows under the band; without one, the band sits centred in their place,
|
||||
* as the band and row share the screen's slack.
|
||||
*/
|
||||
function drawLayoutDiagram(area: Diagram, position: AppSwitcherPosition): void {
|
||||
area.outline(0, 0, G2_LENS_WIDTH, DIAGRAM_AREA_HEIGHT, AREA_OUTLINE, 12);
|
||||
const d = position === "bottom" ? area : area.from((DIAGRAM_AREA_HEIGHT - MIN_WINDOW_HEIGHT) / 2);
|
||||
const statusAtBottom = statusBarPositionSetting.get() === "bottom";
|
||||
const windowLeft = SIDEBAR_WIDTH / 2, windowWidth = G2_LENS_WIDTH - SIDEBAR_WIDTH;
|
||||
switch (position) {
|
||||
case "left":
|
||||
case "right": {
|
||||
const stripLeft = position === "left" ? 0 : G2_LENS_WIDTH - SIDEBAR_WIDTH;
|
||||
const contentLeft = position === "left" ? SIDEBAR_WIDTH : 0;
|
||||
drawStatusBar(d, contentLeft, 0, windowWidth, true);
|
||||
drawContent(d, contentLeft, TOP_BAR_HEIGHT, windowWidth, MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT, 1);
|
||||
const separator = position === "left" ? SIDEBAR_WIDTH - 1 : stripLeft;
|
||||
d.vline(separator, TOP_BAR_HEIGHT, MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT, CHROME_LINE);
|
||||
// One column of icons against the separator.
|
||||
const column = position === "left" ? SIDEBAR_WIDTH - 36 : stripLeft;
|
||||
for (let slot = 0; slot < 4; slot++) drawIcon(d, column + 2, TOP_BAR_HEIGHT + 10 + slot * 40, slot === 0);
|
||||
return;
|
||||
}
|
||||
case "bottom": {
|
||||
// With the status bar in the row, the window's header is just the frame's top.
|
||||
const contentTop = statusAtBottom ? 1 : TOP_BAR_HEIGHT;
|
||||
if (!statusAtBottom) drawStatusBar(d, windowLeft, 0, windowWidth, false);
|
||||
drawContent(d, windowLeft, contentTop, windowWidth, MIN_WINDOW_HEIGHT - contentTop, 1);
|
||||
d.outline(windowLeft - 1, contentTop - 1, windowWidth + 2, MIN_WINDOW_HEIGHT - contentTop + 2, WINDOW_FRAME, 8);
|
||||
for (let slot = 0; slot < 4; slot++) drawIcon(d, windowLeft + 1 + slot * 40, MIN_WINDOW_HEIGHT + 2, slot === 0);
|
||||
if (statusAtBottom) drawStatusItems(d, windowLeft + windowWidth, MIN_WINDOW_HEIGHT + 4);
|
||||
return;
|
||||
}
|
||||
case "popup": {
|
||||
const statusTop = statusAtBottom ? MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT : 0;
|
||||
const contentTop = statusAtBottom ? 1 : TOP_BAR_HEIGHT;
|
||||
const contentHeight = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 1;
|
||||
drawStatusBar(d, windowLeft, statusTop, windowWidth, false);
|
||||
drawContent(d, windowLeft, contentTop, windowWidth, contentHeight, DIM);
|
||||
d.outline(windowLeft - 1, contentTop - 1, windowWidth + 2, contentHeight + 2, WINDOW_FRAME, 8);
|
||||
// The popup: a row of icons over the selected window's title, centred on the content.
|
||||
const box = { width: 272, height: 98 };
|
||||
const boxLeft = (G2_LENS_WIDTH - box.width) / 2;
|
||||
const boxTop = contentTop + (contentHeight - box.height) / 2;
|
||||
d.fill(boxLeft, boxTop, box.width, box.height, 0);
|
||||
d.outline(boxLeft, boxTop, box.width, box.height, WINDOW_FRAME);
|
||||
const iconsLeft = boxLeft + (box.width - (3 * 48 - 4)) / 2;
|
||||
for (let slot = 0; slot < 3; slot++) drawIcon(d, iconsLeft + slot * 48 + 6, boxTop + 18, slot === 0);
|
||||
d.fill(G2_LENS_WIDTH / 2 - 50, boxTop + 70, 100, 12, STATUS, 6);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A status bar along a window's top or bottom edge; `divider` draws its line toward the window. */
|
||||
function drawStatusBar(d: Diagram, x: number, y: number, width: number, divider: boolean): void {
|
||||
if (divider) d.hline(x, y + TOP_BAR_HEIGHT - 1, width, CHROME_LINE);
|
||||
drawStatusItems(d, x + width, y);
|
||||
}
|
||||
|
||||
/** Notification icons, a battery and the clock, ending at `right`, in a status bar's 28 rows from `top`. */
|
||||
function drawStatusItems(d: Diagram, right: number, top: number): void {
|
||||
d.fill(right - 64, top + 7, 56, 14, STATUS, 4);
|
||||
d.outline(right - 108, top + 8, 32, 12, STATUS, 2);
|
||||
d.outline(right - 148, top + 4, 20, 20, CHROME_LINE, 4);
|
||||
d.outline(right - 176, top + 4, 20, 20, CHROME_LINE, 4);
|
||||
}
|
||||
|
||||
/** A switcher icon (32px); the selected one filled, as the switcher's selection tab is. */
|
||||
function drawIcon(d: Diagram, x: number, y: number, selected: boolean): void {
|
||||
if (selected) d.fill(x, y, 32, 32, SELECTED_ICON, 6);
|
||||
else d.outline(x, y, 32, 32, ICON, 6);
|
||||
}
|
||||
|
||||
/** Stand-in window content: a title and list rows, the first selected. */
|
||||
function drawContent(d: Diagram, x: number, y: number, width: number, height: number, brightness: number): void {
|
||||
const rowWidths = [width - 60, 300, 360, 240];
|
||||
d.fill(x + 18, y + 14, 150, 18, CONTENT_TITLE * brightness, 6);
|
||||
d.outline(x + 8, y + 44, width - 16, 34, CONTENT * brightness, 8);
|
||||
for (let row = 0; row < rowWidths.length; row++) {
|
||||
const rowTop = y + 52 + row * 44;
|
||||
if (rowTop + 18 > y + height) break;
|
||||
d.fill(x + 18, rowTop, Math.min(rowWidths[row]!, width - 36), 18, CONTENT * brightness, 6);
|
||||
}
|
||||
function drawLayoutDiagram(d: Diagram, position: AppSwitcherPosition): void {
|
||||
d.outline(0, 0, G2_LENS_WIDTH, LAYOUT_AREA_HEIGHT, AREA_OUTLINE, 12);
|
||||
const top = position === "bottom" ? 0 : (LAYOUT_AREA_HEIGHT - MIN_WINDOW_HEIGHT) / 2;
|
||||
drawLayout(d, position, { top, height: MIN_WINDOW_HEIGHT, fullWidth: false }, true);
|
||||
}
|
||||
Reference in new issue
Block a user