@@ -29,6 +29,7 @@ class ArtboardDemo : public yup::Component
2929 ArtboardDemo ()
3030 {
3131 setWantsKeyboardFocus (true );
32+ setupControls ();
3233 }
3334
3435 bool loadArtboard ()
@@ -64,6 +65,8 @@ class ArtboardDemo : public yup::Component
6465 addAndMakeVisible (art);
6566
6667 art->setFile (artboardFile.getValue ());
68+ art->setLayout (getSelectedLayout ());
69+ art->setAlignment (getSelectedAlignment ());
6770
6871 art->advanceAndApply (i * art->durationSeconds ());
6972 }
@@ -85,6 +88,21 @@ class ArtboardDemo : public yup::Component
8588 return ;
8689
8790 auto bounds = getLocalBounds ().reduced (10 , 20 );
91+ auto controls = bounds.removeFromTop (30 );
92+
93+ auto labelHeight = 20 ;
94+ auto comboHeight = 24 ;
95+ auto labelWidth = 70 ;
96+ auto comboWidth = 170 ;
97+ auto spacing = 12 ;
98+
99+ fitLabel.setBounds (controls.removeFromLeft (labelWidth).withHeight (labelHeight));
100+ fitCombo.setBounds (controls.removeFromLeft (comboWidth).withHeight (comboHeight));
101+ controls.removeFromLeft (spacing);
102+ alignmentLabel.setBounds (controls.removeFromLeft (labelWidth).withHeight (labelHeight));
103+ alignmentCombo.setBounds (controls.removeFromLeft (comboWidth).withHeight (comboHeight));
104+
105+ bounds.removeFromTop (10 );
88106 auto width = bounds.getWidth () / totalColumns;
89107 auto height = bounds.getHeight () / totalRows;
90108
@@ -106,7 +124,119 @@ class ArtboardDemo : public yup::Component
106124 }
107125
108126private:
127+ void setupControls ()
128+ {
129+ auto labelFont = yup::ApplicationTheme::getGlobalTheme ()->getDefaultFont ().withHeight (12 .0f );
130+
131+ fitLabel.setText (" Fit" , yup::dontSendNotification);
132+ fitLabel.setFont (labelFont);
133+ addAndMakeVisible (fitLabel);
134+
135+ fitCombo.addItem (" Fill" , 1 );
136+ fitCombo.addItem (" Contain" , 2 );
137+ fitCombo.addItem (" Cover" , 3 );
138+ fitCombo.addItem (" Fit Width" , 4 );
139+ fitCombo.addItem (" Fit Height" , 5 );
140+ fitCombo.addItem (" None" , 6 );
141+ fitCombo.addItem (" Scale Down" , 7 );
142+ fitCombo.addItem (" Layout" , 8 );
143+ fitCombo.setSelectedId (2 );
144+ fitCombo.onSelectedItemChanged = [this ]
145+ {
146+ updateArtboardsLayout ();
147+ };
148+ addAndMakeVisible (fitCombo);
149+
150+ alignmentLabel.setText (" Align" , yup::dontSendNotification);
151+ alignmentLabel.setFont (labelFont);
152+ addAndMakeVisible (alignmentLabel);
153+
154+ alignmentCombo.addItem (" Top Left" , 1 );
155+ alignmentCombo.addItem (" Top Center" , 2 );
156+ alignmentCombo.addItem (" Top Right" , 3 );
157+ alignmentCombo.addItem (" Center Left" , 4 );
158+ alignmentCombo.addItem (" Center" , 5 );
159+ alignmentCombo.addItem (" Center Right" , 6 );
160+ alignmentCombo.addItem (" Bottom Left" , 7 );
161+ alignmentCombo.addItem (" Bottom Center" , 8 );
162+ alignmentCombo.addItem (" Bottom Right" , 9 );
163+ alignmentCombo.setSelectedId (5 );
164+ alignmentCombo.onSelectedItemChanged = [this ]
165+ {
166+ updateArtboardsLayout ();
167+ };
168+ addAndMakeVisible (alignmentCombo);
169+ }
170+
171+ yup::Artboard::Layout getSelectedLayout () const
172+ {
173+ switch (fitCombo.getSelectedId ())
174+ {
175+ case 1 :
176+ return yup::Artboard::Layout::fill;
177+ case 2 :
178+ return yup::Artboard::Layout::contain;
179+ case 3 :
180+ return yup::Artboard::Layout::cover;
181+ case 4 :
182+ return yup::Artboard::Layout::fitWidth;
183+ case 5 :
184+ return yup::Artboard::Layout::fitHeight;
185+ case 6 :
186+ return yup::Artboard::Layout::none;
187+ case 7 :
188+ return yup::Artboard::Layout::scaleDown;
189+ case 8 :
190+ return yup::Artboard::Layout::layout;
191+ }
192+
193+ return yup::Artboard::Layout::contain;
194+ }
195+
196+ yup::Artboard::Alignment getSelectedAlignment () const
197+ {
198+ switch (alignmentCombo.getSelectedId ())
199+ {
200+ case 1 :
201+ return yup::Artboard::Alignment::topLeft;
202+ case 2 :
203+ return yup::Artboard::Alignment::topCenter;
204+ case 3 :
205+ return yup::Artboard::Alignment::topRight;
206+ case 4 :
207+ return yup::Artboard::Alignment::centerLeft;
208+ case 5 :
209+ return yup::Artboard::Alignment::center;
210+ case 6 :
211+ return yup::Artboard::Alignment::centerRight;
212+ case 7 :
213+ return yup::Artboard::Alignment::bottomLeft;
214+ case 8 :
215+ return yup::Artboard::Alignment::bottomCenter;
216+ case 9 :
217+ return yup::Artboard::Alignment::bottomRight;
218+ }
219+
220+ return yup::Artboard::Alignment::center;
221+ }
222+
223+ void updateArtboardsLayout ()
224+ {
225+ auto newLayout = getSelectedLayout ();
226+ auto newAlignment = getSelectedAlignment ();
227+
228+ for (auto * artboard : artboards)
229+ {
230+ artboard->setLayout (newLayout);
231+ artboard->setAlignment (newAlignment);
232+ }
233+ }
234+
109235 yup::OwnedArray<yup::Artboard> artboards;
236+ yup::Label fitLabel;
237+ yup::ComboBox fitCombo;
238+ yup::Label alignmentLabel;
239+ yup::ComboBox alignmentCombo;
110240 int totalRows = 1 ;
111241 int totalColumns = 1 ;
112242};
0 commit comments