forked from Blendman974/faceclaw
Two-column app switcher
This commit is contained in:
1 parent
7d2a41bd56
commit
65c73ad144
4 files changed
+108
-47
No files matched your search
@@ -12,6 +12,8 @@ import {
|
||||
MIN_WINDOW_HEIGHT,
|
||||
minWindowTop,
|
||||
SHELL_OPAQUE_BLACK,
|
||||
SIDEBAR_COLUMN_WIDTH,
|
||||
SIDEBAR_COLUMNS,
|
||||
SIDEBAR_WIDTH,
|
||||
TOP_BAR_HEIGHT,
|
||||
windowTop,
|
||||
@@ -19,7 +21,9 @@ import {
|
||||
} from "./geometry";
|
||||
|
||||
const ICON_SIZE = 32;
|
||||
const ICON_MARGIN_X = ((SIDEBAR_WIDTH - ICON_SIZE) / 2) | 0;
|
||||
const ICON_MARGIN_X = ((SIDEBAR_COLUMN_WIDTH - ICON_SIZE) / 2) | 0;
|
||||
/** Column index of the rightmost sidebar column (the one that fills first). */
|
||||
const FIRST_COLUMN = SIDEBAR_COLUMNS - 1;
|
||||
const ICON_SPACING = 8;
|
||||
const NOTIFICATION_ICON_SIZE = 24;
|
||||
const BORDER_VALUE = 40;
|
||||
@@ -121,43 +125,61 @@ export class ShellChromeLayer implements Layer {
|
||||
image.fillRect(0, bandTop, SIDEBAR_WIDTH, MIN_WINDOW_HEIGHT, SHELL_OPAQUE_BLACK);
|
||||
|
||||
// Scroll the icon list to keep the selection visible; chevrons mark
|
||||
// windows off-screen above/below.
|
||||
// windows off-screen above/below. Icons fill the right column top to
|
||||
// bottom, then overflow into the left one, so a visible slot's column is
|
||||
// decided by its position within the scrolled window.
|
||||
const listTop = bandTop + TOP_BAR_HEIGHT + 10;
|
||||
const itemStride = ICON_SIZE + ICON_SPACING;
|
||||
const listHeight = bandBottom - listTop - 10;
|
||||
const visibleCount = Math.max(1, ((listHeight + ICON_SPACING) / itemStride) | 0);
|
||||
const rowsPerColumn = Math.max(1, ((listHeight + ICON_SPACING) / itemStride) | 0);
|
||||
const visibleCount = rowsPerColumn * SIDEBAR_COLUMNS;
|
||||
const count = state.windows.length;
|
||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count);
|
||||
const lastVisible = Math.min(count, this.scrollRow + visibleCount);
|
||||
const slotOf = (index: number) => {
|
||||
const position = index - this.scrollRow;
|
||||
const columnsFromRight = (position / rowsPerColumn) | 0;
|
||||
return {
|
||||
column: FIRST_COLUMN - columnsFromRight,
|
||||
y: listTop + (position % rowsPerColumn) * itemStride,
|
||||
};
|
||||
};
|
||||
|
||||
// The selection is a "diversion" of the sidebar/main separator line: the
|
||||
// line bulges right around the selected icon (rounded on the left, open
|
||||
// to the main area on the right), so the separator is drawn with a gap
|
||||
// there. When the sidebar has focus, the diversion is filled white and
|
||||
// the icon drawn inverted.
|
||||
// the icon drawn inverted. Only the right column touches the separator;
|
||||
// a selected overflow icon gets a self-contained box instead.
|
||||
const sep = SIDEBAR_WIDTH - 1;
|
||||
const selVisible = state.selectedIndex >= this.scrollRow && state.selectedIndex < lastVisible;
|
||||
const selTabTop = selVisible ? listTop + (state.selectedIndex - this.scrollRow) * itemStride - 2 : 0;
|
||||
const selTabBottom = selTabTop + ICON_SIZE + 4;
|
||||
if (selVisible) {
|
||||
const selSlot = selVisible ? slotOf(state.selectedIndex) : null;
|
||||
const selTabTop = selSlot && selSlot.column === FIRST_COLUMN ? selSlot.y - 2 : null;
|
||||
if (selTabTop !== null) {
|
||||
image.drawLine(sep, bandTop, sep, selTabTop, BORDER_VALUE);
|
||||
image.drawLine(sep, selTabBottom, sep, bandBottom - 1, BORDER_VALUE);
|
||||
image.drawLine(sep, selTabTop + ICON_SIZE + 4, sep, bandBottom - 1, BORDER_VALUE);
|
||||
} else {
|
||||
image.drawLine(sep, bandTop, sep, bandBottom - 1, BORDER_VALUE);
|
||||
}
|
||||
|
||||
for (let index = this.scrollRow; index < lastVisible; index++) {
|
||||
const window = state.windows[index]!;
|
||||
const y = listTop + (index - this.scrollRow) * itemStride;
|
||||
const { column, y } = slotOf(index);
|
||||
const columnLeft = column * SIDEBAR_COLUMN_WIDTH;
|
||||
const x = columnLeft + ICON_MARGIN_X;
|
||||
const selected = index === state.selectedIndex;
|
||||
const focused = selected && state.focus === "sidebar";
|
||||
if (selected) {
|
||||
drawSelectionTab(image, y - 2, y + ICON_SIZE + 2, focused);
|
||||
if (selected && column === FIRST_COLUMN) {
|
||||
drawSelectionTab(image, columnLeft, y - 2, y + ICON_SIZE + 2, focused);
|
||||
} else if (selected) {
|
||||
// Spans the full column: only 2px of margin flanks a 32px icon in a
|
||||
// 36px column, so anything wider would clip at the screen edge.
|
||||
drawSelectionBox(image, columnLeft, y - 2, SIDEBAR_COLUMN_WIDTH, ICON_SIZE + 4, focused);
|
||||
}
|
||||
window.drawIcon(image, ICON_MARGIN_X, y, ICON_SIZE, focused);
|
||||
window.drawIcon(image, x, y, ICON_SIZE, focused);
|
||||
if (window.attention) {
|
||||
// Black dot on the white focused tab, white dot otherwise.
|
||||
image.fillRoundedRect(ICON_MARGIN_X + ICON_SIZE - 7, y - 1, 8, 8, focused ? SHELL_OPAQUE_BLACK : 255, 4);
|
||||
image.fillRoundedRect(x + ICON_SIZE - 7, y - 1, 8, 8, focused ? SHELL_OPAQUE_BLACK : 255, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,26 +299,40 @@ const TAB_EXTEND = 1;
|
||||
const TAB_STROKE = 150;
|
||||
|
||||
/**
|
||||
* Draw the selection "diversion" of the separator line around a sidebar icon:
|
||||
* rounded on the left, square and open on the right, extending a few px past
|
||||
* the separator into the main area. Focused = filled white; otherwise an
|
||||
* outline.
|
||||
* Draw the selection "diversion" of the separator line around a sidebar icon
|
||||
* in the rightmost column: rounded on the left, square and open on the right,
|
||||
* extending a few px past the separator into the main area. Focused = filled
|
||||
* white; otherwise an outline. `left` is the column's left edge, which the
|
||||
* rounded corners curve in from.
|
||||
*/
|
||||
function drawSelectionTab(image: GrayImage, top: number, bottom: number, focused: boolean): void {
|
||||
function drawSelectionTab(image: GrayImage, left: number, top: number, bottom: number, focused: boolean): void {
|
||||
const right = SIDEBAR_WIDTH - 1 + TAB_EXTEND;
|
||||
if (focused) {
|
||||
for (let yy = top; yy < bottom; yy++) {
|
||||
const inset = tabLeftInset(yy, top, bottom, TAB_RADIUS);
|
||||
image.fillRect(inset, yy, right - inset + 1, 1, 255);
|
||||
const x = left + tabLeftInset(yy, top, bottom, TAB_RADIUS);
|
||||
image.fillRect(x, yy, right - x + 1, 1, 255);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Outline: curved left edge (per-row) plus straight top and bottom edges.
|
||||
for (let yy = top; yy < bottom; yy++) {
|
||||
image.setPixel(tabLeftInset(yy, top, bottom, TAB_RADIUS), yy, TAB_STROKE);
|
||||
image.setPixel(left + tabLeftInset(yy, top, bottom, TAB_RADIUS), yy, TAB_STROKE);
|
||||
}
|
||||
image.drawLine(left + tabLeftInset(top, top, bottom-1, TAB_RADIUS), top, right, top, TAB_STROKE);
|
||||
image.drawLine(left + tabLeftInset(bottom-1, top, bottom-1, TAB_RADIUS), bottom-1, right, bottom-1, TAB_STROKE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selection marker for an overflow-column icon, which has no separator to
|
||||
* divert: a self-contained rounded box, filled white when the sidebar has
|
||||
* focus and outlined otherwise (matching the tab's two states).
|
||||
*/
|
||||
function drawSelectionBox(image: GrayImage, x: number, y: number, width: number, height: number, focused: boolean): void {
|
||||
if (focused) {
|
||||
image.fillRoundedRect(x, y, width, height, 255, TAB_RADIUS);
|
||||
} else {
|
||||
image.drawRoundedRect(x, y, width, height, TAB_STROKE, TAB_RADIUS);
|
||||
}
|
||||
image.drawLine(tabLeftInset(top, top, bottom-1, TAB_RADIUS), top, right, top, TAB_STROKE);
|
||||
image.drawLine(tabLeftInset(bottom-1, top, bottom-1, TAB_RADIUS), bottom-1, right, bottom-1, TAB_STROKE);
|
||||
}
|
||||
|
||||
/** Left boundary x of the tab at row yy: 0 in the middle, curving to the rounded left corners. */
|
||||
|
||||
@@ -3,8 +3,15 @@ import { verticalPositionSetting } from "../dashboard-settings";
|
||||
|
||||
/** Top bar: 24px notification icons plus a little padding. */
|
||||
export const TOP_BAR_HEIGHT = 28;
|
||||
/** Left sidebar: 32px window icons plus a little padding. */
|
||||
export const SIDEBAR_WIDTH = 36;
|
||||
/** One sidebar column: 32px window icons plus a little padding. */
|
||||
export const SIDEBAR_COLUMN_WIDTH = 36;
|
||||
/**
|
||||
* Sidebar icon columns. The right column (against the app area) fills first;
|
||||
* windows past that overflow into the left column, so the common few-window
|
||||
* case keeps every icon next to the content it belongs to.
|
||||
*/
|
||||
export const SIDEBAR_COLUMNS = 2;
|
||||
export const SIDEBAR_WIDTH = SIDEBAR_COLUMN_WIDTH * SIDEBAR_COLUMNS;
|
||||
|
||||
/**
|
||||
* On the color-key shell surface, pixel value 0 is transparent; 1 is the
|
||||
|
||||
Reference in new issue
Block a user