forked from johannesjo/parallel-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.ts
More file actions
119 lines (96 loc) · 3.2 KB
/
ui.ts
File metadata and controls
119 lines (96 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { produce } from 'solid-js/store';
import { store, setStore } from './core';
import type { TerminalFont } from '../lib/fonts';
import type { LookPreset } from '../lib/look';
import type { PersistedWindowState } from './types';
// --- Font Scale (per-panel) ---
const MIN_SCALE = 0.5;
const MAX_SCALE = 2.0;
const SCALE_STEP = 0.1;
export function getFontScale(panelId: string): number {
return store.fontScales[panelId] ?? 1;
}
export function adjustFontScale(panelId: string, delta: 1 | -1): void {
const current = getFontScale(panelId);
const next =
Math.round(Math.min(MAX_SCALE, Math.max(MIN_SCALE, current + delta * SCALE_STEP)) * 10) / 10;
setStore('fontScales', panelId, next);
}
export function resetFontScale(panelId: string): void {
if (panelId.includes(':')) {
setStore('fontScales', panelId, 1.0);
} else {
setStore(
produce((s) => {
const prefix = panelId + ':';
for (const key of Object.keys(s.fontScales)) {
if (key === panelId || key.startsWith(prefix)) s.fontScales[key] = 1.0;
}
}),
);
}
}
// --- Global Scale ---
export function getGlobalScale(): number {
return store.globalScale;
}
export function adjustGlobalScale(delta: 1 | -1): void {
const current = store.globalScale;
const next =
Math.round(Math.min(MAX_SCALE, Math.max(MIN_SCALE, current + delta * SCALE_STEP)) * 10) / 10;
setStore('globalScale', next);
}
export function resetGlobalScale(): void {
setStore('globalScale', 1);
}
// --- Panel Sizes ---
export function getPanelSize(key: string): number | undefined {
return store.panelSizes[key];
}
export function setPanelSizes(entries: Record<string, number>): void {
for (const [key, value] of Object.entries(entries)) {
setStore('panelSizes', key, value);
}
}
// --- Sidebar ---
export function toggleSidebar(): void {
setStore('sidebarVisible', !store.sidebarVisible);
}
export function setTerminalFont(terminalFont: TerminalFont): void {
setStore('terminalFont', terminalFont);
}
export function setThemePreset(themePreset: LookPreset): void {
setStore('themePreset', themePreset);
}
export function setAutoTrustFolders(autoTrustFolders: boolean): void {
setStore('autoTrustFolders', autoTrustFolders);
}
export function setShowPlans(showPlans: boolean): void {
setStore('showPlans', showPlans);
}
export function setDesktopNotificationsEnabled(enabled: boolean): void {
setStore('desktopNotificationsEnabled', enabled);
}
export function setInactiveColumnOpacity(opacity: number): void {
setStore('inactiveColumnOpacity', Math.round(Math.max(0.3, Math.min(1.0, opacity)) * 100) / 100);
}
export function setEditorCommand(command: string): void {
setStore('editorCommand', command);
}
export function toggleArena(show?: boolean): void {
setStore('showArena', show ?? !store.showArena);
}
export function setWindowState(windowState: PersistedWindowState): void {
const current = store.windowState;
if (
current &&
current.x === windowState.x &&
current.y === windowState.y &&
current.width === windowState.width &&
current.height === windowState.height &&
current.maximized === windowState.maximized
) {
return;
}
setStore('windowState', windowState);
}