forked from Blendman974/faceclaw
Simplify glanceboard-trigger angle setting; fix incorrectly-rotated accelerometer readings on G1
The glanceboard head-tilt option was more complicated than necessary, because it wanted the user to take two angle measurements, a baseline angle and a tilt angle. That was a workaround to not knowing the accelerometer's orientation/calibration, but actually, we do know those. (Except, as it turns out, on the G1, the accelerometer orientation is different than it is on the G2, and there was a bug where EvenHub apps got their accelerometer readings in the wrong orientation. So for example the EvenHub Level app didn't work correctly.)
This commit is contained in:
1 parent
37d81d0308
commit
e09f8eae96
17 files changed
+255
-281
No files matched your search
@@ -1724,9 +1724,18 @@ type SettingsMenuOptions<T> = {
|
||||
label?: string
|
||||
}
|
||||
|
||||
type EnumSettingMenuOptions<T> = SettingsMenuOptions<T> & {
|
||||
/**
|
||||
* A live line under the picker's values, such as a sensor reading to pick
|
||||
* by. open() runs as the picker opens, with a function that repaints it,
|
||||
* and returns what to run when the picker closes.
|
||||
*/
|
||||
pickerFooter?: { text: () => string; open: (repaint: () => void) => () => void }
|
||||
}
|
||||
|
||||
export function enumSettingMenuItem<TValue extends string, TId extends string = string>(
|
||||
setting: ConfigSettingEnum<TValue, TId>,
|
||||
opts?: SettingsMenuOptions<TValue>
|
||||
opts?: EnumSettingMenuOptions<TValue>
|
||||
): MenuItem {
|
||||
const label = opts?.label ?? setting.label;
|
||||
return {
|
||||
@@ -1754,7 +1763,11 @@ export function enumSettingMenuItem<TValue extends string, TId extends string =
|
||||
);
|
||||
},
|
||||
}));
|
||||
openModalMenu(ctx, label, items, Math.max(0, setting.values.indexOf(current)));
|
||||
const footer = opts?.pickerFooter;
|
||||
openModalMenu(ctx, label, items, Math.max(0, setting.values.indexOf(current)), {
|
||||
footer: footer?.text,
|
||||
onClosed: footer?.open(() => ctx.actions.requestRender()),
|
||||
});
|
||||
},
|
||||
render: ({ image, x, y, width }) => {
|
||||
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, label, setting.displayValue(setting.get()));
|
||||
|
||||
+33
-6
@@ -57,7 +57,7 @@ export type MenuLayout = {
|
||||
* Dim hint line pinned to the bottom edge inside the box, below the items
|
||||
* (gesture help such as "●— system menu"). Takes a line off the item area.
|
||||
*/
|
||||
footer?: string;
|
||||
footer?: MenuFooter;
|
||||
/** Brightness factor for everything beneath the menu (see Layer.dimUnderneath). Default: none. */
|
||||
dimUnderneath?: number;
|
||||
/**
|
||||
@@ -83,9 +83,16 @@ export type MenuPageLayout = {
|
||||
/** Width of the rows. Default (and at most): the window's, inside its side padding. */
|
||||
width?: number;
|
||||
/** Dim hint line pinned above the window's bottom padding, below the rows. */
|
||||
footer?: string;
|
||||
footer?: MenuFooter;
|
||||
};
|
||||
|
||||
/** A menu's footer line: fixed text, or read on every paint (a live value). */
|
||||
export type MenuFooter = string | (() => string);
|
||||
|
||||
function footerText(footer: MenuFooter): string {
|
||||
return typeof footer === "function" ? footer() : footer;
|
||||
}
|
||||
|
||||
export type MenuItemRenderArgs = {
|
||||
image: GrayImage;
|
||||
x: number;
|
||||
@@ -360,7 +367,7 @@ export class MenuLayer implements Layer {
|
||||
image.drawText(font, x + 12, y + 8, this.title, 220);
|
||||
}
|
||||
if (layout.footer) {
|
||||
image.drawText(font, x + 22, y + height - MENU_BODY_PADDING - font.lineHeight, layout.footer, 110);
|
||||
image.drawText(font, x + 22, y + height - MENU_BODY_PADDING - font.lineHeight, footerText(layout.footer), 110);
|
||||
}
|
||||
|
||||
const bodyY = y + chromeTop;
|
||||
@@ -397,7 +404,7 @@ export class MenuLayer implements Layer {
|
||||
let fixedBottom = height - padding.bottom;
|
||||
if (layout.footer) {
|
||||
const footerY = height - padding.bottom - font.lineHeight;
|
||||
image.drawText(font, x + MENU_ROW_TEXT_INSET, footerY, layout.footer, 110);
|
||||
image.drawText(font, x + MENU_ROW_TEXT_INSET, footerY, footerText(layout.footer), 110);
|
||||
bottom = fixedBottom = footerY - MENU_FOOTER_GAP;
|
||||
}
|
||||
if (bottom <= top) return image;
|
||||
@@ -431,17 +438,26 @@ export class MenuLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
export type ModalMenuOptions = {
|
||||
/** A dim line under the items (see MenuLayout.footer). */
|
||||
footer?: MenuFooter;
|
||||
/** Runs when the menu leaves the stack, however it closes. */
|
||||
onClosed?: () => void;
|
||||
};
|
||||
|
||||
/** Open a centered, bordered menu over the current layer. */
|
||||
export function openModalMenu(
|
||||
ctx: LayerContext,
|
||||
title: string,
|
||||
items: MenuItem[],
|
||||
initialSelectedIndex = 0,
|
||||
options: ModalMenuOptions = {},
|
||||
): void {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const font = getDefaultSmallFont();
|
||||
const menuWidth = Math.min(320, width - 40);
|
||||
const naturalHeight = menuTitleHeight(font) + 2 * MENU_BODY_PADDING + items.length * listRowHeight(font);
|
||||
const footerHeight = options.footer ? MENU_FOOTER_GAP + lineStep(font) : 0;
|
||||
const naturalHeight = menuTitleHeight(font) + 2 * MENU_BODY_PADDING + items.length * listRowHeight(font) + footerHeight;
|
||||
// 20px clear above and below, or 8 in a short window (the RayNeo iO's),
|
||||
// where those rows are worth more than the margin.
|
||||
const marginY = height < SHORT_WINDOW_HEIGHT ? 8 : 20;
|
||||
@@ -454,8 +470,19 @@ export function openModalMenu(
|
||||
maxHeight: menuHeight,
|
||||
// Floats nearer than the content it opens over, like the window and system menus.
|
||||
depth: 4,
|
||||
footer: options.footer,
|
||||
};
|
||||
ctx.stack.push(new MenuLayer(title, items, layout).selectItem(initialSelectedIndex));
|
||||
ctx.stack.push(new ModalMenuLayer(title, items, layout, options.onClosed).selectItem(initialSelectedIndex));
|
||||
}
|
||||
|
||||
class ModalMenuLayer extends MenuLayer {
|
||||
constructor(title: string, items: MenuItem[], layout: MenuLayout, private readonly onClosed?: () => void) {
|
||||
super(title, items, layout);
|
||||
}
|
||||
|
||||
onRemoved(): void {
|
||||
this.onClosed?.();
|
||||
}
|
||||
}
|
||||
|
||||
export function isMenuItemDisabled(item: MenuItem): boolean {
|
||||
|
||||
Reference in new issue
Block a user