forked from Blendman974/faceclaw
[verified] merge upstream 25cb255b into all-features
This commit is contained in:
commit
ffcdae660d
169 files changed
+16201
-597
No files matched your search
@@ -28,6 +28,13 @@ export type SettingsSection = {
|
||||
height: number;
|
||||
ctx: LayerContext;
|
||||
}) => number | void;
|
||||
/**
|
||||
* Leave the section out of the list while this returns true. Re-read on
|
||||
* every paint and input, for a section that only applies with some other
|
||||
* setting (the paired glasses' type): the Settings window outlives changes
|
||||
* to those.
|
||||
*/
|
||||
hidden?: () => boolean;
|
||||
};
|
||||
|
||||
const LEFT_W = 150;
|
||||
@@ -66,7 +73,7 @@ export class SettingsPanelLayer implements Layer {
|
||||
|
||||
constructor(private readonly sections: SettingsSection[]) {
|
||||
this.leftMenu = new Menu<SettingsSection>({
|
||||
items: sections,
|
||||
items: sections.filter((section) => !section.hidden?.()),
|
||||
wrap: true,
|
||||
rowGap: ROW_GAP,
|
||||
highlight: { radius: 6 },
|
||||
@@ -110,9 +117,28 @@ export class SettingsPanelLayer implements Layer {
|
||||
return this.leftMenu.selectedItem ?? this.sections[0]!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring the left column in line with which sections are hidden now. The
|
||||
* highlight stays on its section; if that one just went away it moves to
|
||||
* the list's start, with focus back in the left column.
|
||||
*/
|
||||
private syncSections(): void {
|
||||
const visible = this.sections.filter((section) => !section.hidden?.());
|
||||
const shown = this.leftMenu.items;
|
||||
if (visible.length === shown.length && visible.every((section, index) => section === shown[index])) return;
|
||||
const selected = this.leftMenu.selectedItem;
|
||||
const index = selected ? visible.indexOf(selected) : -1;
|
||||
this.leftMenu.setItems(visible, Math.max(0, index));
|
||||
if (index < 0) {
|
||||
this.focus = "left";
|
||||
this.resetRight();
|
||||
}
|
||||
}
|
||||
|
||||
/** Select a left-column section by label (deep link, e.g. from an app's menu). */
|
||||
focusSection(label: string): void {
|
||||
const index = this.sections.findIndex((section) => section.label === label);
|
||||
this.syncSections();
|
||||
const index = this.leftMenu.items.findIndex((section) => section.label === label);
|
||||
if (index < 0) return;
|
||||
this.leftMenu.select(index);
|
||||
this.focus = "left";
|
||||
@@ -125,6 +151,7 @@ export class SettingsPanelLayer implements Layer {
|
||||
const { width, height, padding } = viewport;
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const appFocused = ctx.stack.isFocused();
|
||||
this.syncSections();
|
||||
const section = this.section();
|
||||
const rightItems = section.items;
|
||||
this.rightMenu.setItems(rightItems);
|
||||
@@ -230,6 +257,7 @@ export class SettingsPanelLayer implements Layer {
|
||||
}
|
||||
|
||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
this.syncSections();
|
||||
const scroll = scrollEventFor(event);
|
||||
if (this.focus === "left") {
|
||||
if (scroll) {
|
||||
|
||||
Reference in new issue
Block a user