-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlayout_flexgrid.py
144 lines (100 loc) · 4.44 KB
/
layout_flexgrid.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from juce_init import START_JUCE_COMPONENT
import popsicle as juce
class RightSidePanel(juce.Component):
backgroundColour = juce.Colours.lightblue
buttons = []
def __init__(self, colour=None):
super().__init__()
if colour:
self.backgroundColour = colour
for i in range(10):
button = juce.TextButton(str(i))
self.buttons.append(button)
self.addAndMakeVisible(button)
def paint(self, g):
g.fillAll(self.backgroundColour)
def resized(self):
fb = juce.FlexBox()
fb.flexWrap = juce.FlexBox.Wrap.wrap
fb.justifyContent = juce.FlexBox.JustifyContent.center
fb.alignContent = juce.FlexBox.AlignContent.center
for b in self.buttons:
fb.items.add(juce.FlexItem(b).withMinWidth(50.0).withMinHeight(50.0))
fb.performLayout(self.getLocalBounds().toFloat())
class LeftSidePanel(juce.Component):
backgroundColour = juce.Colours.lightgrey
knobs = []
def __init__(self, colour=None):
super().__init__()
if colour:
self.backgroundColour = colour
for _ in range(10):
slider = juce.Slider()
slider.setSliderStyle(juce.Slider.SliderStyle.Rotary)
slider.setTextBoxStyle(juce.Slider.NoTextBox, True, 0, 0)
self.knobs.append(slider)
self.addAndMakeVisible(slider)
def paint(self, g):
g.fillAll(self.backgroundColour)
def resized(self):
knobBox = juce.FlexBox()
knobBox.flexWrap = juce.FlexBox.Wrap.wrap
knobBox.justifyContent = juce.FlexBox.JustifyContent.spaceBetween
for k in self.knobs:
knobBox.items.add(juce.FlexItem(k).withMinHeight(50.0).withMinWidth(50.0).withFlex(1))
fb = juce.FlexBox()
fb.flexDirection = juce.FlexBox.Direction.column
fb.items.add(juce.FlexItem(knobBox).withFlex(2.5))
fb.performLayout(self.getLocalBounds().toFloat())
class MainPanel(juce.Component):
sliders = []
def __init__(self):
super().__init__()
for _ in range(5):
slider = juce.Slider()
slider.setTextBoxStyle(juce.Slider.TextEntryBoxPosition.NoTextBox, True, 0, 0)
self.sliders.append(slider)
self.addAndMakeVisible(slider)
def paint(self, g):
g.fillAll(juce.Colours.hotpink)
def resized(self):
isPortrait = self.getLocalBounds().getHeight() > self.getLocalBounds().getWidth()
fb = juce.FlexBox()
fb.flexDirection = juce.FlexBox.Direction.column if isPortrait else juce.FlexBox.Direction.row
for s in self.sliders:
if isPortrait:
s.setSliderStyle(juce.Slider.SliderStyle.LinearHorizontal)
else:
s.setSliderStyle(juce.Slider.SliderStyle.LinearVertical)
fb.items.add(juce.FlexItem(s).withFlex(0, 1, self.getHeight() / 5.0 if isPortrait else self.getWidth() / 5.0))
fb.performLayout(self.getLocalBounds().toFloat())
class MainContentComponent(juce.Component):
def __init__(self):
super().__init__()
self.rightPanel = RightSidePanel(juce.Colours.lightgrey)
self.leftPanel = LeftSidePanel(juce.Colours.lightblue)
self.mainPanel = MainPanel()
self.addAndMakeVisible(self.rightPanel)
self.addAndMakeVisible(self.leftPanel)
self.addAndMakeVisible(self.mainPanel)
self.setSize(600, 400)
def paint(self, g):
g.fillAll(self.getLookAndFeel().findColour(juce.ResizableWindow.backgroundColourId))
def resized(self):
bounds = self.getLocalBounds()
self.leftPanel.setBounds(bounds.removeFromLeft(self.proportionOfWidth(0.25)))
self.rightPanel.setBounds(bounds.removeFromRight(self.proportionOfWidth(0.25)))
self.mainPanel.setBounds(bounds)
"""
grid = juce.Grid()
grid.templateRows.add(juce.Grid.TrackInfo(juce.Grid.Fr(1)))
grid.templateColumns.add(juce.Grid.TrackInfo(juce.Grid.Fr(1)))
grid.templateColumns.add(juce.Grid.TrackInfo(juce.Grid.Fr(2)))
grid.templateColumns.add(juce.Grid.TrackInfo(juce.Grid.Fr(1)))
grid.items.add(juce.GridItem(self.leftPanel))
grid.items.add(juce.GridItem(self.mainPanel))
grid.items.add(juce.GridItem(self.rightPanel))
grid.performLayout(self.getLocalBounds())
"""
if __name__ == "__main__":
START_JUCE_COMPONENT(MainContentComponent, name="Animated Component")