forked from Blendman974/faceclaw
Grouping of glanceboard settings
This commit is contained in:
1 parent
d8a15c5251
commit
2ecb8b64b1
4 files changed
+104
-33
No files matched your search
@@ -5,7 +5,7 @@ import { enumSettingMenuItem, onAnySettingChanged, toggleSettingMenuItem } from
|
||||
import { uiFontOverridePickerMenuItem } from "../../ui/font-picker";
|
||||
import { type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerContext } from "../../ui/layers";
|
||||
import { drawSelectionHighlight, isMenuItemDisabled, MenuLayer, openModalMenu, submenuItem, type MenuItem } from "../../ui/menu";
|
||||
import { drawSelectionHighlight, isMenuItemDisabled, menuHeadingItem, MenuLayer, openModalMenu, submenuItem, type MenuItem } from "../../ui/menu";
|
||||
import { liveHeadPitchFooter } from "../../g2/head-angle";
|
||||
import { headUpControlsAvailable } from "../../native/glasses-controls";
|
||||
import { Menu } from "../../ui/menu-core";
|
||||
@@ -323,34 +323,45 @@ function openSlotPicker(ctx: LayerContext, slotIndex: number): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings: layout, sleep gestures, duration, slot lines, widget font, and
|
||||
* stereo depth, then a row per widget on the board for its own settings.
|
||||
* Settings, in four sections: Layout (the slot grid), Trigger (the sleep
|
||||
* gestures that show the board, and for how long), Display (slot lines,
|
||||
* widget font, stereo depth) and Cards (a row per widget on the board, for
|
||||
* its own settings; left out while the board is empty).
|
||||
*/
|
||||
function openGlanceSettings(ctx: LayerContext): void {
|
||||
const items = (): MenuItem[] => [
|
||||
// The layout decides which slots (and so which widgets) are on the board.
|
||||
enumSettingMenuItem(glanceLayoutSetting, { onChange: () => layer.setItems(items()) }),
|
||||
enumSettingMenuItem(glanceTapDurationSetting),
|
||||
toggleSettingMenuItem(glanceShowOnLongPressSetting),
|
||||
toggleSettingMenuItem(glanceShowOnHeadTiltSetting),
|
||||
enumSettingMenuItem(glanceTiltTimeoutSetting),
|
||||
// Only Android can change the glasses' head-up setting (glasses-controls.ts).
|
||||
// The controller's settings listener sends a new angle to the glasses; the
|
||||
// picker shows the head's current angle to choose by.
|
||||
...(headUpControlsAvailable()
|
||||
? [enumSettingMenuItem(glanceAngleSetting, {
|
||||
pickerFooter: liveHeadPitchFooter(() => shell.isWindowVisible(GLANCEBOARD_WINDOW_ID)),
|
||||
})]
|
||||
: []),
|
||||
toggleSettingMenuItem(glanceShowLinesSetting),
|
||||
uiFontOverridePickerMenuItem(glanceFont, {
|
||||
title: "Glanceboard font",
|
||||
description:
|
||||
"Typeface for the Glanceboard's widgets. Same as UI font follows the Font setting in Settings > Customization.",
|
||||
}),
|
||||
enumSettingMenuItem(glanceDepthSetting),
|
||||
...widgetSettingsMenuItems(),
|
||||
];
|
||||
const items = (): MenuItem[] => {
|
||||
const cards = widgetSettingsMenuItems();
|
||||
return [
|
||||
menuHeadingItem("Layout"),
|
||||
// The layout decides which slots (and so which widgets) are on the board.
|
||||
enumSettingMenuItem(glanceLayoutSetting, { onChange: () => layer.setItems(items()) }),
|
||||
|
||||
menuHeadingItem("Trigger"),
|
||||
enumSettingMenuItem(glanceTapDurationSetting),
|
||||
toggleSettingMenuItem(glanceShowOnLongPressSetting),
|
||||
toggleSettingMenuItem(glanceShowOnHeadTiltSetting),
|
||||
enumSettingMenuItem(glanceTiltTimeoutSetting),
|
||||
// Only Android can change the glasses' head-up setting (glasses-controls.ts).
|
||||
// The controller's settings listener sends a new angle to the glasses; the
|
||||
// picker shows the head's current angle to choose by.
|
||||
...(headUpControlsAvailable()
|
||||
? [enumSettingMenuItem(glanceAngleSetting, {
|
||||
pickerFooter: liveHeadPitchFooter(() => shell.isWindowVisible(GLANCEBOARD_WINDOW_ID)),
|
||||
})]
|
||||
: []),
|
||||
|
||||
menuHeadingItem("Display"),
|
||||
toggleSettingMenuItem(glanceShowLinesSetting),
|
||||
uiFontOverridePickerMenuItem(glanceFont, {
|
||||
title: "Glanceboard font",
|
||||
description:
|
||||
"Typeface for the Glanceboard's widgets. Same as UI font follows the Font setting in Settings > Customization.",
|
||||
}),
|
||||
enumSettingMenuItem(glanceDepthSetting),
|
||||
|
||||
...(cards.length ? [menuHeadingItem("Cards"), ...cards] : []),
|
||||
];
|
||||
};
|
||||
const layer = new MenuLayer("Glanceboard settings", items(), PAGE_MENU_LAYOUT);
|
||||
ctx.stack.push(layer);
|
||||
}
|
||||
|
||||
@@ -50,16 +50,26 @@ export const musicShowAlbumArtSetting = new ConfigSettingBoolean({
|
||||
"Show the album art beside the track details. When off, the title, artist, album and progress bar use the full width of the card.",
|
||||
});
|
||||
|
||||
export const musicShowIdleNoteSetting = new ConfigSettingBoolean({
|
||||
id: "glanceboard-music-show-idle-note",
|
||||
label: "Show note when idle",
|
||||
storageKey: "glanceboard.music.showIdleNote",
|
||||
defaultValue: true,
|
||||
description: "Show a dim music note on the card while nothing is playing. When off, the card is left blank.",
|
||||
});
|
||||
|
||||
/** The music card's submenu in Glanceboard > Settings. */
|
||||
export function musicSettingsMenuItems(): MenuItem[] {
|
||||
return [toggleSettingMenuItem(musicShowAlbumArtSetting)];
|
||||
return [toggleSettingMenuItem(musicShowAlbumArtSetting), toggleSettingMenuItem(musicShowIdleNoteSetting)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Now playing: album art (unless turned off), title/artist/album and a
|
||||
* progress bar for the active media session (Apple Music on iOS), the Music
|
||||
* app's header at card size. The media bridge runs for the whole session; the
|
||||
* widget subscribes and ticks once a second only while something is playing.
|
||||
* app's header at card size. With nothing playing the card holds a dim note,
|
||||
* or nothing with that turned off. The media bridge runs for the whole
|
||||
* session; the widget subscribes and ticks once a second only while
|
||||
* something is playing.
|
||||
*/
|
||||
export class MusicWidget implements GlanceWidget {
|
||||
private media: MediaControllerState = mediaControllerBridge.snapshot();
|
||||
@@ -108,8 +118,8 @@ export class MusicWidget implements GlanceWidget {
|
||||
image.drawText(small, PAD, PAD + small.lineHeight + 6, mediaControllerBridge.accessLabel, 140);
|
||||
return;
|
||||
}
|
||||
// Nothing playing: a dim note, centred, and nothing else.
|
||||
const note = idleNoteImage();
|
||||
// Nothing playing: a dim note, centred, and nothing else; or a blank card.
|
||||
const note = musicShowIdleNoteSetting.get() ? idleNoteImage() : null;
|
||||
if (note) image.drawImage(note, ((image.width - note.width) / 2) | 0, ((image.height - note.height) / 2) | 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ const PAGE_TITLE_OFFSET_Y = 2;
|
||||
const PAGE_TITLE_GAP = 4;
|
||||
/** Room a page menu keeps right of its rows for the scrollbar. */
|
||||
const PAGE_SCROLLBAR_GUTTER = 6;
|
||||
/** A heading row's text: dimmer than a row's, brighter than a disabled row's. */
|
||||
const MENU_HEADING_VALUE = 90;
|
||||
|
||||
export type MenuLayout = {
|
||||
/** Stereo depth of the menu surface, including the selected row. */
|
||||
@@ -111,6 +113,12 @@ export type MenuItem = {
|
||||
description?: string;
|
||||
/** Disabled rows stay visible but render dimly and ignore clicks. */
|
||||
disabled?: boolean | (() => boolean);
|
||||
/**
|
||||
* A label for the group of rows after it (see menuHeadingItem). MenuLayer's
|
||||
* highlight skips it; a list that doesn't know headings shows it as a
|
||||
* disabled row.
|
||||
*/
|
||||
heading?: boolean;
|
||||
onSelect: (ctx: LayerContext, menu: MenuLayer) => Promise<void> | void;
|
||||
render?: (args: MenuItemRenderArgs) => void;
|
||||
};
|
||||
@@ -214,6 +222,22 @@ export function submenuItem(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A heading for the rows that follow it, splitting a long menu into sections:
|
||||
* dim capitals in the rows' text column, never selected.
|
||||
*/
|
||||
export function menuHeadingItem(label: string): MenuItem {
|
||||
return {
|
||||
label,
|
||||
heading: true,
|
||||
disabled: true,
|
||||
onSelect: () => {},
|
||||
render: ({ image, x, y, text }) => {
|
||||
image.drawText(getDefaultSmallFont(), x, y + LIST_ROW_TEXT_INSET, text.toUpperCase(), MENU_HEADING_VALUE);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function drawToggleMenuItem(
|
||||
image: GrayImage,
|
||||
font: UiFont,
|
||||
@@ -281,6 +305,7 @@ export class MenuLayer implements Layer {
|
||||
wrap: true,
|
||||
rowGap: 1,
|
||||
getHeight: () => listRowHeight(getDefaultSmallFont()),
|
||||
isSelectable: (item) => !item.heading,
|
||||
draw: ({ image, item, x, y, width, height, selected }) => {
|
||||
const font = getDefaultSmallFont();
|
||||
const disabled = isMenuItemDisabled(item);
|
||||
|
||||
Reference in new issue
Block a user