-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex1.scd
121 lines (106 loc) · 2.98 KB
/
ex1.scd
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
/*
Layout Management in SuperCollider
* GridLayout - A layout that organizes views in a grid
* StackLayout - A layout that stacks views on top of each other
* HLayout - A layout that distributes views in a horizontal line
* VLayout - A layout that distributes views in a vertical line
Layouts are installed on a View and will distribute the space of that
View for the the items in the Layout. A basic unit on which a layout
operates is therefore abstractly called an item and can be a view or
another layout.
*/
// HLayout basic usage
w = Window();
w.layout_(HLayout(Slider(), TextView(), Slider()));
w.front;
// HLayout using a stretch factor
(
w = Window().layout_(
HLayout(
[ Slider(), stretch:1 ],
[ TextView() ],
[ Slider(), stretch:1 ],
)
).front;
)
// HLayout with a nested VLayout
(
w = Window().layout_(
HLayout(
TextView(),
VLayout(
Button().states_([[ 1 ]]),
Button().states_([[ 2 ]]),
Button().states_([[ 3 ]]),
Button().states_([[ 4 ]]),
),
)
).front;
)
// HLayout with a nested VLayout using alignment
// (see the bottom of this file for possible alignments)
(
w = Window().layout_(
HLayout(
VLayout(
[ Button(), align:\top ],
[ Button(), align:\bottom ],
),
Slider2D(),
VLayout(
[ Button(), align:\top ],
[ Button() ],
[ Button() ],
[ Button(), align:\bottom ],
)
)
// using a size constraint on the top view
).view.fixedSize_(Size(500,300)).front;
)
// GridLayout
(
var grid = GridLayout(),
w = Window().layout_(grid),
view = View().background_(Color.rand),
num = 6;
// add buttons to the GridLayout
// args: item, row, column, align
num.do{|i| grid.add(Button().states_([[ i ]]), 0, i) };
// add a View which vertically span all buttons
// args: item, row, column, rowSpan: 1, columnSpan: 1, align
grid.addSpanning(view, 1, 0, 1, num);
w.front;
)
// GridLayout can be used for finer tuning
(
var grid = GridLayout(),
w = Window().layout_(grid),
num = 30,
spacing = 1,
rowBreak = 10;
// add a custom spacing
grid.hSpacing_(spacing);
grid.vSpacing_(spacing);
num.do{|i|
grid.add(
View().background_(Color.rand(0.3,0.6)).layout_(HLayout(Knob())),
i div: rowBreak,
i % rowBreak
)
};
// using minSizeHint to resize the window to fit the items of the view
w.view.resizeTo(w.view.minSizeHint.width, w.view.minSizeHint.height);
w.front;
)
/*
Possible alignments for layouts
\left
\center
\right
\topLeft
\top
\topRight
\bottomLeft
\bottom
\bottomRight
*/