fix: persist layout panel widths
This commit is contained in:
@@ -3,7 +3,7 @@ import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
const MAIN_WINDOW_MIN_HEIGHT = 400
|
||||
const EDITOR_ONLY_MAIN_WINDOW_MIN_WIDTH = 480
|
||||
const MAIN_WINDOW_SIDEBAR_MIN_WIDTH = 180
|
||||
const MAIN_WINDOW_SIDEBAR_MIN_WIDTH = 220
|
||||
const MAIN_WINDOW_NOTE_LIST_MIN_WIDTH = 220
|
||||
const MAIN_WINDOW_INSPECTOR_MIN_WIDTH = 240
|
||||
|
||||
@@ -11,22 +11,34 @@ export type MainWindowPaneVisibility = {
|
||||
sidebarVisible: boolean
|
||||
noteListVisible: boolean
|
||||
inspectorCollapsed: boolean
|
||||
sidebarWidth?: number
|
||||
noteListWidth?: number
|
||||
inspectorWidth?: number
|
||||
}
|
||||
|
||||
export function getMainWindowMinWidth({
|
||||
sidebarVisible,
|
||||
noteListVisible,
|
||||
inspectorCollapsed,
|
||||
sidebarWidth,
|
||||
noteListWidth,
|
||||
inspectorWidth,
|
||||
}: MainWindowPaneVisibility): number {
|
||||
let minWidth = EDITOR_ONLY_MAIN_WINDOW_MIN_WIDTH
|
||||
|
||||
if (sidebarVisible) minWidth += MAIN_WINDOW_SIDEBAR_MIN_WIDTH
|
||||
if (noteListVisible) minWidth += MAIN_WINDOW_NOTE_LIST_MIN_WIDTH
|
||||
if (!inspectorCollapsed) minWidth += MAIN_WINDOW_INSPECTOR_MIN_WIDTH
|
||||
if (sidebarVisible) minWidth += getPaneWidth(sidebarWidth, MAIN_WINDOW_SIDEBAR_MIN_WIDTH)
|
||||
if (noteListVisible) minWidth += getPaneWidth(noteListWidth, MAIN_WINDOW_NOTE_LIST_MIN_WIDTH)
|
||||
if (!inspectorCollapsed) minWidth += getPaneWidth(inspectorWidth, MAIN_WINDOW_INSPECTOR_MIN_WIDTH)
|
||||
|
||||
return minWidth
|
||||
}
|
||||
|
||||
function getPaneWidth(width: number | undefined, minimum: number): number {
|
||||
return typeof width === 'number' && Number.isFinite(width)
|
||||
? Math.max(minimum, Math.round(width))
|
||||
: minimum
|
||||
}
|
||||
|
||||
type MainWindowSizeConstraintsOptions = MainWindowPaneVisibility & {
|
||||
enabled?: boolean
|
||||
}
|
||||
@@ -46,11 +58,17 @@ export function useMainWindowSizeConstraints({
|
||||
sidebarVisible,
|
||||
noteListVisible,
|
||||
inspectorCollapsed,
|
||||
sidebarWidth,
|
||||
noteListWidth,
|
||||
inspectorWidth,
|
||||
}: MainWindowSizeConstraintsOptions): void {
|
||||
const minWidth = getMainWindowMinWidth({
|
||||
sidebarVisible,
|
||||
noteListVisible,
|
||||
inspectorCollapsed,
|
||||
sidebarWidth,
|
||||
noteListWidth,
|
||||
inspectorWidth,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user