forked from Blendman974/faceclaw
Context menus are centered and include window title
This commit is contained in:
1 parent
5158bc86ff
commit
b1493a353d
14 files changed
+55
-18
No files matched your search
+4
-2
@@ -17,7 +17,8 @@ const MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL = 15;
|
||||
const MENU_HIGHLIGHT_SELECTED_BORDER_STROKE = 45;
|
||||
|
||||
export type MenuLayout = {
|
||||
x: number;
|
||||
/** Left edge, or "center" to center horizontally on the painted surface. */
|
||||
x: number | "center";
|
||||
y: number;
|
||||
width: number;
|
||||
/** Whether to draw the rounded outline around the menu. Default: true. */
|
||||
@@ -200,7 +201,8 @@ export class MenuLayer implements Layer {
|
||||
const rowHeight = listRowHeight(font);
|
||||
const base = ctx.stack.getBaseSize();
|
||||
const image = this.layout.opaque ? new GrayImage(base.width, base.height, 0) : paintBelow();
|
||||
const { x, y, width } = this.layout;
|
||||
const { y, width } = this.layout;
|
||||
const x = this.layout.x === "center" ? ((image.width - width) / 2) | 0 : this.layout.x;
|
||||
const chromeTop = (this.title ? menuTitleHeight(font) : 0) + MENU_BODY_PADDING;
|
||||
const minHeight = this.layout.minHeight ?? DEFAULT_MENU_MIN_HEIGHT;
|
||||
// Cap to the surface being painted on: a window's stack image may be much
|
||||
|
||||
@@ -162,7 +162,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
},
|
||||
});
|
||||
}
|
||||
stack.push(new WindowMenuLayer(items));
|
||||
stack.push(new WindowMenuLayer(options.title, items));
|
||||
};
|
||||
|
||||
const window: ShellWindow = {
|
||||
|
||||
@@ -171,13 +171,15 @@ const LONG_PRESS_ESCAPE_MENU_MS = 4000;
|
||||
class ShellOverlayMenuLayer extends MenuLayer {
|
||||
constructor(items: MenuItem[], private readonly onClosed: () => void) {
|
||||
// Aligned to the min-height window band (like the sidebar), wherever the
|
||||
// vertical position setting currently puts it; past the sidebar strip
|
||||
// where one reserves width (none in the full-panel mode).
|
||||
super(null, items, {
|
||||
x: sidebarWidth() + 8,
|
||||
// vertical position setting currently puts it; centered over the
|
||||
// application area, i.e. the part of the screen past the sidebar strip
|
||||
// (the whole screen in the full-panel mode, where the strip overlays).
|
||||
const width = 272;
|
||||
super("System", items, {
|
||||
x: sidebarWidth() + (((G2_LENS_WIDTH - sidebarWidth() - width) / 2) | 0),
|
||||
y: minWindowTop() + TOP_BAR_HEIGHT + 8,
|
||||
width: 272,
|
||||
minHeight: 0,
|
||||
width,
|
||||
minHeight: 150,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import { shell, type ShellWindow } from "./shell";
|
||||
* worker→Java directly.
|
||||
*/
|
||||
export type WorkerAppMessage =
|
||||
| { type: "open-window"; windowId: string; surfaceId: string; viewport: { width: number; height: number } }
|
||||
| { type: "open-window"; windowId: string; surfaceId: string; title: string; viewport: { width: number; height: number } }
|
||||
| { type: "close-window"; windowId: string }
|
||||
| { type: "input"; windowId: string; event: unknown; frameId: number; focused: boolean }
|
||||
| { type: "text-input"; windowId: string; text: string }
|
||||
@@ -303,6 +303,7 @@ export class WorkerAppHost {
|
||||
type: "open-window",
|
||||
windowId: spec.windowId,
|
||||
surfaceId,
|
||||
title: spec.title,
|
||||
viewport: appViewportSize(heightMode),
|
||||
});
|
||||
const window: ShellWindow = {
|
||||
|
||||
@@ -13,16 +13,18 @@ import type { WorkerAppReply } from "./shell/worker-window";
|
||||
* is held long enough, so an unresponsive app can always be closed.
|
||||
*/
|
||||
|
||||
/** Viewport-relative layout; visually matches the shell's escape menu position. */
|
||||
export const WINDOW_MENU_LAYOUT: MenuLayout = { x: 8, y: 8, width: 272, minHeight: 0 };
|
||||
/** Centered over the viewport; visually matches the shell's escape menu position. */
|
||||
export const WINDOW_MENU_LAYOUT: MenuLayout = { x: "center", y: 8, width: 272, minHeight: 150 };
|
||||
|
||||
export class WindowMenuLayer extends MenuLayer {
|
||||
constructor(items: MenuItem[]) {
|
||||
super(null, items, WINDOW_MENU_LAYOUT);
|
||||
constructor(title: string | null, items: MenuItem[]) {
|
||||
super(title, items, WINDOW_MENU_LAYOUT);
|
||||
}
|
||||
}
|
||||
|
||||
export type WindowMenuOptions = {
|
||||
/** Menu title: the window's title, read at open time. */
|
||||
title: () => string;
|
||||
/** Paint the window content the menu draws over (a fresh, mutable image). */
|
||||
paintBase: () => GrayImage;
|
||||
size: { width: number; height: number };
|
||||
@@ -53,7 +55,7 @@ export class WindowMenu {
|
||||
handleInput: () => {},
|
||||
};
|
||||
const stack = new LayerStack(base, { ...noopLayerActions }, this.options.size, this.options.isFocused);
|
||||
stack.push(new WindowMenuLayer(items));
|
||||
stack.push(new WindowMenuLayer(this.options.title(), items));
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user