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,
cmpsList: cmpsList,
cmpDefs: cmpDefs,
fnArgs: fnArgs
fnArgs: fnArgs,
maxWidth: "100%",
maxHeight: "100%",
});
document.body.innerHTML = ""; // clear children

View File

@ -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 = <SVGGElement>svg.child(host, "g");
host.appendChild(a.el);

View File

@ -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());