From 626055d3eb4e32cc9e0ad5bd372628fa294058a2 Mon Sep 17 00:00:00 2001 From: darzu Date: Wed, 31 Aug 2016 11:34:49 -0700 Subject: [PATCH] fixes microbit board height issue --- sim/dalboard.ts | 4 +++- sim/simlib.ts | 10 +++++++--- sim/visuals/boardhost.ts | 15 ++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/sim/dalboard.ts b/sim/dalboard.ts index b8a46882..8baae2eb 100644 --- a/sim/dalboard.ts +++ b/sim/dalboard.ts @@ -86,7 +86,9 @@ namespace pxsim { boardDef: boardDef, cmpsList: cmpsList, cmpDefs: cmpDefs, - fnArgs: fnArgs + fnArgs: fnArgs, + maxWidth: "100%", + maxHeight: "100%", }); document.body.innerHTML = ""; // clear children diff --git a/sim/simlib.ts b/sim/simlib.ts index b7b40a46..334cc44f 100644 --- a/sim/simlib.ts +++ b/sim/simlib.ts @@ -84,7 +84,12 @@ namespace pxsim.visuals { 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"); 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 scaleUnit = opts.scaleUnit2; let aScalar = opts.scaleUnit2 / opts.scaleUnit1; @@ -112,8 +117,7 @@ namespace pxsim.visuals { "viewBox": `0 0 ${w} ${h}`, "class": `sim-bb`, }); - if (opts.maxWidth && opts.maxHeight) - setWH(host, opts.maxWidth, opts.maxHeight); + setWH(host, opts.maxWidth, opts.maxHeight); setXY(host, 0, 0); let under = svg.child(host, "g"); host.appendChild(a.el); diff --git a/sim/visuals/boardhost.ts b/sim/visuals/boardhost.ts index 9ce15be8..e509bbae 100644 --- a/sim/visuals/boardhost.ts +++ b/sim/visuals/boardhost.ts @@ -35,9 +35,6 @@ namespace pxsim.visuals { wireframe: opts.wireframe, }); - let maxWidth = opts.maxWidth || "100%"; - let maxHeight = opts.maxHeight || "100%"; - let useBreadboard = 0 < activeComponents.length || opts.forceBreadboard; if (useBreadboard) { this.breadboard = new Breadboard({ @@ -50,8 +47,8 @@ namespace pxsim.visuals { scaleUnit2: this.breadboard.getPinDist(), margin: [0, 0, 10, 0], middleMargin: 80, - maxWidth: maxWidth, - maxHeight: maxHeight, + maxWidth: opts.maxWidth, + maxHeight: opts.maxHeight, }); let under = composition.under; let over = composition.over; @@ -78,10 +75,10 @@ namespace pxsim.visuals { } else { let el = this.boardView.getView().el; this.view = el; - svg.hydrate(this.view, { - width: maxWidth, - height: maxHeight, - }); + if (opts.maxWidth) + svg.hydrate(this.view, { width: opts.maxWidth }); + if (opts.maxHeight) + svg.hydrate(this.view, { height: opts.maxHeight }); } this.state.updateSubscribers.push(() => this.updateState());