fix: fix sizing of win-pane in fixed layout

This commit is contained in:
Alois Klink
2024-09-27 21:29:47 +09:00
parent b32acb619c
commit aae4e6f048

View File

@@ -4,15 +4,32 @@ import { styles2String, userNodeOverrides } from './handDrawnShapeStyles.js';
import rough from 'roughjs'; import rough from 'roughjs';
import intersect from '../intersect/index.js'; import intersect from '../intersect/index.js';
/// Width of the frame on the top and left of the shape
const rectOffset = 5;
export const windowPane = async (parent: SVGAElement, node: Node) => { export const windowPane = async (parent: SVGAElement, node: Node) => {
const { labelStyles, nodeStyles } = styles2String(node); const { labelStyles, nodeStyles } = styles2String(node);
node.labelStyle = labelStyles; node.labelStyle = labelStyles;
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node));
const paddingX = node.look === 'neo' ? (node.padding ?? 0) * 2 : (node.padding ?? 0); const paddingX = node.look === 'neo' ? (node.padding ?? 0) * 2 : (node.padding ?? 0);
const paddingY = node.look === 'neo' ? (node.padding ?? 0) * 2 : (node.padding ?? 0); const paddingY = node.look === 'neo' ? (node.padding ?? 0) * 2 : (node.padding ?? 0);
const w = Math.max(bbox.width + paddingX * 2, node?.width ?? 0);
const h = Math.max(bbox.height + paddingY * 2, node?.height ?? 0); // If incoming height & width are present, subtract the padding from them
const rectOffset = 5; // as labelHelper does not take padding into account
// also check if the width or height is less than minimum default values (50),
// if so set it to min value
if (node.width || node.height) {
node.width = Math.max((node?.width ?? 0) - paddingX * 2 - rectOffset, 50);
node.height = Math.max((node?.height ?? 0) - paddingY * 2 - rectOffset, 50);
}
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node));
const totalWidth = Math.max(bbox.width, node?.width ?? 0) + paddingX * 2 + rectOffset;
const totalHeight = Math.max(bbox.height, node?.height ?? 0) + paddingY * 2 + rectOffset;
const w = totalWidth - rectOffset;
const h = totalHeight - rectOffset;
const x = -w / 2; const x = -w / 2;
const y = -h / 2; const y = -h / 2;
const { cssStyles } = node; const { cssStyles } = node;