Skip to content

Commit 8059b87

Browse files
committed
feat: add Auto-Snap toggle with checkbox and button to auto-detect controls
- New autoSnapOnChange property on ResolutionMasterCanvas with persistent default - Auto-Snap button and checkbox rendered in the Auto-detect / Auto-Resize UI area - autoSnapCheckbox click toggles autoSnapOnChange in the click handler map - handleSnap() is automatically called after image detection when autoSnapOnChange is true - autoDetect section height raised 125→160 and Collapse Presets section height raised 100→135 to accommodate new control - Tooltip keys added in ResolutionMasterConfig.js: autoSnapBtn, autoSnapCheckbox
1 parent ad77959 commit 8059b87

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

js/ResolutionMaster.js

Lines changed: 21 additions & 3 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 : 125,
129+
autoDetect: this.collapsedSections?.autoDetect ? 25 : 160,
130130
presets: this.collapsedSections?.presets ? 25 : 90
131131
};
132132
Object.values(sectionHeights).forEach(height => {
@@ -175,6 +175,7 @@ class ResolutionMasterCanvas {
175175
autoDetect: false,
176176
autoFitOnChange: false,
177177
autoResizeOnChange: false,
178+
autoSnapOnChange: false,
178179
selectedCategory: "Standard",
179180
selectedPreset: null,
180181
useCustomCalc: false,
@@ -478,7 +479,7 @@ class ResolutionMasterCanvas {
478479

479480
collapsibleSection("Auto-Detect", "autoDetect", (ctx, y, preview) => {
480481
if (!preview) return this.drawAutoDetectSection(ctx, y);
481-
return 100;
482+
return 135;
482483
});
483484

484485
collapsibleSection("Presets", "presets", (ctx, y, preview) => {
@@ -987,6 +988,17 @@ class ResolutionMasterCanvas {
987988
this.controls.autoResizeCheckbox = { x: autoCheckboxX, y: currentY + 5, w: checkboxWidth, h: 18 };
988989
this.drawCheckbox(ctx, autoCheckboxX, currentY + 5, checkboxWidth, props.autoResizeOnChange, this.hoverElement === 'autoResizeCheckbox');
989990

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;
996+
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+
9901002
ctx.fillStyle = "#ddd";
9911003
ctx.font = "11px Arial";
9921004
ctx.textAlign = "left";
@@ -1004,7 +1016,7 @@ class ResolutionMasterCanvas {
10041016
ctx.textAlign = "left";
10051017
ctx.fillText("Calc", autoCheckboxX + checkboxWidth + 4, currentY + 14);
10061018

1007-
return 100;
1019+
return 135;
10081020
}
10091021

10101022
drawPresetSection(ctx, y) {
@@ -1640,6 +1652,7 @@ class ResolutionMasterCanvas {
16401652
megapixelsBtn: () => this.handleMegapixelsScale(),
16411653
autoFitBtn: () => this.handleAutoFit(),
16421654
autoResizeBtn: () => this.handleAutoResize(),
1655+
autoSnapBtn: () => this.handleSnap(),
16431656
autoCalcBtn: () => this.handleAutoCalc(),
16441657
detectedInfo: () => this.handleDetectedClick(),
16451658
managePresetsBtn: () => this.handleManagePresets(),
@@ -1720,6 +1733,8 @@ class ResolutionMasterCanvas {
17201733
props.autoFitOnChange = !props.autoFitOnChange;
17211734
} else if (checkboxName === 'autoResizeCheckbox') {
17221735
props.autoResizeOnChange = !props.autoResizeOnChange;
1736+
} else if (checkboxName === 'autoSnapCheckbox') {
1737+
props.autoSnapOnChange = !props.autoSnapOnChange;
17231738
} else if (checkboxName === 'customCalcCheckbox') {
17241739
props.useCustomCalc = !props.useCustomCalc;
17251740
} else if (checkboxName === 'preserveScalingRatioCheckbox') {
@@ -2670,6 +2685,9 @@ class ResolutionMasterCanvas {
26702685
if (props.autoResizeOnChange) {
26712686
this.handleAutoResize();
26722687
}
2688+
if (props.autoSnapOnChange) {
2689+
this.handleSnap();
2690+
}
26732691
if (props.useCustomCalc && props.selectedCategory) {
26742692
this.handleAutoCalc();
26752693
}

js/utils/ResolutionMasterConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export const tooltips = {
3434
autoFitCheckbox: "Automatically find and apply the best preset for the new detected image resolution",
3535
autoResizeBtn: "Apply scaling based on selected mode (Manual/Resolution/Megapixels)",
3636
autoResizeCheckbox: "Automatically apply scaling when new image is detected",
37+
autoSnapBtn: "Snap current resolution to the nearest snap value",
38+
autoSnapCheckbox: "Automatically snap after Auto-Resize when a new image is detected",
3739
detectedInfo: "Click to apply detected image resolution directly",
3840

3941
// Preset controls

0 commit comments

Comments
 (0)