This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUILayouts.pde
121 lines (101 loc) · 3.32 KB
/
SUILayouts.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class GridLayout extends Layout {
private int rows = 1;
private int columns = 1;
GridLayout(int rows, int columns) {
super();
this.rows = rows;
this.columns = columns;
}
public void setRows(int rows){
this.rows = rows;
rebuild();
}
public void setColumns(int columns){
this.columns = columns;
rebuild();
}
public int getRows() {return rows;}
public int getColumns() {return columns;}
public void rebuild() {
if (getParentWidget() == null) return;
// define the minimum width
int minW = 0;
int minH = 0;
int w = getParentWidget().getW() / columns;
int h = getParentWidget().getH() / rows;
int n = getParentWidget().getChildren().size();
for (int i=0; i < n; i++) {
int x = i % columns;
int y = (i-x)/columns;
Widget child = getParentWidget().getChildren().get(i);
child.setX(x*w);
child.setY(y*h);
child.resize(w,h);
}
}
}
public final class SplitLayout extends Layout {
SplitLayout() {
super();
}
public void rebuild() {
if (getParentWidget() == null) return;
SplitWidget parentWidget = (SplitWidget) getParentWidget();
int n = parentWidget.getChildren().size();
if(n >= 1){
Widget child = parentWidget.getChildren().get(0);
if(parentWidget.getAxis() == parentWidget.HORIZONTAL){
child.setX(0);
child.setY(0);
child.resize(parentWidget.getW(), (int) (parentWidget.getH()*parentWidget.getOffset())-parentWidget.getSliderWidth()/2);
}else{
child.setY(0);
child.setX(0);
child.resize((int)(parentWidget.getW()*parentWidget.getOffset())-parentWidget.getSliderWidth()/2, parentWidget.getH());
}
}
if(n == 2){
Widget child = parentWidget.getChildren().get(1);
if(parentWidget.getAxis() == parentWidget.HORIZONTAL){
child.setX(0);
child.setY((int) (parentWidget.getH()*parentWidget.getOffset())+parentWidget.getSliderWidth()/2);
child.resize(parentWidget.getW(), (int)(parentWidget.getH()*(1-parentWidget.getOffset()))-parentWidget.getSliderWidth()/2);
} else {
child.setY(0);
child.setX((int) (parentWidget.getW()*parentWidget.getOffset())+parentWidget.getSliderWidth()/2);
child.resize((int)(parentWidget.getW()*(1-parentWidget.getOffset()))-parentWidget.getSliderWidth()/2, parentWidget.getH());
}
}
}
}
class StackLayout extends Layout{
public static final int VERTICAL = 0;
public static final int HORIZONTAL = 1;
private int axis = HORIZONTAL;
private boolean expend = true;
StackLayout(int axis, boolean expend) {
super();
this.axis = axis;
this.expend = expend;
}
public void setExpend(boolean v){expend = v;}
public void rebuild() {
if (getParentWidget() == null) return;
int dist = 0;
for (Widget w : getParentWidget().getChildren()) {
w.calculateMinimumSize();
if(!expend) w.resize(w.getMinW(), w.getMinH());
if(axis == HORIZONTAL){
if(expend)
w.resize(w.getMinW(), max(getParentWidget().getH(), w.getMinH()));
w.setX(dist);
dist += w.getW();
} else {
if(expend)
w.resize(max(getParentWidget().getW(), w.getMinH()), w.getMinH());
w.setY(dist);
dist += w.getH();
}
}
}
}