forked from Blendman974/faceclaw
Glanceboard has a 2x3 layout option
This commit is contained in:
1 parent
bed21c9a5f
commit
17274746a7
8 files changed
+234
-36
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { onAnySettingChanged } from "../../ui/dashboard-settings";
|
||||
import { glanceShowLinesSetting, glanceSlotSettings } from "./glanceboard-settings";
|
||||
import { QUADRANT_LAYOUT, resolveGlanceRegions, slotDividers, type GlanceLayout, type GlanceRegion } from "./layout";
|
||||
import { glanceLayout, glanceShowLinesSetting, glanceSlotSettings } from "./glanceboard-settings";
|
||||
import { resolveGlanceRegions, slotDividers, type GlanceLayout, type GlanceRegion } from "./layout";
|
||||
import { type GlanceWidget } from "./widget";
|
||||
import { findGlanceWidget, glanceWidgetSpans } from "./widgets";
|
||||
|
||||
@@ -27,11 +27,18 @@ export class GlanceBoard {
|
||||
private regions: LiveRegion[] = [];
|
||||
private started = false;
|
||||
private unsubscribeSettings: (() => void) | null = null;
|
||||
private currentLayout: GlanceLayout;
|
||||
|
||||
constructor(
|
||||
private readonly requestRender: () => void,
|
||||
readonly layout: GlanceLayout = QUADRANT_LAYOUT,
|
||||
) {}
|
||||
private readonly fixedLayout?: GlanceLayout,
|
||||
) {
|
||||
this.currentLayout = fixedLayout ?? glanceLayout();
|
||||
}
|
||||
|
||||
get layout(): GlanceLayout {
|
||||
return this.currentLayout;
|
||||
}
|
||||
|
||||
get width(): number {
|
||||
return this.layout.width;
|
||||
@@ -65,9 +72,12 @@ export class GlanceBoard {
|
||||
/** Rebuild the live regions from the settings, keeping widgets whose region is unchanged. */
|
||||
private applySlotSettings(): void {
|
||||
if (!this.started) return;
|
||||
const layout = this.fixedLayout ?? glanceLayout();
|
||||
const layoutChanged = layout !== this.currentLayout;
|
||||
this.currentLayout = layout;
|
||||
const previous = new Map(this.regions.map((live) => [live.key, live]));
|
||||
const next: LiveRegion[] = [];
|
||||
let changed = false;
|
||||
let changed = layoutChanged;
|
||||
for (const region of this.currentRegions()) {
|
||||
const key = regionKey(region);
|
||||
const kept = previous.get(key);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { enumSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
|
||||
import { enumSettingMenuItem, onAnySettingChanged, toggleSettingMenuItem } from "../../ui/dashboard-settings";
|
||||
import { type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { drawSelectionHighlight, MenuLayer, openModalMenu, type MenuItem } from "../../ui/menu";
|
||||
@@ -12,6 +12,8 @@ import { GlanceBoard } from "./board";
|
||||
import {
|
||||
clearConflictingSlots,
|
||||
glanceboardEnabledSetting,
|
||||
glanceLayout,
|
||||
glanceLayoutSetting,
|
||||
glanceShowLinesSetting,
|
||||
glanceShowOnHeadTiltSetting,
|
||||
glanceShowOnLongPressSetting,
|
||||
@@ -20,7 +22,7 @@ import {
|
||||
glanceTapDurationSetting,
|
||||
type GlanceSlotChoice,
|
||||
} from "./glanceboard-settings";
|
||||
import { QUADRANT_LAYOUT, resolveGlanceRegions, slotDividers } from "./layout";
|
||||
import { resolveGlanceRegions, slotDividers } from "./layout";
|
||||
import { glanceWidgetSpans } from "./widgets";
|
||||
|
||||
export const GLANCEBOARD_WINDOW_ID = "glanceboard";
|
||||
@@ -49,24 +51,33 @@ function pageMenuLayout(width: number) {
|
||||
* and the menu (enable toggle, live preview, slot contents, settings). Right
|
||||
* half: a scaled preview of the board's slots with their dividers and the
|
||||
* name of the widget in each. "Select Contents" moves focus into that
|
||||
* preview, where scroll picks a quadrant and a tap opens the picker for it;
|
||||
* preview, where scroll picks a slot and a tap opens the picker for it;
|
||||
* a double-tap returns focus to the menu.
|
||||
*/
|
||||
class GlanceboardHomeLayer implements Layer {
|
||||
private menu: MenuLayer | null = null;
|
||||
private menuTop = 0;
|
||||
private menuHeight = 0;
|
||||
private focus: "menu" | "preview" = "menu";
|
||||
private selectedSlot = 0;
|
||||
|
||||
constructor(private readonly setPreviewVisible: (visible: boolean) => void) {}
|
||||
|
||||
private currentMenu(ctx: LayerContext, menuTop: number): MenuLayer {
|
||||
if (!this.menu || this.menuTop !== menuTop) {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
if (!this.menu || this.menuTop !== menuTop || this.menuHeight !== height) {
|
||||
const half = (width / 2) | 0;
|
||||
const items: MenuItem[] = [
|
||||
toggleSettingMenuItem(glanceboardEnabledSetting),
|
||||
{
|
||||
label: "Preview",
|
||||
onSelect: (menuCtx) => menuCtx.stack.push(new GlancePreviewLayer(() => menuCtx.actions.requestRender())),
|
||||
onSelect: (menuCtx) => {
|
||||
menuCtx.stack.push(new GlancePreviewLayer(
|
||||
() => menuCtx.actions.requestRender(),
|
||||
() => this.setPreviewVisible(false),
|
||||
));
|
||||
this.setPreviewVisible(true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Select Contents",
|
||||
@@ -80,6 +91,7 @@ class GlanceboardHomeLayer implements Layer {
|
||||
},
|
||||
];
|
||||
this.menuTop = menuTop;
|
||||
this.menuHeight = height;
|
||||
this.menu = new MenuLayer(null, items, {
|
||||
x: 8, y: menuTop, width: half - 16,
|
||||
showBorder: false, minHeight: 0, maxHeight: height - menuTop,
|
||||
@@ -92,9 +104,10 @@ class GlanceboardHomeLayer implements Layer {
|
||||
private previewRect(width: number, height: number): { x: number; y: number; width: number; height: number } {
|
||||
const half = (width / 2) | 0;
|
||||
const availableWidth = width - half - 2 * PREVIEW_MARGIN;
|
||||
const scale = Math.min(availableWidth / QUADRANT_LAYOUT.width, (height - 2 * PREVIEW_MARGIN) / QUADRANT_LAYOUT.height);
|
||||
const previewWidth = Math.round(QUADRANT_LAYOUT.width * scale);
|
||||
const previewHeight = Math.round(QUADRANT_LAYOUT.height * scale);
|
||||
const layout = glanceLayout();
|
||||
const scale = Math.min(availableWidth / layout.width, (height - 2 * PREVIEW_MARGIN) / layout.height);
|
||||
const previewWidth = Math.round(layout.width * scale);
|
||||
const previewHeight = Math.round(layout.height * scale);
|
||||
return {
|
||||
x: half + PREVIEW_MARGIN + (((availableWidth - previewWidth) / 2) | 0),
|
||||
y: ((height - previewHeight) / 2) | 0,
|
||||
@@ -123,6 +136,7 @@ class GlanceboardHomeLayer implements Layer {
|
||||
const menuCtx: LayerContext = { ...ctx, stack: Object.assign(Object.create(ctx.stack), { isFocused: () => menuFocused }) };
|
||||
menu.paint(menuCtx, () => image);
|
||||
|
||||
this.selectedSlot = Math.min(this.selectedSlot, glanceLayout().slots.length - 1);
|
||||
const preview = this.previewRect(width, height);
|
||||
drawSlotPreview(image, preview, {
|
||||
selectedSlot: this.selectedSlot,
|
||||
@@ -133,7 +147,8 @@ class GlanceboardHomeLayer implements Layer {
|
||||
|
||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
if (this.focus === "preview") {
|
||||
const slotCount = QUADRANT_LAYOUT.slots.length;
|
||||
const slotCount = glanceLayout().slots.length;
|
||||
this.selectedSlot = Math.min(this.selectedSlot, slotCount - 1);
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
this.selectedSlot = (this.selectedSlot + slotCount - 1) % slotCount;
|
||||
@@ -166,7 +181,7 @@ class GlanceboardHomeLayer implements Layer {
|
||||
* The board's slots scaled into `rect`: dividers (full brightness, or the
|
||||
* dimmest dotted line when "Show lines" is off), the widget name centred in
|
||||
* each region (a merged double-height region has one name and no line
|
||||
* across it), and the selected quadrant highlighted.
|
||||
* across it), and the selected slot highlighted.
|
||||
*/
|
||||
function drawSlotPreview(
|
||||
image: GrayImage,
|
||||
@@ -174,7 +189,7 @@ function drawSlotPreview(
|
||||
options: { selectedSlot: number; selectionFocused: boolean },
|
||||
): void {
|
||||
const font = getDefaultSmallFont();
|
||||
const layout = QUADRANT_LAYOUT;
|
||||
const layout = glanceLayout();
|
||||
const settings = glanceSlotSettings(layout);
|
||||
const choices = settings.map((setting) => setting.get());
|
||||
const regions = resolveGlanceRegions(layout, choices, glanceWidgetSpans);
|
||||
@@ -232,14 +247,15 @@ function drawDottedLine(image: GrayImage, x0: number, y0: number, x1: number, y1
|
||||
|
||||
/** The picker for one slot: every widget, the current one marked; choosing applies the one-per-board rule. */
|
||||
function openSlotPicker(ctx: LayerContext, slotIndex: number): void {
|
||||
const setting = glanceSlotSettings(QUADRANT_LAYOUT)[slotIndex];
|
||||
const layout = glanceLayout();
|
||||
const setting = glanceSlotSettings(layout)[slotIndex];
|
||||
if (!setting) return;
|
||||
const current = setting.get();
|
||||
const items: MenuItem[] = setting.values.map((value) => ({
|
||||
label: setting.displayValue(value),
|
||||
onSelect: (menuCtx) => {
|
||||
setting.set(value);
|
||||
clearConflictingSlots(QUADRANT_LAYOUT, slotIndex, value);
|
||||
clearConflictingSlots(layout, slotIndex, value);
|
||||
menuCtx.stack.pop();
|
||||
},
|
||||
render: ({ image, x, y }) => {
|
||||
@@ -249,7 +265,7 @@ function openSlotPicker(ctx: LayerContext, slotIndex: number): void {
|
||||
openModalMenu(ctx, setting.label, items, Math.max(0, setting.values.indexOf(current)));
|
||||
}
|
||||
|
||||
/** Settings: which sleep gestures show the board, for how long, and the slot lines. */
|
||||
/** Settings: layout, sleep gestures, duration, and slot lines. */
|
||||
class GlanceSettingsLayer implements Layer {
|
||||
private menu: MenuLayer | null = null;
|
||||
|
||||
@@ -257,6 +273,7 @@ class GlanceSettingsLayer implements Layer {
|
||||
if (!this.menu) {
|
||||
const { width } = ctx.stack.getBaseSize();
|
||||
const items: MenuItem[] = [
|
||||
enumSettingMenuItem(glanceLayoutSetting),
|
||||
enumSettingMenuItem(glanceTapDurationSetting),
|
||||
toggleSettingMenuItem(glanceShowOnLongPressSetting),
|
||||
toggleSettingMenuItem(glanceShowOnHeadTiltSetting),
|
||||
@@ -280,7 +297,7 @@ class GlanceSettingsLayer implements Layer {
|
||||
class GlancePreviewLayer implements Layer {
|
||||
private readonly board: GlanceBoard;
|
||||
|
||||
constructor(requestRender: () => void) {
|
||||
constructor(requestRender: () => void, private readonly onClose: () => void) {
|
||||
this.board = new GlanceBoard(requestRender);
|
||||
this.board.start();
|
||||
}
|
||||
@@ -302,27 +319,40 @@ class GlancePreviewLayer implements Layer {
|
||||
|
||||
onRemoved(): void {
|
||||
this.board.stop();
|
||||
this.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
export function createGlanceboardAppWindow(options: InProcessAppOptions): InProcessWindow {
|
||||
return createInProcessWindow({
|
||||
let previewVisible = false;
|
||||
const heightMode = () => previewVisible && glanceLayoutSetting.get() === "2x3" ? "max" as const : "medium" as const;
|
||||
let unsubscribeSettings: (() => void) | undefined;
|
||||
const app = createInProcessWindow({
|
||||
appId: "glanceboard",
|
||||
windowId: GLANCEBOARD_WINDOW_ID,
|
||||
title: "Glanceboard",
|
||||
iconLetter: "Gb",
|
||||
icon: "eye",
|
||||
closeable: true,
|
||||
// 576x288: the board's own size, so the preview is pixel-exact.
|
||||
heightMode: "medium",
|
||||
// Settings and the contents picker stay in the default 576x288 viewport;
|
||||
// only the live six-slot preview needs the taller window.
|
||||
heightMode: heightMode(),
|
||||
actions: options.actions,
|
||||
// Not wrapped in YieldAtRootLayer: the home page routes double-click
|
||||
// itself (preview focus -> menu focus, menu focus -> sidebar).
|
||||
baseLayer: new GlanceboardHomeLayer(),
|
||||
baseLayer: new GlanceboardHomeLayer((visible) => {
|
||||
previewVisible = visible;
|
||||
app.setHeightMode(heightMode());
|
||||
}),
|
||||
submitFrame: options.submitFrame,
|
||||
setSurfaceVisible: options.setSurfaceVisible,
|
||||
removeSurface: options.removeSurface,
|
||||
reconfigureSurface: options.reconfigureSurface,
|
||||
onClosed: options.onClosed,
|
||||
onClosed: () => {
|
||||
unsubscribeSettings?.();
|
||||
options.onClosed();
|
||||
},
|
||||
});
|
||||
unsubscribeSettings = onAnySettingChanged(() => app.setHeightMode(heightMode()));
|
||||
return app;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ConfigSettingBoolean, ConfigSettingEnum } from "../../ui/dashboard-settings";
|
||||
import { QUADRANT_LAYOUT, slotsVerticallyAdjacent, type GlanceLayout } from "./layout";
|
||||
import { QUADRANT_LAYOUT, SIX_SLOT_LAYOUT, slotsVerticallyAdjacent, type GlanceLayout } from "./layout";
|
||||
import { type GlanceWidgetId } from "./widget";
|
||||
import { glanceWidgetSpans } from "./widgets";
|
||||
|
||||
@@ -27,6 +27,19 @@ export function glanceSlotChoiceLabel(choice: GlanceSlotChoice): string {
|
||||
*/
|
||||
const DEFAULT_QUADRANT_CHOICES: readonly GlanceSlotChoice[] = ["system-card", "calendar", "music", "calendar"];
|
||||
|
||||
export const glanceLayoutSetting = new ConfigSettingEnum<"2x2" | "2x3">({
|
||||
id: "glanceboard-layout",
|
||||
label: "Layout",
|
||||
storageKey: "glanceboard.layout",
|
||||
defaultValue: "2x2",
|
||||
values: ["2x2", "2x3"],
|
||||
description: "Choose two columns with two or three rows of widgets.",
|
||||
});
|
||||
|
||||
export function glanceLayout(): GlanceLayout {
|
||||
return glanceLayoutSetting.get() === "2x3" ? SIX_SLOT_LAYOUT : QUADRANT_LAYOUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether sleep-time gestures show the board at all. Off restores the plain
|
||||
* behaviour: a tap, hold or head-tilt while asleep does nothing (a head-tilt
|
||||
@@ -100,17 +113,19 @@ export const glanceShowLinesSetting = new ConfigSettingBoolean({
|
||||
});
|
||||
|
||||
/**
|
||||
* One picker per layout slot, keyed by layout id and slot index so a future
|
||||
* layout gets its own stored choices rather than inheriting the quadrants'.
|
||||
* Both grid sizes share the original storage keys so changing row count
|
||||
* preserves the first four choices and remembers the hidden bottom row.
|
||||
*/
|
||||
export function glanceSlotSettings(layout: GlanceLayout = QUADRANT_LAYOUT): ConfigSettingEnum<GlanceSlotChoice>[] {
|
||||
export function glanceSlotSettings(layout: GlanceLayout = glanceLayout()): ConfigSettingEnum<GlanceSlotChoice>[] {
|
||||
const grid = layout === QUADRANT_LAYOUT || layout === SIX_SLOT_LAYOUT;
|
||||
const storageId = grid ? QUADRANT_LAYOUT.id : layout.id;
|
||||
return layout.slots.map(
|
||||
(slot, index) =>
|
||||
new ConfigSettingEnum<GlanceSlotChoice>({
|
||||
id: `glanceboard-${layout.id}-slot-${index}`,
|
||||
label: slot.label,
|
||||
storageKey: `glanceboard.${layout.id}.slot.${index}`,
|
||||
defaultValue: (layout === QUADRANT_LAYOUT ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none",
|
||||
storageKey: `glanceboard.${storageId}.slot.${index}`,
|
||||
defaultValue: (grid ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none",
|
||||
values: SLOT_CHOICES,
|
||||
formatValue: glanceSlotChoiceLabel,
|
||||
description: `Which widget fills the ${slot.label.toLowerCase()} slot of the Glanceboard.`,
|
||||
@@ -129,9 +144,13 @@ export function clearConflictingSlots(layout: GlanceLayout, changedIndex: number
|
||||
const settings = glanceSlotSettings(layout);
|
||||
const spans = glanceWidgetSpans(choice);
|
||||
const cleared: number[] = [];
|
||||
let keptPartner = false;
|
||||
settings.forEach((setting, index) => {
|
||||
if (index === changedIndex || setting.get() !== choice) return;
|
||||
if (spans && slotsVerticallyAdjacent(layout, changedIndex, index)) return;
|
||||
if (spans && !keptPartner && slotsVerticallyAdjacent(layout, changedIndex, index)) {
|
||||
keptPartner = true;
|
||||
return;
|
||||
}
|
||||
setting.set("none");
|
||||
cleared.push(index);
|
||||
});
|
||||
|
||||
@@ -3,12 +3,12 @@ import { GlanceBoard } from "./board";
|
||||
import { createGlanceboardAppWindow, GLANCEBOARD_SURFACE_ID, GLANCEBOARD_WINDOW_ID } from "./glanceboard-app";
|
||||
import {
|
||||
glanceboardEnabledSetting,
|
||||
glanceLayout,
|
||||
glanceShowOnHeadTiltSetting,
|
||||
glanceShowOnLongPressSetting,
|
||||
glanceShowOnTap,
|
||||
glanceTapTimeoutMs,
|
||||
} from "./glanceboard-settings";
|
||||
import { QUADRANT_LAYOUT } from "./layout";
|
||||
|
||||
const glanceboardApp: AppDefinition = {
|
||||
appId: "glanceboard",
|
||||
@@ -16,13 +16,16 @@ const glanceboardApp: AppDefinition = {
|
||||
icon: "eye",
|
||||
launch: (ctx) => ctx.launchInProcessApp(GLANCEBOARD_WINDOW_ID, GLANCEBOARD_SURFACE_ID, createGlanceboardAppWindow),
|
||||
glanceboard: {
|
||||
size: { width: QUADRANT_LAYOUT.width, height: QUADRANT_LAYOUT.height },
|
||||
get size() {
|
||||
const layout = glanceLayout();
|
||||
return { width: layout.width, height: layout.height };
|
||||
},
|
||||
isEnabled: () => glanceboardEnabledSetting.get(),
|
||||
showOnTap: glanceShowOnTap,
|
||||
tapTimeoutMs: glanceTapTimeoutMs,
|
||||
showOnLongPress: () => glanceShowOnLongPressSetting.get(),
|
||||
showOnHeadTilt: () => glanceShowOnHeadTiltSetting.get(),
|
||||
createBoard: (requestRender) => new GlanceBoard(requestRender, QUADRANT_LAYOUT),
|
||||
createBoard: (requestRender) => new GlanceBoard(requestRender),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,20 @@ export const QUADRANT_LAYOUT: GlanceLayout = {
|
||||
],
|
||||
};
|
||||
|
||||
/** Six 288x144 slots: the same first two rows, plus a third at the bottom. */
|
||||
export const SIX_SLOT_LAYOUT: GlanceLayout = {
|
||||
id: "six-slots",
|
||||
width: GLANCEBOARD_WIDTH,
|
||||
height: 432,
|
||||
slots: [
|
||||
...QUADRANT_LAYOUT.slots.slice(0, 2),
|
||||
{ label: "Middle left", rect: { x: 0, y: 144, width: 288, height: 144 } },
|
||||
{ label: "Middle right", rect: { x: 288, y: 144, width: 288, height: 144 } },
|
||||
{ label: "Bottom left", rect: { x: 0, y: 288, width: 288, height: 144 } },
|
||||
{ label: "Bottom right", rect: { x: 288, y: 288, width: 288, height: 144 } },
|
||||
],
|
||||
};
|
||||
|
||||
/** Whether two slots stack vertically with matching width (one region if merged). */
|
||||
export function slotsVerticallyAdjacent(layout: GlanceLayout, a: number, b: number): boolean {
|
||||
const first = layout.slots[a]?.rect;
|
||||
|
||||
Reference in new issue
Block a user