fixes microbit board height issue

This commit is contained in:
darzu 2016-08-31 11:34:49 -07:00
parent c2e37a2c6e
commit 626055d3eb
3 changed files with 16 additions and 13 deletions

View File

@ -86,7 +86,9 @@ namespace pxsim {
boardDef: boardDef, boardDef: boardDef,
cmpsList: cmpsList, cmpsList: cmpsList,
cmpDefs: cmpDefs, cmpDefs: cmpDefs,
fnArgs: fnArgs fnArgs: fnArgs,
maxWidth: "100%",
maxHeight: "100%",
}); });
document.body.innerHTML = ""; // clear children document.body.innerHTML = ""; // clear children

View File

@ -84,7 +84,12 @@ namespace pxsim.visuals {
let [a, b] = [opts.el1, opts.el2]; let [a, b] = [opts.el1, opts.el2];
U.assert(a.x == 0 && a.y == 0 && b.x == 0 && b.y == 0, "el1 and el2 x,y offsets not supported"); U.assert(a.x == 0 && a.y == 0 && b.x == 0 && b.y == 0, "el1 and el2 x,y offsets not supported");
let setXY = (e: SVGSVGElement, x: number, y: number) => svg.hydrate(e, {x: x, y: y}); let setXY = (e: SVGSVGElement, x: number, y: number) => svg.hydrate(e, {x: x, y: y});
let setWH = (e: SVGSVGElement, w: string, h: string) => svg.hydrate(e, {width: w, height: h}); let setWH = (e: SVGSVGElement, w: string, h: string) => {
if (w)
svg.hydrate(e, {width: w});
if (h)
svg.hydrate(e, {height: h});
}
let setWHpx = (e: SVGSVGElement, w: number, h: number) => svg.hydrate(e, {width: `${w}px`, height: `${h}px`}); let setWHpx = (e: SVGSVGElement, w: number, h: number) => svg.hydrate(e, {width: `${w}px`, height: `${h}px`});
let scaleUnit = opts.scaleUnit2; let scaleUnit = opts.scaleUnit2;
let aScalar = opts.scaleUnit2 / opts.scaleUnit1; let aScalar = opts.scaleUnit2 / opts.scaleUnit1;
@ -112,8 +117,7 @@ namespace pxsim.visuals {
"viewBox": `0 0 ${w} ${h}`, "viewBox": `0 0 ${w} ${h}`,
"class": `sim-bb`, "class": `sim-bb`,
}); });
if (opts.maxWidth && opts.maxHeight) setWH(host, opts.maxWidth, opts.maxHeight);
setWH(host, opts.maxWidth, opts.maxHeight);
setXY(host, 0, 0); setXY(host, 0, 0);
let under = <SVGGElement>svg.child(host, "g"); let under = <SVGGElement>svg.child(host, "g");
host.appendChild(a.el); host.appendChild(a.el);

View File

@ -35,9 +35,6 @@ namespace pxsim.visuals {
wireframe: opts.wireframe, wireframe: opts.wireframe,
}); });
let maxWidth = opts.maxWidth || "100%";
let maxHeight = opts.maxHeight || "100%";
let useBreadboard = 0 < activeComponents.length || opts.forceBreadboard; let useBreadboard = 0 < activeComponents.length || opts.forceBreadboard;
if (useBreadboard) { if (useBreadboard) {
this.breadboard = new Breadboard({ this.breadboard = new Breadboard({
@ -50,8 +47,8 @@ namespace pxsim.visuals {
scaleUnit2: this.breadboard.getPinDist(), scaleUnit2: this.breadboard.getPinDist(),
margin: [0, 0, 10, 0], margin: [0, 0, 10, 0],
middleMargin: 80, middleMargin: 80,
maxWidth: maxWidth, maxWidth: opts.maxWidth,
maxHeight: maxHeight, maxHeight: opts.maxHeight,
}); });
let under = composition.under; let under = composition.under;
let over = composition.over; let over = composition.over;
@ -78,10 +75,10 @@ namespace pxsim.visuals {
} else { } else {
let el = this.boardView.getView().el; let el = this.boardView.getView().el;
this.view = el; this.view = el;
svg.hydrate(this.view, { if (opts.maxWidth)
width: maxWidth, svg.hydrate(this.view, { width: opts.maxWidth });
height: maxHeight, if (opts.maxHeight)
}); svg.hydrate(this.view, { height: opts.maxHeight });
} }
this.state.updateSubscribers.push(() => this.updateState()); this.state.updateSubscribers.push(() => this.updateState());