Skip to content

Commit 8d7f310

Browse files
committed
feat: add calcInfoToggle for independently controlling calc info message visibility
- Add showCalcInfo state prop (default false) to control whether the model-specific calc info message is displayed, decoupling it from useCustomCalc - Add a new Show/Hide toggle button next to the Calc action button in the actions grid - Simplify drawInfoMessage conditions: messages now render whenever a category is selected, using showCalcInfo as the visibility gate instead of useCustomCalc - Resize autoDetect section header (120->135) and actions section height (95->110) to accommodate the new toggle control - Add textOffset parameter to drawButton for improved text alignment - Add calcInfoToggle tooltip in ResolutionMasterConfig
1 parent f5c40ea commit 8d7f310

2 files changed

Lines changed: 44 additions & 24 deletions

File tree

js/ResolutionMaster.js

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ 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 : 120,
129+
autoDetect: this.collapsedSections?.autoDetect ? 25 : 135,
130130
presets: this.collapsedSections?.presets ? 25 : 90
131131
};
132132
Object.values(sectionHeights).forEach(height => {
133133
currentY += height + spacing;
134134
});
135-
if (props.useCustomCalc && props.selectedCategory) {
135+
if (props.showCalcInfo && props.selectedCategory) {
136136
currentY += 40;
137137
}
138138

@@ -179,6 +179,7 @@ class ResolutionMasterCanvas {
179179
selectedCategory: "Standard",
180180
selectedPreset: null,
181181
useCustomCalc: false,
182+
showCalcInfo: false,
182183
manual_slider_min_w: 64,
183184
manual_slider_max_w: 2048,
184185
manual_slider_step_w: 64,
@@ -479,14 +480,14 @@ class ResolutionMasterCanvas {
479480

480481
collapsibleSection("Auto-Detect", "autoDetect", (ctx, y, preview) => {
481482
if (!preview) return this.drawAutoDetectSection(ctx, y);
482-
return 95;
483+
return 110;
483484
});
484485

485486
collapsibleSection("Presets", "presets", (ctx, y, preview) => {
486487
if (!preview) return this.drawPresetSection(ctx, y);
487488
return 30;
488489
});
489-
if (props.useCustomCalc && props.selectedCategory) {
490+
if (props.showCalcInfo && props.selectedCategory) {
490491
const messageHeight = this.drawInfoMessage(ctx, currentY);
491492
if (messageHeight > 0) {
492493
currentY += messageHeight + spacing;
@@ -972,26 +973,41 @@ class ResolutionMasterCanvas {
972973
const rowGap = 6;
973974
const actionWidth = (availableWidth - actionGap) / 2;
974975
const actionButtonWidth = actionWidth - checkboxWidth - 4;
976+
const showToggleWidth = 56;
975977
const calcEnabled = !!props.selectedCategory;
976978
const actions = [
977979
{ button: 'autoFitBtn', checkbox: 'autoFitCheckbox', icon: this.icons.autoFit, label: 'Fit', checked: props.autoFitOnChange, disabled: !props.selectedCategory, col: 0, row: 0 },
978980
{ button: 'autoResizeBtn', checkbox: 'autoResizeCheckbox', icon: this.icons.autoResize, label: 'Resize', checked: props.autoResizeOnChange, disabled: false, col: 0, row: 1 },
979981
{ 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 }
982+
{ button: 'autoCalcBtn', checkbox: 'customCalcCheckbox', icon: this.icons.autoCalculate, label: 'Calc', checked: props.useCustomCalc, disabled: !calcEnabled, col: 1, row: 1, showInfoToggle: true, textOffset: 8 }
981983
];
982984

983985
actions.forEach((action) => {
984986
const x = margin + action.col * (actionWidth + actionGap);
985987
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);
988+
const buttonWidth = action.showInfoToggle ? actionWidth - checkboxWidth - showToggleWidth - 8 : actionButtonWidth;
989+
this.controls[action.button] = { x, y: actionY, w: buttonWidth, h: 28 };
990+
this.drawButton(ctx, x, actionY, buttonWidth, 28, action.icon, this.hoverElement === action.button, action.disabled, action.label, false, action.textOffset || 0);
991+
992+
if (action.showInfoToggle) {
993+
const toggleX = x + buttonWidth + 4;
994+
this.controls.calcInfoToggle = { x: toggleX, y: actionY + 3, w: showToggleWidth, h: 22 };
995+
const previousAlpha = ctx.globalAlpha;
996+
if (action.disabled) ctx.globalAlpha = 0.5;
997+
this.drawToggle(ctx, toggleX, actionY + 3, showToggleWidth, 22, props.showCalcInfo, "Show", this.hoverElement === 'calcInfoToggle');
998+
ctx.globalAlpha = previousAlpha;
999+
1000+
const checkboxX = toggleX + showToggleWidth + 4;
1001+
this.controls[action.checkbox] = { x: checkboxX, y: actionY + 5, w: checkboxWidth, h: 18 };
1002+
this.drawCheckbox(ctx, checkboxX, actionY + 5, checkboxWidth, action.checked, this.hoverElement === action.checkbox, action.disabled);
1003+
} else {
1004+
const checkboxX = x + buttonWidth + 4;
1005+
this.controls[action.checkbox] = { x: checkboxX, y: actionY + 5, w: checkboxWidth, h: 18 };
1006+
this.drawCheckbox(ctx, checkboxX, actionY + 5, checkboxWidth, action.checked, this.hoverElement === action.checkbox, action.disabled);
1007+
}
9921008
});
9931009

994-
return 95;
1010+
return 110;
9951011
}
9961012

9971013
drawPresetSection(ctx, y) {
@@ -1036,23 +1052,23 @@ class ResolutionMasterCanvas {
10361052
const category = props.selectedCategory;
10371053

10381054
let message = "";
1039-
if (category === "SDXL" && props.useCustomCalc) {
1055+
if (category === "SDXL") {
10401056
message = "💡 SDXL Mode: Only using presets!";
1041-
} else if (category === "Flux" && props.useCustomCalc) {
1057+
} else if (category === "Flux") {
10421058
message = "💡 FLUX Mode: Round to: 32px | Edge range: 320-2560px | Max resolution: 4.0 MP";
1043-
} else if (category === "Flux.2" && props.useCustomCalc) {
1059+
} else if (category === "Flux.2") {
10441060
message = "💡 FLUX.2 Mode: Round to: 16px | Edge range: 320-3840px | Max resolution: 6.0 MP";
1045-
} else if (category === "WAN" && props.useCustomCalc && this.widthWidget && this.heightWidget) {
1061+
} else if (category === "WAN" && this.widthWidget && this.heightWidget) {
10461062
const pixels = this.widthWidget.value * this.heightWidget.value;
10471063
const model = pixels < 600000 ? "480p" : "720p";
10481064
message = `💡 WAN Mode: Suggesting ${model} model | Round to: 16px | Resolution range: 320p-820p`;
1049-
} else if (category === "HiDream Dev" && props.useCustomCalc) {
1065+
} else if (category === "HiDream Dev") {
10501066
message = "💡 HiDream Dev: Only using presets!";
1051-
} else if (category === "Qwen-Image" && props.useCustomCalc) {
1067+
} else if (category === "Qwen-Image") {
10521068
message = "💡 Qwen-Image: Resolution range: ~0.6MP-4.2MP. If input is already in this range, it remains unchanged.";
1053-
} else if (['Standard', 'Social Media', 'Print', 'Cinema'].includes(category) && props.useCustomCalc) {
1069+
} else if (['Standard', 'Social Media', 'Print', 'Cinema'].includes(category)) {
10541070
message = "💡 Calc Mode: Scales the selected preset to the closest current resolution, maintaining the preset's aspect ratio.";
1055-
} else if (props.useCustomCalc) {
1071+
} else {
10561072
message = "⚠️ Calc Mode: Custom calculation not available for this category)";
10571073
}
10581074

@@ -1126,7 +1142,7 @@ class ResolutionMasterCanvas {
11261142

11271143
return y + 45;
11281144
}
1129-
drawButton(ctx, x, y, w, h, content, hover = false, disabled = false, text = null, centerIconAndText = false) {
1145+
drawButton(ctx, x, y, w, h, content, hover = false, disabled = false, text = null, centerIconAndText = false, textOffset = 0) {
11301146
const grad = ctx.createLinearGradient(x, y, x, y + h);
11311147
if (disabled) {
11321148
grad.addColorStop(0, "#4a4a4a");
@@ -1203,7 +1219,7 @@ class ResolutionMasterCanvas {
12031219
ctx.fillText(text, textX, y + h / 2 + 1);
12041220
} else {
12051221
ctx.textAlign = "center";
1206-
ctx.fillText(text, x + w / 2, y + h / 2 + 1);
1222+
ctx.fillText(text, x + w / 2 + textOffset, y + h / 2 + 1);
12071223
}
12081224
}
12091225
}
@@ -1699,6 +1715,9 @@ class ResolutionMasterCanvas {
16991715
const widget = this.node.widgets?.find(w => w.name === 'auto_detect');
17001716
if (widget) widget.value = props.autoDetect;
17011717
app.graph.setDirtyCanvas(true);
1718+
} else if (toggleName === 'calcInfoToggle' && props.selectedCategory) {
1719+
props.showCalcInfo = !props.showCalcInfo;
1720+
app.graph.setDirtyCanvas(true);
17021721
}
17031722
}
17041723

js/utils/ResolutionMasterConfig.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ export const tooltips = {
4141
// Preset controls
4242
categoryDropdown: "Select preset category (Standard, SDXL, Flux, HiDream Dev, Qwen-Image, etc.)",
4343
presetDropdown: "Choose specific preset from selected category",
44-
customCalcCheckbox: "Automatically apply model-specific optimizations for the new detected image resolution (read orange information below)",
45-
autoCalcBtn: "Apply model-specific optimizations for current resolution (read orange information below)",
44+
customCalcCheckbox: "Automatically apply model-specific optimizations for the new detected image resolution",
45+
autoCalcBtn: "Apply model-specific optimizations for current resolution",
46+
calcInfoToggle: "Show or hide information about the selected Calc mode",
4647
compactToggleBtn: "Hide/show all extra control sections below the 2D canvas",
4748
compactHelpBtn: "Open Resolution Master help and project link",
4849

0 commit comments

Comments
 (0)