Skip to content

Commit c9ed2d9

Browse files
committed
Refactor editable value background rendering
1 parent 12b65b2 commit c9ed2d9

2 files changed

Lines changed: 70 additions & 15 deletions

File tree

js/drawing/resolution_master_draw_methods.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export const drawingMethods = {
263263
h: latAreaHeight
264264
};
265265

266-
this.drawEditableOutputBackground(ctx, 'latValueArea', latAreaX, y_offset_5 - 10, latAreaWidth, latAreaHeight, [248, 136, 187]);
266+
this.drawEditableValueBackground(ctx, 'latValueArea', latAreaX, y_offset_5 - 10, latAreaWidth, latAreaHeight, [248, 136, 187]);
267267

268268
ctx.fillStyle = this.hoverElement === 'latValueArea' ? "#FAB" : "#F8B";
269269
ctx.font = "bold 12px Arial";
@@ -289,7 +289,7 @@ export const drawingMethods = {
289289
w: w - (OUTPUT_VALUE_HIT_RIGHT_INSET - OUTPUT_VALUE_VISUAL_RIGHT_INSET),
290290
h
291291
};
292-
this.drawEditableOutputBackground(ctx, controlName, x, y, w, h, hoverColor);
292+
this.drawEditableValueBackground(ctx, controlName, x, y, w, h, hoverColor);
293293
ctx.fillStyle = this.hoverElement === controlName ? activeTextColor : textColor;
294294
ctx.textAlign = "center";
295295
this.drawVerticallyCenteredText(ctx, text, x + w / 2, textY);
@@ -311,15 +311,13 @@ export const drawingMethods = {
311311
ctx.restore();
312312
},
313313

