Skip to content

Commit a825d51

Browse files
committed
Some tweaks to pieces area return values for freespace-style renderers
1 parent 376c6dc commit a825d51

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/renderers/_base.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9004,7 +9004,7 @@ export abstract class RendererBase {
90049004
*
90059005
* @param gridPoints -
90069006
*/
9007-
protected piecesArea(box: SVGBox, opts?: {padding?: number, canvas?: Svg}): number|undefined {
9007+
protected piecesArea(box: SVGBox, opts?: {padding?: number, canvas?: Svg}): {newY: number|undefined; width: number|undefined} {
90089008
if (this.rootSvg === undefined) {
90099009
throw new Error("Can't place a `pieces` area until the root SVG is initialized!");
90109010
}
@@ -9013,6 +9013,7 @@ export abstract class RendererBase {
90139013
padding = opts.padding;
90149014
}
90159015
let placeY: number|undefined;
9016+
let finalWidth: number|undefined;
90169017
if ( (this.json !== undefined) && (this.json.areas !== undefined) && (Array.isArray(this.json.areas)) && (this.json.areas.length > 0) ) {
90179018
const areas = this.json.areas.filter((x) => x.type === "pieces") as AreaPieces[];
90189019
const boardBottom = box.y2; // + this.cellsize;
@@ -9050,6 +9051,12 @@ export abstract class RendererBase {
90509051
root = opts.canvas;
90519052
}
90529053
const nested = root.nested().id(`_pieces${iArea}`).size(areaWidth+2, areaHeight+2).viewbox(-1 - markWidth - 5, -1, areaWidth+2+markWidth+10, areaHeight+2);
9054+
const fullWidth = areaWidth + 2 + markWidth + 10;
9055+
if (finalWidth === undefined) {
9056+
finalWidth = fullWidth;
9057+
} else {
9058+
finalWidth = Math.max(finalWidth, fullWidth);
9059+
}
90539060
if ("background" in area) {
90549061
nested.rect(areaWidth,areaHeight).fill(area.background as string);
90559062
}
@@ -9100,7 +9107,7 @@ export abstract class RendererBase {
91009107
placeY += nested.bbox().height + (this.cellsize * 0.5);
91019108
}
91029109
}
9103-
return placeY;
9110+
return {newY: placeY, width: finalWidth};
91049111
}
91059112

91069113
/**

src/renderers/freespace.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class FreespaceRenderer extends RendererBase {
109109
const box = field.viewbox();
110110

111111
// `pieces` area, if present
112-
const newY = this.piecesArea(box, {canvas: field})!;
112+
const {newY, width: areaWidth} = this.piecesArea(box, {canvas: field})!;
113113

114114
// // button bar
115115
// this.placeButtonBar(gridPoints);
@@ -137,6 +137,11 @@ export class FreespaceRenderer extends RendererBase {
137137
h += dy;
138138
// field.viewbox(x, y, w, h);
139139
}
140+
if (areaWidth !== undefined) {
141+
if (w < areaWidth) {
142+
w = areaWidth;
143+
}
144+
}
140145
field.viewbox(x, y, w, h);
141146
draw.viewbox(x, y, w, h);
142147
}

src/renderers/polyomino.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class PolyominoRenderer extends RendererBase {
129129
}
130130
}
131131

132-
protected piecesArea(box: SVGBox): number|undefined {
132+
protected piecesArea(box: SVGBox): {newY: number|undefined; width: number|undefined} {
133133
if (this.rootSvg === undefined) {
134134
throw new Error("Can't place a `pieces` area until the root SVG is initialized!");
135135
}
@@ -269,7 +269,7 @@ export class PolyominoRenderer extends RendererBase {
269269
}
270270
}
271271
}
272-
return undefined;
272+
return {newY: undefined, width: undefined};
273273
}
274274

275275
/**

src/renderers/treePyramid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class TreePyramidRenderer extends RendererBase {
156156
const box = field.viewbox();
157157

158158
// `pieces` area, if present
159-
const newY = this.piecesArea(box, {canvas: field})!;
159+
const {newY} = this.piecesArea(box, {canvas: field})!;
160160

161161
// // button bar
162162
// this.placeButtonBar(box);

0 commit comments

Comments
 (0)