Skip to content

Commit f5c40ea

Browse files
committed
refactor: simplify auto-action controls into a data-driven 2x2 grid layout
- Replace four individual button/checkbox rows (Auto-fit, Auto-Resize, Auto-Snap, Auto-calc) with a declarative actions array and a single forEach loop, cutting ~40 lines of duplicated draw logic. - Toggle width: 110 → 140 | gap: 8 → 6 | section heights adjusted (autoDetect collapsed: 160 → 120, preview: 135 → 95) to match the new compact layout. - Detected-dimensions label reflows into the remaining available width with centered fillText, replacing the previous centred-measurement approach. - Drop useCustomCalc guard in handleAutoCalc — the dissabled-state now gates the button, so the double runtime check was unnecessary.
1 parent abe71c7 commit f5c40ea

1 file changed

Lines changed: 45 additions & 70 deletions

File tree

js/ResolutionMaster.js

Lines changed: 45 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class ResolutionMasterCanvas {
126126
const sectionHeights = {
127127
actions: this.collapsedSections?.actions ? 25 : 55,
128128
scaling: this.collapsedSections?.scaling ? 25 : 130,
129-
autoDetect: this.collapsedSections?.autoDetect ? 25 : 160,
129+
autoDetect: this.collapsedSections?.autoDetect ? 25 : 120,
130130
presets: this.collapsedSections?.presets ? 25 : 90
131131
};
132132
Object.values(sectionHeights).forEach(height => {
@@ -479,7 +479,7 @@ class ResolutionMasterCanvas {
479479

480480
collapsibleSection("Auto-Detect", "autoDetect", (ctx, y, preview) => {
481481
if (!preview) return this.drawAutoDetectSection(ctx, y);
482-
return 135;
482+
return 95;
483483
});
484484

485485
collapsibleSection("Presets", "presets", (ctx, y, preview) => {
@@ -941,82 +941,57 @@ class ResolutionMasterCanvas {
941941
const props = node.properties;
942942
const margin = 20;
943943
const availableWidth = node.size[0] - margin * 2;
944-
const gap = 8;
945-
946-
const toggleWidth = 110;
944+
const gap = 6;
945+
const toggleWidth = 140;
947946
const checkboxWidth = 18;
948-
const checkboxLabelWidth = 30;
949-
const autoFitWidth = availableWidth - toggleWidth - checkboxWidth - checkboxLabelWidth - (gap * 2);
950947

951-
let currentX = margin;
952948
let currentY = y;
953-
this.controls.autoDetectToggle = { x: currentX, y: currentY, w: toggleWidth, h: 28 };
954-
this.drawToggle(ctx, currentX, currentY, toggleWidth, 28, props.autoDetect,
949+
this.controls.autoDetectToggle = { x: margin, y: currentY, w: toggleWidth, h: 28 };
950+
this.drawToggle(ctx, margin, currentY, toggleWidth, 28, props.autoDetect,
955951
props.autoDetect ? "Auto-detect ON" : "Auto-detect OFF",
956952
this.hoverElement === 'autoDetectToggle');
957-
958-
const autoFitStartX = currentX + toggleWidth + gap;
959-
this.controls.autoFitBtn = { x: autoFitStartX, y: currentY, w: autoFitWidth, h: 28 };
960-
const btnEnabled = props.selectedCategory;
961-
this.drawButton(ctx, autoFitStartX, currentY, autoFitWidth, 28, this.icons.autoFit, this.hoverElement === 'autoFitBtn', !btnEnabled, "Auto-fit");
962-
963-
const autoCheckboxX = autoFitStartX + autoFitWidth + gap;
964-
this.controls.autoFitCheckbox = { x: autoCheckboxX, y: currentY + 5, w: checkboxWidth, h: 18 };
965-
this.drawCheckbox(ctx, autoCheckboxX, currentY + 5, checkboxWidth, props.autoFitOnChange, this.hoverElement === 'autoFitCheckbox', !btnEnabled);
966-
967-
ctx.fillStyle = btnEnabled ? "#ddd" : "#777";
968-
ctx.font = "11px Arial";
969-
ctx.textAlign = "left";
970-
ctx.fillText("Auto", autoCheckboxX + checkboxWidth + 4, currentY + 14);
971-
currentY += 35;
953+
972954
if (props.autoDetect && this.detectedDimensions) {
973-
const detectedText = `Detected: ${this.detectedDimensions.width}×${this.detectedDimensions.height}`;
974-
ctx.font = "12px Arial";
975-
const textWidth = ctx.measureText(detectedText).width;
976-
const toggleCenterX = margin + (toggleWidth / 2);
977-
const textX = toggleCenterX - (textWidth / 2);
978-
this.controls.detectedInfo = { x: textX - 5, y: currentY + 2, w: textWidth + 10, h: 24 };
979-
980-
this.drawValueAreaHoverBackground(ctx, 'detectedInfo', textX - 5, currentY + 2, textWidth + 10, 20, [95, 255, 95]);
981-
955+
const detectedText = `Detected: ${this.detectedDimensions.width}x${this.detectedDimensions.height}`;
956+
const detectedX = margin + toggleWidth + gap;
957+
const detectedWidth = availableWidth - toggleWidth - gap;
958+
this.controls.detectedInfo = { x: detectedX, y: currentY + 2, w: detectedWidth, h: 24 };
959+
960+
this.drawValueAreaHoverBackground(ctx, 'detectedInfo', detectedX, currentY + 2, detectedWidth, 20, [95, 255, 95]);
961+
982962
ctx.fillStyle = this.hoverElement === 'detectedInfo' ? "#7f7" : "#5f5";
983-
ctx.textAlign = "left";
984-
ctx.fillText(detectedText, textX, currentY + 14);
963+
ctx.font = "12px Arial";
964+
ctx.textAlign = "center";
965+
ctx.textBaseline = "middle";
966+
ctx.fillText(detectedText, detectedX + detectedWidth / 2, currentY + 14);
985967
}
986-
this.controls.autoResizeBtn = { x: autoFitStartX, y: currentY, w: autoFitWidth, h: 28 };
987-
this.drawButton(ctx, autoFitStartX, currentY, autoFitWidth, 28, this.icons.autoResize, this.hoverElement === 'autoResizeBtn', false, "Auto-Resize");
988-
this.controls.autoResizeCheckbox = { x: autoCheckboxX, y: currentY + 5, w: checkboxWidth, h: 18 };
989-
this.drawCheckbox(ctx, autoCheckboxX, currentY + 5, checkboxWidth, props.autoResizeOnChange, this.hoverElement === 'autoResizeCheckbox');
990-
991-
ctx.fillStyle = "#ddd";
992-
ctx.font = "11px Arial";
993-
ctx.textAlign = "left";
994-
ctx.fillText("Auto", autoCheckboxX + checkboxWidth + 4, currentY + 14);
995-
currentY += 35;
996968

997-
this.controls.autoSnapBtn = { x: autoFitStartX, y: currentY, w: autoFitWidth, h: 28 };
998-
this.drawButton(ctx, autoFitStartX, currentY, autoFitWidth, 28, this.icons.snap, this.hoverElement === 'autoSnapBtn', false, "Auto-Snap");
999-
this.controls.autoSnapCheckbox = { x: autoCheckboxX, y: currentY + 5, w: checkboxWidth, h: 18 };
1000-
this.drawCheckbox(ctx, autoCheckboxX, currentY + 5, checkboxWidth, props.autoSnapOnChange, this.hoverElement === 'autoSnapCheckbox');
1001-
1002-
ctx.fillStyle = "#ddd";
1003-
ctx.font = "11px Arial";
1004-
ctx.textAlign = "left";
1005-
ctx.fillText("Auto", autoCheckboxX + checkboxWidth + 4, currentY + 14);
1006969
currentY += 35;
1007-
1008-
this.controls.autoCalcBtn = { x: autoFitStartX, y: currentY, w: autoFitWidth, h: 28 };
1009-
const calcEnabled = props.useCustomCalc && props.selectedCategory;
1010-
this.drawButton(ctx, autoFitStartX, currentY, autoFitWidth, 28, this.icons.autoCalculate, this.hoverElement === 'autoCalcBtn', !calcEnabled, "Auto-calc");
1011-
this.controls.customCalcCheckbox = { x: autoCheckboxX, y: currentY + 5, w: checkboxWidth, h: 18 };
1012-
this.drawCheckbox(ctx, autoCheckboxX, currentY + 5, checkboxWidth, props.useCustomCalc, this.hoverElement === 'customCalcCheckbox');
1013-
1014-
ctx.fillStyle = "#ddd";
1015-
ctx.font = "11px Arial";
1016-
ctx.textAlign = "left";
1017-
ctx.fillText("Calc", autoCheckboxX + checkboxWidth + 4, currentY + 14);
1018-
1019-
return 135;
970+
971+
const actionGap = 8;
972+
const rowGap = 6;
973+
const actionWidth = (availableWidth - actionGap) / 2;
974+
const actionButtonWidth = actionWidth - checkboxWidth - 4;
975+
const calcEnabled = !!props.selectedCategory;
976+
const actions = [
977+
{ button: 'autoFitBtn', checkbox: 'autoFitCheckbox', icon: this.icons.autoFit, label: 'Fit', checked: props.autoFitOnChange, disabled: !props.selectedCategory, col: 0, row: 0 },
978+
{ button: 'autoResizeBtn', checkbox: 'autoResizeCheckbox', icon: this.icons.autoResize, label: 'Resize', checked: props.autoResizeOnChange, disabled: false, col: 0, row: 1 },
979+
{ button: 'autoSnapBtn', checkbox: 'autoSnapCheckbox', icon: this.icons.snap, label: 'Snap', checked: props.autoSnapOnChange, disabled: false, col: 1, row: 0 },
980+
{ button: 'autoCalcBtn', checkbox: 'customCalcCheckbox', icon: this.icons.autoCalculate, label: 'Calc', checked: props.useCustomCalc, disabled: !calcEnabled, col: 1, row: 1 }
981+
];
982+
983+
actions.forEach((action) => {
984+
const x = margin + action.col * (actionWidth + actionGap);
985+
const actionY = currentY + action.row * (28 + rowGap);
986+
this.controls[action.button] = { x, y: actionY, w: actionButtonWidth, h: 28 };
987+
this.drawButton(ctx, x, actionY, actionButtonWidth, 28, action.icon, this.hoverElement === action.button, action.disabled, action.label);
988+
989+
const checkboxX = x + actionButtonWidth + 4;
990+
this.controls[action.checkbox] = { x: checkboxX, y: actionY + 5, w: checkboxWidth, h: 18 };
991+
this.drawCheckbox(ctx, checkboxX, actionY + 5, checkboxWidth, action.checked, this.hoverElement === action.checkbox, action.disabled);
992+
});
993+
994+
return 95;
1020995
}
1021996

1022997
drawPresetSection(ctx, y) {
@@ -2341,8 +2316,8 @@ class ResolutionMasterCanvas {
23412316
handleAutoCalc() {
23422317
const props = this.node.properties;
23432318

2344-
if (!props.useCustomCalc || !props.selectedCategory) {
2345-
log.debug("Auto-calc: Calc checkbox or category not selected");
2319+
if (!props.selectedCategory) {
2320+
log.debug("Auto-calc: Category not selected");
23462321
return;
23472322
}
23482323

0 commit comments

Comments
 (0)