gravity/toolbar.js

41 lines
795 B
JavaScript

import {
TOOLBAR_CLASSNAME,
} from './config.js';
import {Header} from './tool/header.js';
export class Toolbar {
sim = undefined;
tools = [];
constructor(sim, title, group) {
this.sim = sim;
// Create ourselves a div, as child of sim's div
const div = document.createElement('div');
this.div = div;
if (group) {
group.addToolbar(this);
} else {
this.sim.div.appendChild(div);
}
div.classList.add(TOOLBAR_CLASSNAME);
// Create a collapse/expand tool
const header = new Header(this, title);
this.addTool(header);
}
// tool: instance of Tool
addTool(tool) {
this.div.appendChild(tool.div);
this.tools.push(tool);
return this;
}
frame() {
for (let tool of this.tools) {
tool.frame();
}
}
}