Draw boxes, set font size

This commit is contained in:
Ian Gulliver
2019-07-01 20:53:20 +00:00
parent ae771b554b
commit 207a9f7f8f
2 changed files with 33 additions and 5 deletions

View File

@@ -18,6 +18,7 @@ class Architype {
this.container_.classList.add('dark');
this.container_.addEventListener('keydown', (e) => { this.onKeyDown(e); });
this.container_.addEventListener('resize', (e) => { this.onResize(e); });
let editorElem = document.createElement('ul');
this.container_.appendChild(editorElem);
@@ -71,6 +72,7 @@ class Architype {
this.graph_ = this.buildGraph();
this.buildGrid(this.graph_);
this.updateTargets(this.graph_);
this.fixSizes(this.graph_.nodes);
}
onKeyDown(e) {
@@ -81,6 +83,10 @@ class Architype {
}
}
onResize(e) {
this.fixSizes(this.graph_.nodes);
}
exportGraphviz() {
let lines = [
'digraph G {',
@@ -513,6 +519,19 @@ class Architype {
node.gridElem.style.gridRow = node.pos[1] + 1;
}
}
fixSizes(nodes) {
for (let node of nodes) {
let elem = node.gridElem;
let size = 16;
for (let size = 16;
size && (elem.scrollWidth > elem.clientWidth ||
elem.scrollHeight > elem.clientHeight);
--size) {
elem.style.fontSize = size + 'px';
}
}
}
}
class ListenUtils {