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);
|
||||
|
||||
@@ -17,7 +17,7 @@ const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4,
|
||||
const menuCore=load('app/ui/menu-core.ts',{
|
||||
'../graphics/image':graphics,'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
|
||||
});
|
||||
const {MenuLayer,TextPageLayer}=load('app/ui/menu.ts',{
|
||||
const {MenuLayer,TextPageLayer,menuHeadingItem}=load('app/ui/menu.ts',{
|
||||
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
|
||||
'../graphics/image':graphics,'../graphics/textwrap':{wrapText:(_font,text)=>text.split('\n')},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font},
|
||||
'../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{},
|
||||
@@ -81,6 +81,31 @@ test('a submenu that replaces its parent menu skips the parent plane and dims th
|
||||
stack.pop();stack.pop();
|
||||
assert.equal(stack.paint().length,2);
|
||||
});
|
||||
test('heading rows label a section and are never selected',async()=>{
|
||||
const picked=[];
|
||||
const row=label=>({label,onSelect(){picked.push(label);}});
|
||||
const layer=new MenuLayer(null,[menuHeadingItem('First'),row('A'),row('B'),menuHeadingItem('Second'),row('C')],
|
||||
{x:0,y:0,width:120,minHeight:150,maxHeight:150,squareCorners:true,showBorder:false});
|
||||
const context={stack:{getBaseSize:()=>({width:120,height:150}),isFocused:()=>true}};
|
||||
const paint=()=>layer.paint(context,()=>new graphics.GrayImage(120,150));
|
||||
const move=async type=>{await layer.handleInput({type},context);paint();return layer.selectedIndex;};
|
||||
// The highlight starts below the first heading and steps over the second, both ways and when wrapping.
|
||||
paint();assert.equal(layer.selectedIndex,1);
|
||||
assert.equal(await move('scroll-down'),2);
|
||||
assert.equal(await move('scroll-down'),4);
|
||||
assert.equal(await move('scroll-down'),1);
|
||||
assert.equal(await move('scroll-up'),4);
|
||||
assert.equal(await move('scroll-up'),2);
|
||||
await layer.handleInput({type:'click'},context);assert.deepEqual(picked,['B']);
|
||||
// A heading asked for by index lands on the row under it.
|
||||
layer.selectItem(3);assert.equal(layer.selectedIndex,4);
|
||||
// Headings draw dim, in capitals (4px per character in this font), in the rows' text column.
|
||||
const image=paint().withDrawsBaked(false),inkAt=y=>{const xs=[];for(let x=0;x<120;x++) if(image.pixels[y*120+x]>=8) xs.push([x,image.pixels[y*120+x]]);return xs;};
|
||||
const heading=inkAt(8+4+2),unselected=inkAt(8+20+4+2);
|
||||
assert.equal(heading[0][0],unselected[0][0]);
|
||||
assert.ok(heading.every(([,value])=>value===90));assert.ok(unselected.every(([,value])=>value===200));
|
||||
assert.equal(heading.length,'FIRST'.length*2);
|
||||
});
|
||||
test('text page paints at the stack size, not the lens size',()=>{
|
||||
// An app window's stack is its viewport; a lens-sized plane is rejected by
|
||||
// the compositor as larger than the window surface.
|
||||
|
||||
Reference in new issue
Block a user