1
0
mirror of https://github.com/MultiMote/niimblue synced 2026-01-19 19:37:11 +03:00

Fix splitParts optional

This commit is contained in:
MultiMote
2025-05-18 23:22:21 +03:00
parent 5f7cff7cbd
commit cdfdc55912
2 changed files with 12 additions and 9 deletions

View File

@@ -110,23 +110,24 @@ export class CustomCanvas extends fabric.Canvas {
getFoldInfo(): FoldInfo {
const bb = this.getLabelBounds();
const points: number[] = [];
const splitParts = this.labelProps.splitParts ?? 2;
if (this.labelProps.splitParts < 2) {
if (splitParts < 2) {
return { axis: "none", points };
}
if (this.labelProps.split === "horizontal") {
const segmentHeight = bb.height / this.labelProps.splitParts;
const segmentHeight = bb.height / splitParts;
for (let i = 1; i < this.labelProps.splitParts; i++) {
for (let i = 1; i < splitParts; i++) {
points.push(bb.startY + segmentHeight * i - this.SEPARATOR_LINE_WIDTH / 2 + 1);
}
return { axis: "horizontal", points };
} else if (this.labelProps.split === "vertical") {
const segmentWidth = bb.width / this.labelProps.splitParts;
const segmentWidth = bb.width / splitParts;
for (let i = 1; i < this.labelProps.splitParts; i++) {
for (let i = 1; i < splitParts; i++) {
points.push(bb.startX + segmentWidth * i - this.SEPARATOR_LINE_WIDTH / 2 + 1);
}
@@ -199,13 +200,15 @@ export class CustomCanvas extends fabric.Canvas {
ctx.beginPath();
const splitParts = this.labelProps.splitParts ?? 2;
if (this.labelProps.shape === "rounded_rect") {
if (this.labelProps.split === "horizontal") {
const segmentHeight = bb.height / this.labelProps.splitParts;
const segmentHeight = bb.height / splitParts;
ctx.roundRect(bb.startX, bb.startY, bb.width, segmentHeight, roundRadius); // First part
fold.points.forEach((y) => ctx.roundRect(bb.startX, y, bb.width, segmentHeight, roundRadius)); // Other parts
} else if (this.labelProps.split === "vertical") {
const segmentWidth = bb.width / this.labelProps.splitParts;
const segmentWidth = bb.width / splitParts;
ctx.roundRect(bb.startX, bb.startY, segmentWidth, bb.height, roundRadius); // First part
fold.points.forEach((x) => ctx.roundRect(x, bb.startY, segmentWidth, bb.height, roundRadius)); // Other parts
} else {

View File

@@ -27,7 +27,7 @@ export const LabelPropsSchema = z.object({
}),
shape: z.enum(["rect", "rounded_rect", "circle"]).default("rect").optional(),
split: z.enum(["none", "vertical", "horizontal"]).default("none").optional(),
splitParts: z.number().min(1).default(2),
splitParts: z.number().min(1).default(2).optional(),
tailPos: z.enum(["right", "bottom", "left", "top"]).default("right").optional(),
tailLength: z.number().default(0).optional(),
mirror: z.enum(["none", "copy", "flip"]).default("none").optional(),
@@ -42,7 +42,7 @@ export const LabelPresetSchema = z.object({
title: z.string().optional(),
shape: z.enum(["rect", "rounded_rect", "circle"]).default("rect").optional(),
split: z.enum(["none", "vertical", "horizontal"]).default("none").optional(),
splitParts: z.number().min(1).default(2),
splitParts: z.number().min(1).default(2).optional(),
tailPos: z.enum(["right", "bottom", "left", "top"]).default("right").optional(),
tailLength: z.number().default(0).optional(),
mirror: z.enum(["none", "copy", "flip"]).default("none").optional(),