layout update

This commit is contained in:
Marvin Sanchez 2016-08-23 16:13:08 +08:00
parent c2b62d6ecc
commit 24d6cf97a8
4 changed files with 38 additions and 6 deletions

View File

@ -89,6 +89,13 @@ class Layout {
void _position(Node n) { void _position(Node n) {
boolean centeredVertically = false;
if (n.parent != null) {
if (n.parent.parent == null)
centeredVertically = true;
}
Style style = n.style; Style style = n.style;
Rect exT = style.calculateTextExtents(n.text, style.textSize); Rect exT = style.calculateTextExtents(n.text, style.textSize);
Rect exS = style.calculateTextExtents(" ", style.textSize); Rect exS = style.calculateTextExtents(" ", style.textSize);
@ -123,6 +130,10 @@ class Layout {
_position(nc); _position(nc);
} }
if (centeredVertically && ! n.childrenDirection.equals("down") && children.size() > 1) {
n.layout.y = n.layout.y + (n.layout.bounds.height / 2);
}
} }
void _calculatePorts(Node n) { void _calculatePorts(Node n) {
@ -222,7 +233,7 @@ class Layout {
_reset(n); _reset(n);
_calculateSize(n); _calculateSize(n);
int d = _getDepth(); int d = 1; // _getDepth();
for (int i=0; i<d; i++) { for (int i=0; i<d; i++) {
_calculateBounds(n); _calculateBounds(n);
_position(n); _position(n);

View File

@ -66,4 +66,10 @@ class Rect {
width = 0; width = 0;
height = 0; height = 0;
} }
boolean pointInRect(int px, int py) {
if (px < x || px > x + width || py < y || py > y +height)
return false;
return true;
}
} }

View File

@ -97,10 +97,17 @@ class Renderer {
float tx = (eh.height / 2) + (r.width / 2) - (ew.width / 2); float tx = (eh.height / 2) + (r.width / 2) - (ew.width / 2);
float ty = (eh.height / 1.6) + (r.height / 2) - (ew.height / 2); float ty = (eh.height / 1.6) + (r.height / 2) - (ew.height / 2);
if (previewOnly) {
int border = 8;
g.fill(style.textColor);
g.noStroke();
g.rect(r.x + (border*2), r.y + (border*2), r.width - (border*4), r.height - (border*4));
} else {
g.textFont(gs.font, style.textSize); g.textFont(gs.font, style.textSize);
g.textAlign(style.textAlign); g.textAlign(style.textAlign);
g.fill(style.textColor); g.fill(style.textColor);
g.text(n.text, r.x + tx, r.y + ty); g.text(n.text, r.x + tx, r.y + ty);
}
for (Object c : n.children) { for (Object c : n.children) {
Node nc = (Node)c; Node nc = (Node)c;

View File

@ -1,4 +1,6 @@
String project = "civpro"; String project = "crim2b";
boolean previewOnly = false;
Node root; Node root;
@ -23,6 +25,9 @@ void doRedraw() {
void settings() void settings()
{ {
if (previewOnly) {
scale = 0.25;
}
size((int)(1280*windowScale), (int)(720*windowScale)); size((int)(1280*windowScale), (int)(720*windowScale));
} }
@ -117,8 +122,11 @@ void keyReleased() {
{ {
if (key == 'i') { if (key == 'i') {
boolean tmp = previewOnly;
previewOnly = false;
println("saving image"); println("saving image");
globalRenderer.saveImage(root, fileScale); globalRenderer.saveImage(root, fileScale);
previewOnly = tmp;
} }
} }