forked from Blendman974/faceclaw
Fancier battery displays: Stacked view, segmenting
This commit is contained in:
1 parent
6f60cda9cc
commit
ca839f45d6
6 files changed
+277
-58
No files matched your search
@@ -8,6 +8,8 @@
|
|||||||
* Add "AI Chat" app (conversational-style use of the voice assistant with hold-to-talk)
|
* Add "AI Chat" app (conversational-style use of the voice assistant with hold-to-talk)
|
||||||
* Add rightness control to the system context menu
|
* Add rightness control to the system context menu
|
||||||
* Messaging in the flasher distinguishes between downgrading from stock firmwares where that's been validated and veresions where it hasn't, and considers 2.2.10 validated
|
* Messaging in the flasher distinguishes between downgrading from stock firmwares where that's been validated and veresions where it hasn't, and considers 2.2.10 validated
|
||||||
|
* Add R1 battery indicator to the top bar
|
||||||
|
* Change the styling and add more customization options for battery indicators
|
||||||
|
|
||||||
## 0.6.5 - 2026-09-04
|
## 0.6.5 - 2026-09-04
|
||||||
* Changed context menu gestures: — for system, ●— for app context menu.
|
* Changed context menu gestures: — for system, ●— for app context menu.
|
||||||
|
|||||||
+62
-23
@@ -1,20 +1,36 @@
|
|||||||
import { GrayImage, imageFromAsciiArt } from "./image";
|
import { GrayImage, imageFromAsciiArt } from "./image";
|
||||||
|
|
||||||
const EMPTY_BATTERY_ICON = imageFromAsciiArt(
|
/**
|
||||||
[
|
* Top-bar battery gauge: a 10px-tall outlined body with a nub on the right,
|
||||||
" ################## ",
|
* filled left-to-right in proportion to the charge. The fill is drawn as
|
||||||
" #................# ",
|
* BATTERY_BAR_COUNT bars of BATTERY_BAR_WIDTH px separated by dimmed
|
||||||
" #................###",
|
* BATTERY_BAR_GAP-px columns; the body outline is sized from those
|
||||||
" #................###",
|
* constants so they can be tuned freely. The fill level is continuous (not
|
||||||
" #................###",
|
* quantized to whole bars): the rightmost lit bar is cut to a partial width.
|
||||||
" #................###",
|
*/
|
||||||
" #................###",
|
export const BATTERY_BAR_COUNT = 4;
|
||||||
" #................###",
|
export const BATTERY_BAR_WIDTH = 3;
|
||||||
" #................# ",
|
export const BATTERY_BAR_GAP = 1;
|
||||||
" ################## ",
|
|
||||||
],
|
const OUTLINE_VALUE = 120;
|
||||||
120,
|
const BAR_VALUE = 190;
|
||||||
);
|
/** The separator columns inside the lit portion of the fill. */
|
||||||
|
const BAR_GAP_VALUE = 70;
|
||||||
|
|
||||||
|
const ICON_HEIGHT = 10;
|
||||||
|
/** Outline stroke plus one clear pixel between it and the fill, per side. */
|
||||||
|
const BODY_INSET = 2;
|
||||||
|
const NUB_WIDTH = 2;
|
||||||
|
const NUB_TOP = 2;
|
||||||
|
const NUB_HEIGHT = 6;
|
||||||
|
|
||||||
|
const FILL_X = BODY_INSET;
|
||||||
|
const FILL_Y = BODY_INSET;
|
||||||
|
const FILL_WIDTH = BATTERY_BAR_COUNT * BATTERY_BAR_WIDTH + (BATTERY_BAR_COUNT - 1) * BATTERY_BAR_GAP;
|
||||||
|
const FILL_HEIGHT = ICON_HEIGHT - 2 * BODY_INSET;
|
||||||
|
const BODY_WIDTH = FILL_WIDTH + 2 * BODY_INSET;
|
||||||
|
|
||||||
|
export const BATTERY_ICON_WIDTH = BODY_WIDTH + NUB_WIDTH;
|
||||||
|
|
||||||
const BATTERY_BOLT_ICON = imageFromAsciiArt(
|
const BATTERY_BOLT_ICON = imageFromAsciiArt(
|
||||||
[
|
[
|
||||||
@@ -29,25 +45,48 @@ const BATTERY_BOLT_ICON = imageFromAsciiArt(
|
|||||||
255,
|
255,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const BATTERY_ICON_WIDTH = EMPTY_BATTERY_ICON.width;
|
/** The empty outline, built once from the geometry constants. */
|
||||||
|
const EMPTY_BATTERY_ICON = buildEmptyBattery();
|
||||||
|
|
||||||
const BATTERY_FILL_X = 3;
|
function buildEmptyBattery(): GrayImage {
|
||||||
const BATTERY_FILL_Y = 2;
|
const icon = new GrayImage(BATTERY_ICON_WIDTH, ICON_HEIGHT, 0);
|
||||||
const BATTERY_FILL_WIDTH = 14;
|
icon.fillRect(0, 0, BODY_WIDTH, 1, OUTLINE_VALUE);
|
||||||
const BATTERY_FILL_HEIGHT = 6;
|
icon.fillRect(0, ICON_HEIGHT - 1, BODY_WIDTH, 1, OUTLINE_VALUE);
|
||||||
|
icon.fillRect(0, 0, 1, ICON_HEIGHT, OUTLINE_VALUE);
|
||||||
|
icon.fillRect(BODY_WIDTH - 1, 0, 1, ICON_HEIGHT, OUTLINE_VALUE);
|
||||||
|
icon.fillRect(BODY_WIDTH, NUB_TOP, NUB_WIDTH, NUB_HEIGHT, OUTLINE_VALUE);
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
export function drawBattery(percentCharge: number, isCharging: boolean): GrayImage {
|
export function drawBattery(percentCharge: number, isCharging: boolean): GrayImage {
|
||||||
const icon = new GrayImage(EMPTY_BATTERY_ICON.width, EMPTY_BATTERY_ICON.height, 0);
|
const icon = new GrayImage(EMPTY_BATTERY_ICON.width, EMPTY_BATTERY_ICON.height, 0);
|
||||||
icon.bitBlt(EMPTY_BATTERY_ICON, 0, 0);
|
icon.bitBlt(EMPTY_BATTERY_ICON, 0, 0);
|
||||||
const clamped = Math.max(0, Math.min(100, percentCharge));
|
const clamped = Math.max(0, Math.min(100, percentCharge));
|
||||||
const fillWidth = Math.round((BATTERY_FILL_WIDTH * clamped) / 100);
|
const litWidth = Math.round((FILL_WIDTH * clamped) / 100);
|
||||||
icon.fillRect(BATTERY_FILL_X, BATTERY_FILL_Y, fillWidth, BATTERY_FILL_HEIGHT, 190);
|
drawSegmentedFill(icon, litWidth);
|
||||||
if (isCharging) {
|
if (isCharging) {
|
||||||
overlayImage(icon, BATTERY_BOLT_ICON, 7, 1, clamped > 50 ? 0 : 255);
|
const boltX = FILL_X + (((FILL_WIDTH - BATTERY_BOLT_ICON.width) / 2) | 0);
|
||||||
|
overlayImage(icon, BATTERY_BOLT_ICON, boltX, 1, clamped > 50 ? 0 : 255);
|
||||||
}
|
}
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Light the leftmost `litWidth` columns of the fill area as bars with dim
|
||||||
|
* separator columns. Columns past the lit width stay clear, so a partial
|
||||||
|
* charge ends mid-bar rather than snapping to a bar boundary. A separator is
|
||||||
|
* only drawn between two lit bars: when the lit width ends exactly on one it
|
||||||
|
* is left clear rather than dangling past the last bar.
|
||||||
|
*/
|
||||||
|
function drawSegmentedFill(icon: GrayImage, litWidth: number): void {
|
||||||
|
const pitch = BATTERY_BAR_WIDTH + BATTERY_BAR_GAP;
|
||||||
|
for (let column = 0; column < litWidth; column++) {
|
||||||
|
const isBar = column % pitch < BATTERY_BAR_WIDTH;
|
||||||
|
if (!isBar && column + BATTERY_BAR_GAP >= litWidth) continue;
|
||||||
|
icon.fillRect(FILL_X + column, FILL_Y, 1, FILL_HEIGHT, isBar ? BAR_VALUE : BAR_GAP_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function overlayImage(target: GrayImage, source: GrayImage, dx: number, dy: number, value: number): void {
|
function overlayImage(target: GrayImage, source: GrayImage, dx: number, dy: number, value: number): void {
|
||||||
for (let y = 0; y < source.height; y++) {
|
for (let y = 0; y < source.height; y++) {
|
||||||
for (let x = 0; x < source.width; x++) {
|
for (let x = 0; x < source.width; x++) {
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ export type NightscoutSettings = {
|
|||||||
siteUrl: string;
|
siteUrl: string;
|
||||||
apiToken: string;
|
apiToken: string;
|
||||||
};
|
};
|
||||||
export type BatteryDisplayMode = "icon" | "percentage";
|
export type BatteryDisplayMode = "icon" | "percentage" | "stacked" | "stacked-percentage";
|
||||||
|
/** When a top-bar battery indicator is shown: always, only below 50%, or never. */
|
||||||
|
export type BatteryIndicatorVisibility = "always" | "low" | "never";
|
||||||
export type TimeFormat = "24h" | "12h";
|
export type TimeFormat = "24h" | "12h";
|
||||||
export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "3m" | "never";
|
export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "3m" | "never";
|
||||||
// "auto" lets the glasses' ambient-light sensor drive brightness; the numeric
|
// "auto" lets the glasses' ambient-light sensor drive brightness; the numeric
|
||||||
@@ -206,14 +208,63 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
|
|||||||
|
|
||||||
export const batteryDisplayModeSetting = new ConfigSettingEnum<BatteryDisplayMode>({
|
export const batteryDisplayModeSetting = new ConfigSettingEnum<BatteryDisplayMode>({
|
||||||
id: "batteryDisplayMode",
|
id: "batteryDisplayMode",
|
||||||
label: "Battery display",
|
label: "Style",
|
||||||
storageKey: "dashboard.systemCard.batteryDisplayMode",
|
storageKey: "dashboard.systemCard.batteryDisplayMode",
|
||||||
defaultValue: "icon",
|
defaultValue: "stacked",
|
||||||
values: ["icon", "percentage"],
|
values: ["icon", "percentage", "stacked", "stacked-percentage"],
|
||||||
formatValue: batteryDisplayModeLabel,
|
formatValue: batteryDisplayModeLabel,
|
||||||
description: "How the top bar shows the phone and glasses battery levels: a small gauge icon or an exact percentage.",
|
description: "How the top bar shows battery levels: a gauge icon or exact percentage beside the label, or a compact gauge or percentage with the label stacked above it.",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Below this charge level a "Below 50%" indicator becomes visible. */
|
||||||
|
export const BATTERY_LOW_VISIBILITY_THRESHOLD = 50;
|
||||||
|
|
||||||
|
function batteryVisibilitySetting(
|
||||||
|
id: string,
|
||||||
|
device: string,
|
||||||
|
storageKey: string,
|
||||||
|
): ConfigSettingEnum<BatteryIndicatorVisibility> {
|
||||||
|
return new ConfigSettingEnum<BatteryIndicatorVisibility>({
|
||||||
|
id,
|
||||||
|
label: device,
|
||||||
|
storageKey,
|
||||||
|
defaultValue: "always",
|
||||||
|
values: ["always", "low", "never"],
|
||||||
|
formatValue: batteryIndicatorVisibilityLabel,
|
||||||
|
description: `When the top bar shows the ${device} battery: always, only once it drops below ${BATTERY_LOW_VISIBILITY_THRESHOLD}%, or never.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const phoneBatteryVisibilitySetting = batteryVisibilitySetting(
|
||||||
|
"phoneBatteryVisibility", "Phone", "display.battery.phoneVisibility",
|
||||||
|
);
|
||||||
|
export const glassesBatteryVisibilitySetting = batteryVisibilitySetting(
|
||||||
|
"glassesBatteryVisibility", "G2", "display.battery.glassesVisibility",
|
||||||
|
);
|
||||||
|
export const ringBatteryVisibilitySetting = batteryVisibilitySetting(
|
||||||
|
"ringBatteryVisibility", "R1", "display.battery.ringVisibility",
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Whether an indicator with this visibility setting shows at the given charge. */
|
||||||
|
export function batteryIndicatorVisible(visibility: BatteryIndicatorVisibility, percent: number): boolean {
|
||||||
|
if (visibility === "never") return false;
|
||||||
|
if (visibility === "always") return true;
|
||||||
|
return percent < BATTERY_LOW_VISIBILITY_THRESHOLD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One string summarizing every setting the top-bar battery block reads, so
|
||||||
|
* the shell can cheaply tell whether a settings change needs a repaint.
|
||||||
|
*/
|
||||||
|
export function batteryIndicatorSettingsKey(): string {
|
||||||
|
return [
|
||||||
|
batteryDisplayModeSetting.get(),
|
||||||
|
phoneBatteryVisibilitySetting.get(),
|
||||||
|
glassesBatteryVisibilitySetting.get(),
|
||||||
|
ringBatteryVisibilitySetting.get(),
|
||||||
|
].join("|");
|
||||||
|
}
|
||||||
|
|
||||||
export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
|
export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
|
||||||
id: "timeFormat",
|
id: "timeFormat",
|
||||||
label: "Time format",
|
label: "Time format",
|
||||||
@@ -929,7 +980,16 @@ export function screenTimeoutLabel(value: ScreenTimeoutSetting): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function batteryDisplayModeLabel(value: BatteryDisplayMode): string {
|
export function batteryDisplayModeLabel(value: BatteryDisplayMode): string {
|
||||||
return value === "icon" ? "Icon" : "Percentage";
|
if (value === "percentage") return "Percentage";
|
||||||
|
if (value === "stacked") return "Stacked";
|
||||||
|
if (value === "stacked-percentage") return "Stacked percentage";
|
||||||
|
return "Icon";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function batteryIndicatorVisibilityLabel(value: BatteryIndicatorVisibility): string {
|
||||||
|
if (value === "never") return "Never";
|
||||||
|
if (value === "low") return `Below ${BATTERY_LOW_VISIBILITY_THRESHOLD}%`;
|
||||||
|
return "Always";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function timeFormatLabel(value: TimeFormat): string {
|
export function timeFormatLabel(value: TimeFormat): string {
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ import {
|
|||||||
assistantSkipConfirmationSetting,
|
assistantSkipConfirmationSetting,
|
||||||
batteryDisplayModeSetting,
|
batteryDisplayModeSetting,
|
||||||
brightnessSetting,
|
brightnessSetting,
|
||||||
|
glassesBatteryVisibilitySetting,
|
||||||
|
phoneBatteryVisibilitySetting,
|
||||||
|
ringBatteryVisibilitySetting,
|
||||||
displayModeSetting,
|
displayModeSetting,
|
||||||
navigateDisplayModeSetting,
|
navigateDisplayModeSetting,
|
||||||
navigateVerticalPositionSetting,
|
navigateVerticalPositionSetting,
|
||||||
@@ -75,7 +78,7 @@ import {
|
|||||||
} from "../dashboard-settings";
|
} from "../dashboard-settings";
|
||||||
import { clearRecentDestinations } from "../../apps/navigate/destinations";
|
import { clearRecentDestinations } from "../../apps/navigate/destinations";
|
||||||
import { wearBridge } from "../../native/wear-bridge";
|
import { wearBridge } from "../../native/wear-bridge";
|
||||||
import { SettingsPanelLayer, type SettingsSection } from "./settings-panel";
|
import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from "./settings-panel";
|
||||||
import { terminalFontPickerMenuItem, uiFontPickerMenuItem } from "../font-picker";
|
import { terminalFontPickerMenuItem, uiFontPickerMenuItem } from "../font-picker";
|
||||||
|
|
||||||
/** The Settings app's master-detail panel (sections on the left, contents on the right). */
|
/** The Settings app's master-detail panel (sections on the left, contents on the right). */
|
||||||
@@ -102,8 +105,8 @@ function settingsSections(): SettingsSection[] {
|
|||||||
enumSettingMenuItem(verticalPositionSetting),
|
enumSettingMenuItem(verticalPositionSetting),
|
||||||
// Band / tall / full-panel; the dashboard controller reflows windows.
|
// Band / tall / full-panel; the dashboard controller reflows windows.
|
||||||
enumSettingMenuItem(displayModeSetting),
|
enumSettingMenuItem(displayModeSetting),
|
||||||
// Controls the top-bar battery indicators (icon vs percentage).
|
// Submenu: top-bar battery indicator style plus per-device visibility.
|
||||||
enumSettingMenuItem(batteryDisplayModeSetting),
|
batteryIndicatorsMenuItem(),
|
||||||
// Controls the top-bar clock (24-hour vs 12-hour).
|
// Controls the top-bar clock (24-hour vs 12-hour).
|
||||||
enumSettingMenuItem(timeFormatSetting),
|
enumSettingMenuItem(timeFormatSetting),
|
||||||
// Opens the modal font picker (face, weight, size) for UI text.
|
// Opens the modal font picker (face, weight, size) for UI text.
|
||||||
@@ -236,6 +239,38 @@ function settingsSections(): SettingsSection[] {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Display section's "Battery indicators" row: opens a modal submenu with
|
||||||
|
* the style (icon / percentage / stacked) and, per device, when its
|
||||||
|
* indicator is visible. The row itself shows the current style.
|
||||||
|
*/
|
||||||
|
function batteryIndicatorsMenuItem(): MenuItem {
|
||||||
|
return {
|
||||||
|
label: "Battery indicators",
|
||||||
|
description:
|
||||||
|
"Top-bar battery indicators for the phone, glasses, and ring: their style, and whether each shows always, only when low, or never.",
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
openSettingsSubMenu(ctx, "Battery indicators", [
|
||||||
|
enumSettingMenuItem(batteryDisplayModeSetting),
|
||||||
|
enumSettingMenuItem(phoneBatteryVisibilitySetting),
|
||||||
|
enumSettingMenuItem(glassesBatteryVisibilitySetting),
|
||||||
|
enumSettingMenuItem(ringBatteryVisibilitySetting),
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
render: ({ image, x, y, width }) => {
|
||||||
|
drawRightValueMenuItem(
|
||||||
|
image,
|
||||||
|
getDefaultSmallFont(),
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
"Battery indicators",
|
||||||
|
batteryDisplayModeSetting.displayValue(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const LOCAL_MODEL_GB = `${(LOCAL_MODEL.sizeBytes / 1e9).toFixed(1)}GB`;
|
const LOCAL_MODEL_GB = `${(LOCAL_MODEL.sizeBytes / 1e9).toFixed(1)}GB`;
|
||||||
|
|
||||||
// While a download is running, re-render on progress updates so the row's
|
// While a download is running, re-render on progress updates so the row's
|
||||||
|
|||||||
@@ -7,7 +7,16 @@ import { readActiveNotificationIcons } from "../../native/notification-icons";
|
|||||||
import { readPhoneBatteryState } from "../../native/phone-battery";
|
import { readPhoneBatteryState } from "../../native/phone-battery";
|
||||||
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness";
|
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness";
|
||||||
import { renderIcon, renderIconWithGlyph, type IconActivity, type IconName } from "../../graphics/icons";
|
import { renderIcon, renderIconWithGlyph, type IconActivity, type IconName } from "../../graphics/icons";
|
||||||
import { batteryDisplayModeSetting, timeFormatSetting } from "../dashboard-settings";
|
import {
|
||||||
|
batteryDisplayModeSetting,
|
||||||
|
batteryIndicatorVisible,
|
||||||
|
glassesBatteryVisibilitySetting,
|
||||||
|
phoneBatteryVisibilitySetting,
|
||||||
|
ringBatteryVisibilitySetting,
|
||||||
|
timeFormatSetting,
|
||||||
|
type BatteryIndicatorVisibility,
|
||||||
|
} from "../dashboard-settings";
|
||||||
|
import { getFont } from "../../graphics/bdffont";
|
||||||
import { Layer } from "../layers";
|
import { Layer } from "../layers";
|
||||||
import { scrollToKeepSelectionVisible } from "../menu";
|
import { scrollToKeepSelectionVisible } from "../menu";
|
||||||
import { lineStep } from "../metrics";
|
import { lineStep } from "../metrics";
|
||||||
@@ -337,38 +346,45 @@ export class ShellChromeLayer implements Layer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Labelled battery indicators for the phone, G2, and R1, right-aligned in
|
* Labelled battery indicators for the phone, G2, and R1, right-aligned in
|
||||||
* the top bar, following the dashboard card's icon/percentage setting.
|
* the top bar. The Settings > Display > Battery indicators submenu picks
|
||||||
* Returns the left edge of the battery block.
|
* the style (label beside a gauge icon or percentage, or stacked above
|
||||||
|
* either) and, per device, whether the indicator shows always, only below
|
||||||
|
* 50%, or never. Returns the left edge of the battery block.
|
||||||
*/
|
*/
|
||||||
private drawTopBarBatteries(image: GrayImage, state: ShellChromeState, barTop: number): number {
|
private drawTopBarBatteries(image: GrayImage, state: ShellChromeState, barTop: number): number {
|
||||||
const font = getDefaultSmallFont();
|
const mode = batteryDisplayModeSetting.get();
|
||||||
const percentageMode = batteryDisplayModeSetting.get() === "percentage";
|
|
||||||
type BatteryItem = { label: string; percent: number; charging: boolean };
|
|
||||||
const items: BatteryItem[] = [];
|
const items: BatteryItem[] = [];
|
||||||
const phone = readPhoneBatteryState();
|
const phone = readPhoneBatteryState();
|
||||||
if (phone.battery !== null && Number.isFinite(phone.battery)) {
|
if (phone.battery !== null && Number.isFinite(phone.battery)) {
|
||||||
items.push({ label: "Phone", percent: phone.battery, charging: Boolean(phone.charging) });
|
pushBatteryItem(items, phoneBatteryVisibilitySetting.get(), "Phone", phone.battery, Boolean(phone.charging));
|
||||||
}
|
}
|
||||||
if (state.battery.headset !== null && Number.isFinite(state.battery.headset)) {
|
if (state.battery.headset !== null && Number.isFinite(state.battery.headset)) {
|
||||||
items.push({ label: "G2", percent: state.battery.headset, charging: Boolean(state.battery.headsetCharging) });
|
pushBatteryItem(items, glassesBatteryVisibilitySetting.get(), "G2", state.battery.headset,
|
||||||
|
Boolean(state.battery.headsetCharging));
|
||||||
}
|
}
|
||||||
if (state.battery.ring !== null && Number.isInteger(state.battery.ring)
|
if (state.battery.ring !== null && Number.isInteger(state.battery.ring)
|
||||||
&& state.battery.ring >= 0 && state.battery.ring <= 100) {
|
&& state.battery.ring >= 0 && state.battery.ring <= 100) {
|
||||||
items.push({ label: "R1", percent: state.battery.ring, charging: Boolean(state.battery.ringCharging) });
|
pushBatteryItem(items, ringBatteryVisibilitySetting.get(), "R1", state.battery.ring,
|
||||||
|
Boolean(state.battery.ringCharging));
|
||||||
}
|
}
|
||||||
if (!items.length) return G2_LENS_WIDTH;
|
if (!items.length) return G2_LENS_WIDTH;
|
||||||
|
if (mode === "stacked" || mode === "stacked-percentage") {
|
||||||
|
return drawStackedBatteries(image, items, barTop, mode === "stacked-percentage");
|
||||||
|
}
|
||||||
|
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
|
const percentageMode = mode === "percentage";
|
||||||
const labelGap = 5;
|
const labelGap = 5;
|
||||||
const itemGap = 12;
|
const itemGap = 12;
|
||||||
const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
|
const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
|
||||||
let x = G2_LENS_WIDTH - 8;
|
let x = G2_LENS_WIDTH - BATTERY_BLOCK_RIGHT_MARGIN;
|
||||||
for (let index = items.length - 1; index >= 0; index--) {
|
for (let index = items.length - 1; index >= 0; index--) {
|
||||||
const item = items[index]!;
|
const item = items[index]!;
|
||||||
const percentText = `${Math.max(0, Math.min(100, Math.round(item.percent)))}%`;
|
const percentText = `${item.percent}%`;
|
||||||
const valueWidth = percentageMode ? font.measureText(percentText) : BATTERY_ICON_WIDTH;
|
const valueWidth = percentageMode ? font.measureText(percentText) : BATTERY_ICON_WIDTH;
|
||||||
const labelWidth = font.measureText(item.label);
|
const labelWidth = font.measureText(item.label);
|
||||||
x -= labelWidth + labelGap + valueWidth;
|
x -= labelWidth + labelGap + valueWidth;
|
||||||
image.drawText(font, x, textY, item.label, 150);
|
image.drawText(font, x, textY, item.label, BATTERY_LABEL_VALUE);
|
||||||
const valueX = x + labelWidth + labelGap;
|
const valueX = x + labelWidth + labelGap;
|
||||||
if (percentageMode) {
|
if (percentageMode) {
|
||||||
if (item.charging) {
|
if (item.charging) {
|
||||||
@@ -390,6 +406,74 @@ export class ShellChromeLayer implements Layer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BatteryItem = { label: string; percent: number; charging: boolean };
|
||||||
|
|
||||||
|
const BATTERY_BLOCK_RIGHT_MARGIN = 8;
|
||||||
|
const BATTERY_LABEL_VALUE = 150;
|
||||||
|
|
||||||
|
/** Append an indicator if its visibility setting shows it at this charge. */
|
||||||
|
function pushBatteryItem(
|
||||||
|
items: BatteryItem[],
|
||||||
|
visibility: BatteryIndicatorVisibility,
|
||||||
|
label: string,
|
||||||
|
percent: number,
|
||||||
|
charging: boolean,
|
||||||
|
): void {
|
||||||
|
const clamped = Math.max(0, Math.min(100, Math.round(percent)));
|
||||||
|
if (!batteryIndicatorVisible(visibility, clamped)) return;
|
||||||
|
items.push({ label, percent: clamped, charging });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stacked style geometry, in rows below the bar's top edge. The bar has 27
|
||||||
|
// usable rows above its bottom border line, too few for the user-sized UI
|
||||||
|
// font (line height up to 21px) over a 10px gauge, so both stacked lines use
|
||||||
|
// a fixed 12px bitmap face instead: TerminusV, proportional, with 8px
|
||||||
|
// capitals and digits on a 10px ascent. Ink then spans rows 3..22: label
|
||||||
|
// capitals at 3..10, a 2px gap, and the gauge at 13..22 (or the percentage
|
||||||
|
// digits at 13..20, whose charging highlight box covers 12..21), leaving 3
|
||||||
|
// rows above and 4 below (before the border) so the pair reads as one
|
||||||
|
// centered unit.
|
||||||
|
const STACKED_LABEL_BASELINE = 11;
|
||||||
|
const STACKED_ICON_TOP = 13;
|
||||||
|
const STACKED_PERCENT_BASELINE = 21;
|
||||||
|
const STACKED_ITEM_GAP = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stacked styles: each label centered above its gauge icon (or percentage
|
||||||
|
* text), right-aligned in the bar. Returns the left edge of the battery
|
||||||
|
* block.
|
||||||
|
*/
|
||||||
|
function drawStackedBatteries(image: GrayImage, items: BatteryItem[], barTop: number, percentage: boolean): number {
|
||||||
|
const font = getFont("terminusv12");
|
||||||
|
const labelTop = barTop + STACKED_LABEL_BASELINE - font.ascent;
|
||||||
|
const percentTop = barTop + STACKED_PERCENT_BASELINE - font.ascent;
|
||||||
|
let x = G2_LENS_WIDTH - BATTERY_BLOCK_RIGHT_MARGIN;
|
||||||
|
for (let index = items.length - 1; index >= 0; index--) {
|
||||||
|
const item = items[index]!;
|
||||||
|
const percentText = `${item.percent}%`;
|
||||||
|
const labelWidth = font.measureText(item.label);
|
||||||
|
const valueWidth = percentage ? font.measureText(percentText) : BATTERY_ICON_WIDTH;
|
||||||
|
const itemWidth = Math.max(labelWidth, valueWidth);
|
||||||
|
x -= itemWidth;
|
||||||
|
image.drawText(font, x + (((itemWidth - labelWidth) / 2) | 0), labelTop, item.label, BATTERY_LABEL_VALUE);
|
||||||
|
const valueX = x + (((itemWidth - valueWidth) / 2) | 0);
|
||||||
|
if (!percentage) {
|
||||||
|
const icon = drawBattery(item.percent, item.charging);
|
||||||
|
image.bitBlt(icon, valueX, barTop + STACKED_ICON_TOP, { transparentZero: true });
|
||||||
|
} else if (item.charging) {
|
||||||
|
// Inverted text marks charging, as in the side-by-side percentage style;
|
||||||
|
// the box hugs the digits' 8px ink rather than the full 12px line.
|
||||||
|
const inkTop = barTop + STACKED_PERCENT_BASELINE - 8;
|
||||||
|
image.fillRect(valueX - 2, inkTop - 1, valueWidth + 4, 10, 255);
|
||||||
|
image.drawText(font, valueX, percentTop, percentText, 1);
|
||||||
|
} else {
|
||||||
|
image.drawText(font, valueX, percentTop, percentText, 200);
|
||||||
|
}
|
||||||
|
x -= STACKED_ITEM_GAP;
|
||||||
|
}
|
||||||
|
return x + STACKED_ITEM_GAP;
|
||||||
|
}
|
||||||
|
|
||||||
// Ambient cards (encounter popups): compact and deliberately unobtrusive,
|
// Ambient cards (encounter popups): compact and deliberately unobtrusive,
|
||||||
// anchored to the bottom-right of the window band and stacking upward, clear
|
// anchored to the bottom-right of the window band and stacking upward, clear
|
||||||
// of the caption area's left-aligned text. Never interactive.
|
// of the caption area's left-aligned text. Never interactive.
|
||||||
|
|||||||
+13
-14
@@ -34,7 +34,7 @@ import {
|
|||||||
assistantBridgeTokenSetting,
|
assistantBridgeTokenSetting,
|
||||||
assistantModelSetting,
|
assistantModelSetting,
|
||||||
assistantSkipConfirmationSetting,
|
assistantSkipConfirmationSetting,
|
||||||
batteryDisplayModeSetting,
|
batteryIndicatorSettingsKey,
|
||||||
brightnessSetting,
|
brightnessSetting,
|
||||||
onAnySettingChanged,
|
onAnySettingChanged,
|
||||||
openAiApiKeySetting,
|
openAiApiKeySetting,
|
||||||
@@ -289,6 +289,11 @@ class ShellAlertLayer implements Layer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Every setting the top bar paints from, as one comparable string. */
|
||||||
|
function topBarSettingsKey(): string {
|
||||||
|
return `${batteryIndicatorSettingsKey()}|${timeFormatSetting.get()}`;
|
||||||
|
}
|
||||||
|
|
||||||
class Shell {
|
class Shell {
|
||||||
private windows: ShellWindow[] = [];
|
private windows: ShellWindow[] = [];
|
||||||
private selectedIndex = 0;
|
private selectedIndex = 0;
|
||||||
@@ -343,11 +348,10 @@ class Shell {
|
|||||||
private readonly chrome = new ShellChromeLayer(() => this.chromeState());
|
private readonly chrome = new ShellChromeLayer(() => this.chromeState());
|
||||||
private readonly stack = new LayerStack(this.chrome, this.actions);
|
private readonly stack = new LayerStack(this.chrome, this.actions);
|
||||||
|
|
||||||
// Top-bar settings we mirror into the chrome; a change to either repaints
|
// Top-bar settings we mirror into the chrome; a change to any of them
|
||||||
// the shell surface so the top bar reflects it immediately.
|
// repaints the shell surface so the top bar reflects it immediately.
|
||||||
private topBarSettingsSubscribed = false;
|
private topBarSettingsSubscribed = false;
|
||||||
private lastBatteryDisplayMode: string | null = null;
|
private lastTopBarSettingsKey: string | null = null;
|
||||||
private lastTimeFormat: string | null = null;
|
|
||||||
|
|
||||||
configure(config: ShellConfig): void {
|
configure(config: ShellConfig): void {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@@ -373,16 +377,11 @@ class Shell {
|
|||||||
private subscribeToTopBarSettings(): void {
|
private subscribeToTopBarSettings(): void {
|
||||||
if (this.topBarSettingsSubscribed) return;
|
if (this.topBarSettingsSubscribed) return;
|
||||||
this.topBarSettingsSubscribed = true;
|
this.topBarSettingsSubscribed = true;
|
||||||
this.lastBatteryDisplayMode = batteryDisplayModeSetting.get();
|
this.lastTopBarSettingsKey = topBarSettingsKey();
|
||||||
this.lastTimeFormat = timeFormatSetting.get();
|
|
||||||
onAnySettingChanged(() => {
|
onAnySettingChanged(() => {
|
||||||
const batteryMode = batteryDisplayModeSetting.get();
|
const key = topBarSettingsKey();
|
||||||
const timeFormat = timeFormatSetting.get();
|
if (key === this.lastTopBarSettingsKey) return;
|
||||||
if (batteryMode === this.lastBatteryDisplayMode && timeFormat === this.lastTimeFormat) {
|
this.lastTopBarSettingsKey = key;
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.lastBatteryDisplayMode = batteryMode;
|
|
||||||
this.lastTimeFormat = timeFormat;
|
|
||||||
this.config.requestShellRender();
|
this.config.requestShellRender();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user