fix: align widget layouts with visible board size

This commit is contained in:
ajnart committed 2026-09-09 15:19:03 +02:00
1 parent 19a887ea55
commit c8c0458764
61 files changed
+580 -190

No files matched your search

@@ -27,7 +27,7 @@ import { WidgetCardShell, WidgetTitleBadge } from "@homarr/widgets/widget-card-s
import type { SectionItem } from "~/app/[locale]/boards/_types";
import { getLogicalTrackSize } from "~/components/board/layout";
import { useBoardCanvasScale } from "~/components/board/layout/scaled-board-canvas";
import { useBoardContentScale } from "~/components/board/layout/scaled-board-canvas";
import advancedFocusClasses from "../advanced-focus/advanced-focus.module.css";
import { useAdvancedFocus } from "../advanced-focus/context";
import { startAdvancedFocusEntrance } from "../advanced-focus/entrance";
@@ -148,7 +148,7 @@ const LoadedBoardItemContent = ({
const cardRef = useRef<HTMLDivElement>(null);
const previewEntranceFrameRef = useRef<number | null>(null);
const board = useRequiredBoard();
const boardCanvasScale = useBoardCanvasScale();
const boardContentScale = useBoardContentScale();
const t = useI18n();
const [isEditMode] = useEditMode();
const settings = useSettings();
@@ -163,8 +163,8 @@ const LoadedBoardItemContent = ({
const supportsAdvancedFocus = definitionSupportsAdvancedFocus(definition);
const widgetName = getWidgetName(item.kind, t);
const previewDimensions = useMemo(
() => ({ width, height, scale: boardCanvasScale }),
[boardCanvasScale, height, width],
() => ({ width, height, scale: boardContentScale }),
[boardContentScale, height, width],
);
const advancedViewLabel = t("item.advancedFocus.label", { widget: widgetName });
const advancedViewId = `advanced-focus-${item.id}`;
@@ -314,7 +314,7 @@ const LoadedBoardItemContent = ({
item={item}
width={width}
height={height}
displayScale={boardCanvasScale}
displayScale={boardContentScale}
widgetStateRef={widgetStateRef}
widgetRuntimeRef={widgetRuntimeRef}
displayMode={isAdvanced ? "advanced" : "compact"}
@@ -8,6 +8,10 @@ import { useElementSize } from "@mantine/hooks";
import classes from "./scaled-board-canvas.module.css";
const BoardCanvasScaleContext = createContext(1);
// Widget content can also be scaled by containers inside the board canvas.
const BoardContentScaleContext = createContext(1);
export const BoardContentScaleProvider = BoardContentScaleContext.Provider;
export const useBoardContentScale = () => useContext(BoardContentScaleContext);
export const useBoardCanvasScale = () => useContext(BoardCanvasScaleContext);
@@ -86,7 +90,9 @@ export const ScaledBoardCanvas = ({
zoom: scale,
}}
>
<BoardCanvasScaleContext.Provider value={scale}>{children}</BoardCanvasScaleContext.Provider>
<BoardCanvasScaleContext.Provider value={scale}>
<BoardContentScaleProvider value={scale}>{children}</BoardContentScaleProvider>
</BoardCanvasScaleContext.Provider>
</Box>
</Box>
</Box>
@@ -18,7 +18,12 @@ import {
getReadonlyCanvasAttributes,
normalizeGridPlacement,
} from "~/components/board/layout";
import { calculateBoardUiScale, useBoardCanvasScale } from "~/components/board/layout/scaled-board-canvas";
import {
BoardContentScaleProvider,
calculateBoardUiScale,
useBoardCanvasScale,
useBoardContentScale,
} from "~/components/board/layout/scaled-board-canvas";
import { useGridEditorRuntimeStatus } from "./grid-editor-runtime";
import { createGridEntryElementStore, useGridEditorRegistry } from "./grid-editor-registry";
import type { SectionGridPlacement } from "./use-grid-layout-actions";
@@ -50,6 +55,7 @@ export const SectionGrid = ({
}: SectionGridProps) => {
const [isEditMode] = useEditMode();
const canvasScale = useBoardCanvasScale();
const parentContentScale = useBoardContentScale();
const editorRuntimeStatus = useGridEditorRuntimeStatus();
const editorRegistry = useGridEditorRegistry();
const editorHostRef = useRef<HTMLDivElement>(null);
@@ -327,7 +333,9 @@ export const SectionGrid = ({
data-kind={section.kind}
data-grid-editor-error={isEditMode && editorRuntimeStatus === "error" ? "true" : undefined}
>
<SectionContent />
<BoardContentScaleProvider value={parentContentScale * containerContentScale}>
<SectionContent />
</BoardContentScaleProvider>
</Box>
<div ref={editorHostRef} className={classes.editorPortalHost} />
</Box>