diff --git a/src/components/designer-controls/LabelPropsEditor.svelte b/src/components/designer-controls/LabelPropsEditor.svelte index 3545966..99f0e48 100644 --- a/src/components/designer-controls/LabelPropsEditor.svelte +++ b/src/components/designer-controls/LabelPropsEditor.svelte @@ -50,7 +50,34 @@ let tailLength = $state(0); let tailPos = $state("right"); let mirror = $state("none"); - let error = $state(""); + + let error = $derived.by(() => { + let error = ""; + + const headSize = labelProps.printDirection == "left" ? labelProps.size.height : labelProps.size.width; + if ($printerMeta !== undefined) { + if (headSize > $printerMeta.printheadPixels) { + error += $tr("params.label.warning.width") + " "; + error += `(${headSize} > ${$printerMeta.printheadPixels})`; + error += "\n"; + } + + if ($printerMeta.printDirection !== labelProps.printDirection) { + error += $tr("params.label.warning.direction") + " "; + if ($printerMeta.printDirection == "left") { + error += $tr("params.label.direction.left"); + } else { + error += $tr("params.label.direction.top"); + } + } + } + + if (headSize % 8 !== 0) { + error += $tr("params.label.warning.div8"); + } + + return error; + }); const onApply = () => { let newWidth = width; @@ -163,32 +190,6 @@ prevUnit = unit; }; - const checkError = (props: LabelProps) => { - error = ""; - - const headSize = props.printDirection == "left" ? props.size.height : props.size.width; - if ($printerMeta !== undefined) { - if (headSize > $printerMeta.printheadPixels) { - error += $tr("params.label.warning.width") + " "; - error += `(${headSize} > ${$printerMeta.printheadPixels})`; - error += "\n"; - } - - if ($printerMeta.printDirection !== props.printDirection) { - error += $tr("params.label.warning.direction") + " "; - if ($printerMeta.printDirection == "left") { - error += $tr("params.label.direction.left"); - } else { - error += $tr("params.label.direction.top"); - } - } - } - - if (headSize % 8 !== 0) { - error += $tr("params.label.warning.div8"); - } - }; - const fillWithCurrentParams = () => { prevUnit = "px"; width = labelProps.size.width; @@ -253,21 +254,17 @@ tick().then(() => fillWithCurrentParams()); }); - $effect(() => { - checkError(labelProps); - }); $effect(() => { if (shape === "circle" && split !== "none") split = "none"; }); + $effect(() => { - if (split === "none") tailLength = 0; + if (split === "none" || tailLength < 0) tailLength = 0; }); + $effect(() => { if (mirror === "flip" && splitParts !== 2) mirror = "copy"; }); - $effect(() => { - if (tailLength < 0) tailLength = 0; - });