Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion js/__tests__/blockfactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,22 @@ describe("SVG Class", () => {
});

it("should set stroke width", () => {
svg.setstrokeWidth(2);
svg.setStrokeWidth(2);
expect(svg._strokeWidth).toBe(2);
});

it("should compute slot size dynamically", () => {
// With defaults: radius=8, innieY2=4, strokeWidth=1
// Expected: 2 * 8 + 4 + 1 = 21
expect(svg._slotSize).toBe(21);

// When strokeWidth changes, slotSize should update
svg.setStrokeWidth(2);
// New innieY2 = (9 - 2) / 2 = 3.5
// Expected: 2 * 8 + 3.5 + 2 = 21.5
expect(svg._slotSize).toBe(21.5);
});

it("should set colors", () => {
svg.setColors(["red", "blue"]);
expect(svg._fill).toBe("red");
Expand Down
14 changes: 10 additions & 4 deletions js/blockfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ class SVG {
this._expandY2 = 0;
this._clampCount = 1;
this._clampSlots = [1];
this._slotSize = 21; // TODO: Compute this.
// Slot size represents the standard height of a basic block.
// Derived from: 2 * radius + innieY2 + strokeWidth
// This ensures clamp block jaws scale properly with theme changes.
this._slotSize = 2 * this._radius + this._innieY2 + this._strokeWidth;
this._arm = true;
this._else = false;
this._draw_inniess = true;
Expand Down Expand Up @@ -202,11 +205,14 @@ class SVG {

/**
* @public
* @param {number} stroke_width
* @param {number} strokeWidth
* @returns {void}
*/
setstrokeWidth(stroke_width) {
this._strokeWidth = stroke_width;
setStrokeWidth(strokeWidth) {
this._strokeWidth = strokeWidth;
// Recalculate dependent values that use strokeWidth
this._innieY2 = (9 - this._strokeWidth) / 2;
this._slotSize = 2 * this._radius + this._innieY2 + this._strokeWidth;
this._calc_porch_params();
}

Expand Down