@@ -74,39 +74,58 @@ class CustomWindow
7474 }
7575 */
7676
77- // Add the demos
78- int demo = 4 ;
79-
80- if (demo == 0 )
8177 {
78+ auto button = std::make_unique<yup::TextButton> (" Audio" );
79+ button->onClick = [this ] { selectComponent (0 ); };
80+ addAndMakeVisible (button.get ());
81+ buttons.add (std::move (button));
82+
8283 components.add (std::make_unique<AudioExample> (font));
83- addAndMakeVisible (components.getLast ());
84+ addChildComponent (components.getLast ());
8485 }
8586
86- if (demo == 1 )
8787 {
88+ auto button = std::make_unique<yup::TextButton> (" Layout Fonts" );
89+ button->onClick = [this ] { selectComponent (1 ); };
90+ addAndMakeVisible (button.get ());
91+ buttons.add (std::move (button));
92+
8893 components.add (std::make_unique<LayoutFontsExample> (font));
89- addAndMakeVisible (components.getLast ());
94+ addChildComponent (components.getLast ());
9095 }
9196
92- if (demo == 2 )
9397 {
98+ auto button = std::make_unique<yup::TextButton> (" Variable Fonts" );
99+ button->onClick = [this ] { selectComponent (2 ); };
100+ addAndMakeVisible (button.get ());
101+ buttons.add (std::move (button));
102+
94103 components.add (std::make_unique<VariableFontsExample> (font));
95- addAndMakeVisible (components.getLast ());
104+ addChildComponent (components.getLast ());
96105 }
97106
98- if (demo == 3 )
99107 {
108+ auto button = std::make_unique<yup::TextButton> (" Paths" );
109+ button->onClick = [this ] { selectComponent (3 ); };
110+ addAndMakeVisible (button.get ());
111+ buttons.add (std::move (button));
112+
100113 components.add (std::make_unique<PathsExample>());
101- addAndMakeVisible (components.getLast ());
114+ addChildComponent (components.getLast ());
102115 }
103116
104- if (demo == 4 )
105117 {
118+ auto button = std::make_unique<yup::TextButton> (" Text Editor" );
119+ button->onClick = [this ] { selectComponent (4 ); };
120+ addAndMakeVisible (button.get ());
121+ buttons.add (std::move (button));
122+
106123 components.add (std::make_unique<TextEditorDemo>());
107- addAndMakeVisible (components.getLast ());
124+ addChildComponent (components.getLast ());
108125 }
109126
127+ selectComponent (0 );
128+
110129 // Timer
111130 startTimerHz (10 );
112131 }
@@ -117,8 +136,15 @@ class CustomWindow
117136
118137 void resized () override
119138 {
139+ auto bounds = getLocalBounds ().reduced (5 );
140+ auto buttonBounds = bounds.removeFromTop (30 );
141+
142+ const auto buttonWidth = buttonBounds.getWidth () / buttons.size ();
143+ for (auto & button : buttons)
144+ button->setBounds (buttonBounds.removeFromLeft (buttonWidth));
145+
120146 for (auto & component : components)
121- component->setBounds (getLocalBounds () );
147+ component->setBounds (bounds );
122148 }
123149
124150 void paint (yup::Graphics& g) override
@@ -176,6 +202,14 @@ class CustomWindow
176202 yup::YUPApplication::getInstance ()->systemRequestedQuit ();
177203 }
178204
205+ void selectComponent (int index)
206+ {
207+ for (auto & component : components)
208+ component->setVisible (false );
209+
210+ components[index]->setVisible (true );
211+ }
212+
179213private:
180214 void updateWindowTitle ()
181215 {
@@ -194,6 +228,7 @@ class CustomWindow
194228 setTitle (title);
195229 }
196230
231+ yup::OwnedArray<yup::TextButton> buttons;
197232 yup::OwnedArray<yup::Component> components;
198233
199234 yup::Font font;
0 commit comments