314-
drawEditableOutputBackground(ctx, controlName, x, y, w, h, color, borderRadius = 5) {
314+
drawEditableValueBackground(ctx, controlName, x, y, w, h, color, borderRadius = 5) {
315315
const isHovered = this.hoverElement === controlName;
316316
ctx.save();
317-
ctx.fillStyle = isHovered
318-
? `rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.12)`
319-
: SECTION_BACKGROUND_COLOR;
317+
ctx.fillStyle = "rgba(0,0,0,0)";
320318
ctx.strokeStyle = isHovered
321319
? `rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.9)`
322-
: "rgba(205, 210, 220, 0.28)";
320+
: "rgba(205, 210, 220, 0.18)";
323321
ctx.lineWidth = isHovered ? 1.4 : 1;
324322
ctx.beginPath();
325323
ctx.roundRect(x, y, w, h, borderRadius);
@@ -354,13 +352,13 @@ export const drawingMethods = {
354352
const snapValueX = sliderX + sliderWidth + gap;
355353
this.controls.snapValueArea = { x: snapValueX, y, w: valueWidth, h: 28 };
356354

357-
this.drawValueAreaHoverBackground(ctx, 'snapValueArea', snapValueX, y, valueWidth, 28, [100, 150, 255]);
355+
this.drawEditableValueBackground(ctx, 'snapValueArea', snapValueX, y, valueWidth, 28, [100, 150, 255]);
358356

359357
ctx.fillStyle = this.hoverElement === 'snapValueArea' ? "#5af" : "#ccc";
360358
ctx.font = "12px Arial";
361-
ctx.textAlign = "left";
359+
ctx.textAlign = "center";
362360
ctx.textBaseline = "middle";
363-
ctx.fillText(props.snapValue.toString(), snapValueX + 10, y + 14);
361+
this.drawVerticallyCenteredText(ctx, props.snapValue.toString(), snapValueX + valueWidth / 2, y + 14);
364362
},
365363

366364
draw2DCanvas(ctx, x, y, w, h, padding = 20) {
@@ -1181,12 +1179,12 @@ export const drawingMethods = {
11811179
const valueAreaControl = config.buttonControl.replace('Btn', 'ValueArea');
11821180
this.controls[valueAreaControl] = { x: currentX, y, w: layout.valueWidth, h: 28 };
11831181

1184-
this.drawValueAreaHoverBackground(ctx, valueAreaControl, currentX, y, layout.valueWidth, 28, [100, 150, 255]);
1182+
this.drawEditableValueBackground(ctx, valueAreaControl, currentX, y, layout.valueWidth, 28, [100, 150, 255]);
11851183
this.setCanvasTextStyle(ctx, {
11861184
fillStyle: this.hoverElement === valueAreaControl ? "#5af" : "#ccc",
11871185
textAlign: "center"
11881186
});
1189-
ctx.fillText(config.displayValue, currentX + layout.valueWidth / 2, y + 14);
1187+
this.drawVerticallyCenteredText(ctx, config.displayValue, currentX + layout.valueWidth / 2, y + 14);
11901188
currentX += layout.valueWidth + layout.gap;
11911189
if (this.validateWidgets() && config.previewDimensions) {
11921190
const newW = Math.round(Number(config.previewDimensions.width) || 0);

tests/js/output_value_drawing.test.mjs

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ test("editable outputs have persistent pills while rescale factor remains plain
9292
controller.drawOutputValues(ctx);
9393

9494
assert.equal(ctx.rectangles.length, 4);
95-
assert.ok(ctx.rectangles.every(rect => rect.fillStyle === "rgba(0,0,0,0.2)"));
96-
assert.ok(ctx.rectangles.every(rect => rect.strokeStyle === "rgba(205, 210, 220, 0.28)"));
95+
assert.ok(ctx.rectangles.every(rect => rect.fillStyle === "rgba(0,0,0,0)"));
96+
assert.ok(ctx.rectangles.every(rect => rect.strokeStyle === "rgba(205, 210, 220, 0.18)"));
9797
assert.deepEqual(Object.keys(controller.controls), [
9898
"widthValueArea",
9999
"heightValueArea",
@@ -134,7 +134,7 @@ test("hover strengthens the editable output pill", () => {
134134
const ctx = createCanvasContext();
135135
controller.drawOutputValues(ctx);
136136

137-
assert.equal(ctx.rectangles[0].fillStyle, "rgba(136, 153, 255, 0.12)");
137+
assert.equal(ctx.rectangles[0].fillStyle, "rgba(0,0,0,0)");
138138
assert.equal(ctx.rectangles[0].strokeStyle, "rgba(136, 153, 255, 0.9)");
139139
assert.equal(ctx.rectangles[0].lineWidth, 1.4);
140140
} finally {
@@ -163,3 +163,60 @@ test("Nodes 2.0 output pills follow the measured DOM slot centers", () => {
163163
globalThis.LiteGraph = originalLiteGraph;
164164
}
165165
});
166+
167+
test("custom snap step uses the persistent editable value background", () => {
168+
const controller = createController();
169+
controller.node.properties = {
170+
snapValue: 176,
171+
action_slider_snap_min: 1,
172+
action_slider_snap_max: 256,
173+
action_slider_snap_step: 1
174+
};
175+
controller.node.size = [330, 400];
176+
controller.icons = { swap: {}, snap: {} };
177+
controller.drawButton = () => {};
178+
controller.drawSlider = () => {};
179+
const ctx = createCanvasContext();
180+
181+
controller.drawPrimaryControls(ctx, 0);
182+
183+
assert.equal(ctx.rectangles.length, 1);
184+
assert.equal(ctx.rectangles[0].fillStyle, "rgba(0,0,0,0)");
185+
assert.equal(ctx.rectangles[0].strokeStyle, "rgba(205, 210, 220, 0.18)");
186+
assert.equal(ctx.text.find(entry => entry.value === "176")?.x, 297.5);
187+
});
188+
189+
test("scaling numeric values use the persistent editable value background", () => {
190+
const controller = createController();
191+
controller.node.properties = { upscaleValue: 1.25, rescaleMode: "manual" };
192+
controller.getScalingRowLayout = () => ({
193+
btnWidth: 70,
194+
sliderWidth: 90,
195+
dropdownWidth: 90,
196+
valueWidth: 45,
197+
previewWidth: 0,
198+
radioWidth: 18,
199+
gap: 5
200+
});
201+
controller.drawButton = () => {};
202+
controller.drawSlider = () => {};
203+
controller.drawRadioButton = () => {};
204+
controller.validateWidgets = () => false;
205+
const ctx = createCanvasContext();
206+
207+
controller.drawScalingRowBase(ctx, 10, 20, {
208+
buttonControl: "scaleBtn",
209+
mainControl: "scaleSlider",
210+
controlType: "slider",
211+
valueProperty: "upscaleValue",
212+
min: 0.1,
213+
max: 4,
214+
step: 0.05,
215+
displayValue: "1.25",
216+
rescaleMode: "manual"
217+
});
218+
219+
assert.equal(controller.controls.scaleValueArea.w, 45);
220+
assert.equal(ctx.rectangles[0].fillStyle, "rgba(0,0,0,0)");
221+
assert.equal(ctx.rectangles[0].strokeStyle, "rgba(205, 210, 220, 0.18)");
222+
});

0 commit comments

Comments
 (0)