Skip to content

Commit

Permalink
Compute group height assuming group width is 2 (Strilanc#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc authored Sep 14, 2020
1 parent d995a7a commit 2043fa7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/ui/DisplayedInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ class DisplayedInspector {
* @returns {!DisplayedInspector}
*/
static empty(drawArea) {
let topToolbox = new DisplayedToolbox('Toolbox', 0, Gates.TopToolboxGroups, true, 3);
let topToolbox = new DisplayedToolbox('Toolbox', 0, Gates.TopToolboxGroups, true);
let displayedCircuit = DisplayedCircuit.empty(topToolbox.desiredHeight());
let bottomToolbox = new DisplayedToolbox(
'Toolbox₂',
displayedCircuit.top + displayedCircuit.desiredHeight(),
Gates.BottomToolboxGroups,
false,
4);
false);
return new DisplayedInspector(
drawArea,
displayedCircuit,
Expand Down
13 changes: 7 additions & 6 deletions src/ui/DisplayedToolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class DisplayedToolbox {
* @param {!number} top
* @param {!Array<!{hint: !string, gates: !Array<undefined|!Gate>}>} toolboxGroups
* @param {!boolean} labelsOnTop
* @param {!int} groupHeight
* @param {undefined|!Array<!{hint: !string, gates: !Array<undefined|!Gate>}>=} originalGroups
* @param {undefined|!CachablePainting=undefined} standardAppearance
*/
Expand All @@ -41,7 +40,6 @@ class DisplayedToolbox {
top,
toolboxGroups,
labelsOnTop,
groupHeight,
originalGroups=undefined,
standardAppearance=undefined) {
/** @type {!String} */
Expand All @@ -52,8 +50,6 @@ class DisplayedToolbox {
this.toolboxGroups = toolboxGroups;
/** @type {!boolean} */
this.labelsOnTop = labelsOnTop;
/** @type {!int} */
this.groupHeight = groupHeight;
/** @type {!Array<!{hint: !string, gates: !Array<undefined|!Gate>}>} */
this._originalGroups = originalGroups || this.toolboxGroups;
/**
Expand All @@ -68,6 +64,13 @@ class DisplayedToolbox {
this._paintStandardContents(painter);
painter.ctx.restore();
});

/** @type {!int} */
this.groupHeight = 1;
for (let group of toolboxGroups) {
let h = Math.ceil(group.gates.length / 2);
this.groupHeight = Math.max(this.groupHeight, h);
}
}

/**
Expand All @@ -90,7 +93,6 @@ class DisplayedToolbox {
this.top,
groups,
this.labelsOnTop,
this.groupHeight,
this._originalGroups,
this._standardApperance);
}
Expand Down Expand Up @@ -181,7 +183,6 @@ class DisplayedToolbox {
newTop,
this.toolboxGroups,
this.labelsOnTop,
this.groupHeight,
this._originalGroups,
this._standardApperance);
}
Expand Down

0 comments on commit 2043fa7

Please sign in to comment.