The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1355 lines
51KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. /*******************************************************************************
  16. The block below describes the properties of this PIP. A PIP is a short snippet
  17. of code that can be read by the Projucer and used to generate a JUCE project.
  18. BEGIN_JUCE_PIP_METADATA
  19. name: WidgetsDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Showcases various widgets.
  24. dependencies: juce_core, juce_data_structures, juce_events, juce_graphics,
  25. juce_gui_basics, juce_gui_extra
  26. exporters: xcode_mac, vs2017, linux_make, androidstudio, xcode_iphone
  27. type: Component
  28. mainClass: WidgetsDemo
  29. useLocalCopy: 1
  30. END_JUCE_PIP_METADATA
  31. *******************************************************************************/
  32. #pragma once
  33. #ifndef PIP_DEMO_UTILITIES_INCLUDED
  34. #include "../Assets/DemoUtilities.h"
  35. #endif
  36. //==============================================================================
  37. static void showBubbleMessage (Component& targetComponent, const String& textToShow,
  38. std::unique_ptr<BubbleMessageComponent>& bmc)
  39. {
  40. bmc.reset (new BubbleMessageComponent());
  41. if (Desktop::canUseSemiTransparentWindows())
  42. {
  43. bmc->setAlwaysOnTop (true);
  44. bmc->addToDesktop (0);
  45. }
  46. else
  47. {
  48. targetComponent.getTopLevelComponent()->addChildComponent (bmc.get());
  49. }
  50. AttributedString text (textToShow);
  51. text.setJustification (Justification::centred);
  52. text.setColour (targetComponent.findColour (TextButton::textColourOffId));
  53. bmc->showAt (&targetComponent, text, 2000, true, false);
  54. }
  55. //==============================================================================
  56. /** To demonstrate how sliders can have custom snapping applied to their values,
  57. this simple class snaps the value to 50 if it comes near.
  58. */
  59. struct SnappingSlider : public Slider
  60. {
  61. double snapValue (double attemptedValue, DragMode dragMode) override
  62. {
  63. if (dragMode == notDragging)
  64. return attemptedValue; // if they're entering the value in the text-box, don't mess with it.
  65. if (attemptedValue > 40 && attemptedValue < 60)
  66. return 50.0;
  67. return attemptedValue;
  68. }
  69. };
  70. /** A TextButton that pops up a colour chooser to change its colours. */
  71. class ColourChangeButton : public TextButton,
  72. public ChangeListener
  73. {
  74. public:
  75. ColourChangeButton()
  76. : TextButton ("Click to change colour...")
  77. {
  78. setSize (10, 24);
  79. changeWidthToFitText();
  80. }
  81. void clicked() override
  82. {
  83. auto* colourSelector = new ColourSelector();
  84. colourSelector->setName ("background");
  85. colourSelector->setCurrentColour (findColour (TextButton::buttonColourId));
  86. colourSelector->addChangeListener (this);
  87. colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  88. colourSelector->setSize (300, 400);
  89. CallOutBox::launchAsynchronously (colourSelector, getScreenBounds(), nullptr);
  90. }
  91. void changeListenerCallback (ChangeBroadcaster* source) override
  92. {
  93. if (auto* cs = dynamic_cast<ColourSelector*> (source))
  94. setColour (TextButton::buttonColourId, cs->getCurrentColour());
  95. }
  96. };
  97. //==============================================================================
  98. struct SlidersPage : public Component
  99. {
  100. SlidersPage()
  101. {
  102. Rectangle<int> layoutArea { 20, 20, 580, 430 };
  103. auto sliderArea = layoutArea.removeFromTop (320);
  104. auto* s = createSlider (false);
  105. s->setSliderStyle (Slider::LinearVertical);
  106. s->setTextBoxStyle (Slider::TextBoxBelow, false, 100, 20);
  107. s->setBounds (sliderArea.removeFromLeft (70));
  108. s->setDoubleClickReturnValue (true, 50.0); // double-clicking this slider will set it to 50.0
  109. s->setTextValueSuffix (" units");
  110. s = createSlider (false);
  111. s->setSliderStyle (Slider::LinearVertical);
  112. s->setVelocityBasedMode (true);
  113. s->setSkewFactor (0.5);
  114. s->setTextBoxStyle (Slider::TextBoxAbove, true, 100, 20);
  115. s->setBounds (sliderArea.removeFromLeft (70));
  116. s->setTextValueSuffix (" rels");
  117. sliderArea.removeFromLeft (20);
  118. auto horizonalSliderArea = sliderArea.removeFromLeft (180);
  119. s = createSlider (true);
  120. s->setSliderStyle (Slider::LinearHorizontal);
  121. s->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
  122. s->setBounds (horizonalSliderArea.removeFromTop (20));
  123. s = createSlider (false);
  124. s->setSliderStyle (Slider::LinearHorizontal);
  125. s->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  126. horizonalSliderArea.removeFromTop (20);
  127. s->setBounds (horizonalSliderArea.removeFromTop (20));
  128. s->setPopupDisplayEnabled (true, false, this);
  129. s->setTextValueSuffix (" nuns required to change a lightbulb");
  130. s = createSlider (false);
  131. s->setSliderStyle (Slider::LinearHorizontal);
  132. s->setTextBoxStyle (Slider::TextEntryBoxPosition::TextBoxAbove, false, 70, 20);
  133. horizonalSliderArea.removeFromTop (20);
  134. s->setBounds (horizonalSliderArea.removeFromTop (50));
  135. s->setPopupDisplayEnabled (true, false, this);
  136. s = createSlider (false);
  137. s->setSliderStyle (Slider::IncDecButtons);
  138. s->setTextBoxStyle (Slider::TextBoxLeft, false, 50, 20);
  139. horizonalSliderArea.removeFromTop (20);
  140. s->setBounds (horizonalSliderArea.removeFromTop (20));
  141. s->setIncDecButtonsMode (Slider::incDecButtonsDraggable_Vertical);
  142. s = createSlider (false);
  143. s->setSliderStyle (Slider::Rotary);
  144. s->setRotaryParameters (MathConstants<float>::pi * 1.2f, MathConstants<float>::pi * 2.8f, false);
  145. s->setTextBoxStyle (Slider::TextBoxRight, false, 70, 20);
  146. horizonalSliderArea.removeFromTop (15);
  147. s->setBounds (horizonalSliderArea.removeFromTop (70));
  148. s->setTextValueSuffix (" mm");
  149. s = createSlider (false);
  150. s->setSliderStyle (Slider::LinearBar);
  151. horizonalSliderArea.removeFromTop (10);
  152. s->setBounds (horizonalSliderArea.removeFromTop (30));
  153. s->setTextValueSuffix (" gallons");
  154. sliderArea.removeFromLeft (20);
  155. auto twoValueSliderArea = sliderArea.removeFromLeft (180);
  156. s = createSlider (false);
  157. s->setSliderStyle (Slider::TwoValueHorizontal);
  158. s->setBounds (twoValueSliderArea.removeFromTop (40));
  159. s = createSlider (false);
  160. s->setSliderStyle (Slider::ThreeValueHorizontal);
  161. s->setPopupDisplayEnabled (true, false, this);
  162. twoValueSliderArea.removeFromTop (10);
  163. s->setBounds (twoValueSliderArea.removeFromTop (40));
  164. s = createSlider (false);
  165. s->setSliderStyle (Slider::TwoValueVertical);
  166. twoValueSliderArea.removeFromLeft (30);
  167. s->setBounds (twoValueSliderArea.removeFromLeft (40));
  168. s = createSlider (false);
  169. s->setSliderStyle (Slider::ThreeValueVertical);
  170. s->setPopupDisplayEnabled (true, false, this);
  171. twoValueSliderArea.removeFromLeft (30);
  172. s->setBounds (twoValueSliderArea.removeFromLeft (40));
  173. s = createSlider (false);
  174. s->setSliderStyle (Slider::LinearBarVertical);
  175. s->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  176. sliderArea.removeFromLeft (20);
  177. s->setBounds (sliderArea.removeFromLeft (20));
  178. s->setPopupDisplayEnabled (true, true, this);
  179. s->setTextValueSuffix (" mickles in a muckle");
  180. /* Here, we'll create a Value object, and tell a bunch of our sliders to use it as their
  181. value source. By telling them all to share the same Value, they'll stay in sync with
  182. each other.
  183. We could also optionally keep a copy of this Value elsewhere, and by changing it,
  184. cause all the sliders to automatically update.
  185. */
  186. Value sharedValue;
  187. sharedValue = Random::getSystemRandom().nextDouble() * 100;
  188. for (int i = 0; i < 8; ++i)
  189. sliders.getUnchecked (i)->getValueObject().referTo (sharedValue);
  190. // ..and now we'll do the same for all our min/max slider values..
  191. Value sharedValueMin, sharedValueMax;
  192. sharedValueMin = Random::getSystemRandom().nextDouble() * 40.0;
  193. sharedValueMax = Random::getSystemRandom().nextDouble() * 40.0 + 60.0;
  194. for (int i = 8; i <= 11; ++i)
  195. {
  196. auto* selectedSlider = sliders.getUnchecked(i);
  197. selectedSlider->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  198. selectedSlider->getMaxValueObject().referTo (sharedValueMax);
  199. selectedSlider->getMinValueObject().referTo (sharedValueMin);
  200. }
  201. hintLabel.setBounds (layoutArea);
  202. addAndMakeVisible (hintLabel);
  203. }
  204. private:
  205. OwnedArray<Slider> sliders;
  206. Label hintLabel { "hint", "Try right-clicking on a slider for an options menu. \n\n"
  207. "Also, holding down CTRL while dragging will turn on a slider's velocity-sensitive mode" };
  208. Slider* createSlider (bool isSnapping)
  209. {
  210. auto* s = isSnapping ? new SnappingSlider()
  211. : new Slider();
  212. sliders.add (s);
  213. addAndMakeVisible (s);
  214. s->setRange (0.0, 100.0, 0.1);
  215. s->setPopupMenuEnabled (true);
  216. s->setValue (Random::getSystemRandom().nextDouble() * 100.0, dontSendNotification);
  217. return s;
  218. }
  219. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SlidersPage)
  220. };
  221. //==============================================================================
  222. struct ButtonsPage : public Component
  223. {
  224. ButtonsPage()
  225. {
  226. {
  227. auto* group = addToList (new GroupComponent ("group", "Radio buttons"));
  228. group->setBounds (20, 20, 220, 140);
  229. }
  230. for (int i = 0; i < 4; ++i)
  231. {
  232. auto* tb = addToList (new ToggleButton ("Radio Button #" + String (i + 1)));
  233. tb->setRadioGroupId (1234);
  234. tb->setBounds (45, 46 + i * 22, 180, 22);
  235. tb->setTooltip ("A set of mutually-exclusive radio buttons");
  236. if (i == 0)
  237. tb->setToggleState (true, dontSendNotification);
  238. }
  239. for (int i = 0; i < 4; ++i)
  240. {
  241. DrawablePath normal, over;
  242. Path p;
  243. p.addStar ({}, i + 5, 20.0f, 50.0f, -0.2f);
  244. normal.setPath (p);
  245. normal.setFill (Colours::lightblue);
  246. normal.setStrokeFill (Colours::black);
  247. normal.setStrokeThickness (4.0f);
  248. over.setPath (p);
  249. over.setFill (Colours::blue);
  250. over.setStrokeFill (Colours::black);
  251. over.setStrokeThickness (4.0f);
  252. auto* db = addToList (new DrawableButton (String (i + 5) + " points", DrawableButton::ImageAboveTextLabel));
  253. db->setImages (&normal, &over, 0);
  254. db->setClickingTogglesState (true);
  255. db->setRadioGroupId (23456);
  256. int buttonSize = 50;
  257. db->setBounds (25 + i * buttonSize, 180, buttonSize, buttonSize);
  258. if (i == 0)
  259. db->setToggleState (true, dontSendNotification);
  260. }
  261. for (int i = 0; i < 4; ++i)
  262. {
  263. auto* tb = addToList (new TextButton ("Button " + String (i + 1)));
  264. tb->setClickingTogglesState (true);
  265. tb->setRadioGroupId (34567);
  266. tb->setColour (TextButton::textColourOffId, Colours::black);
  267. tb->setColour (TextButton::textColourOnId, Colours::black);
  268. tb->setColour (TextButton::buttonColourId, Colours::white);
  269. tb->setColour (TextButton::buttonOnColourId, Colours::blueviolet.brighter());
  270. tb->setBounds (20 + i * 55, 260, 55, 24);
  271. tb->setConnectedEdges (((i != 0) ? Button::ConnectedOnLeft : 0)
  272. | ((i != 3) ? Button::ConnectedOnRight : 0));
  273. if (i == 0)
  274. tb->setToggleState (true, dontSendNotification);
  275. }
  276. {
  277. auto* colourChangeButton = new ColourChangeButton();
  278. components.add (colourChangeButton);
  279. addAndMakeVisible (colourChangeButton);
  280. colourChangeButton->setTopLeftPosition (20, 320);
  281. }
  282. {
  283. auto* hyperlink = addToList (new HyperlinkButton ("This is a HyperlinkButton",
  284. { "http://www.juce.com" }));
  285. hyperlink->setBounds (260, 20, 200, 24);
  286. }
  287. // create some drawables to use for our drawable buttons...
  288. DrawablePath normal, over;
  289. {
  290. Path p;
  291. p.addStar ({}, 5, 20.0f, 50.0f, 0.2f);
  292. normal.setPath (p);
  293. normal.setFill (getRandomDarkColour());
  294. }
  295. {
  296. Path p;
  297. p.addStar ({}, 9, 25.0f, 50.0f, 0.0f);
  298. over.setPath (p);
  299. over.setFill (getRandomBrightColour());
  300. over.setStrokeFill (getRandomDarkColour());
  301. over.setStrokeThickness (5.0f);
  302. }
  303. DrawableImage down;
  304. down.setImage (getImageFromAssets ("juce_icon.png"));
  305. down.setOverlayColour (Colours::black.withAlpha (0.3f));
  306. auto popupMessageCallback = [this]
  307. {
  308. if (auto* focused = Component::getCurrentlyFocusedComponent())
  309. showBubbleMessage (*focused,
  310. "This is a demo of the BubbleMessageComponent, which lets you pop up a message pointing "
  311. "at a component or somewhere on the screen.\n\n"
  312. "The message bubbles will disappear after a timeout period, or when the mouse is clicked.",
  313. this->bubbleMessage);
  314. };
  315. {
  316. // create an image-above-text button from these drawables..
  317. auto db = addToList (new DrawableButton ("Button 1", DrawableButton::ImageAboveTextLabel));
  318. db->setImages (&normal, &over, &down);
  319. db->setBounds (260, 60, 80, 80);
  320. db->setTooltip ("This is a DrawableButton with a label");
  321. db->onClick = popupMessageCallback;
  322. }
  323. {
  324. // create an image-only button from these drawables..
  325. auto db = addToList (new DrawableButton ("Button 2", DrawableButton::ImageFitted));
  326. db->setImages (&normal, &over, &down);
  327. db->setClickingTogglesState (true);
  328. db->setBounds (370, 60, 80, 80);
  329. db->setTooltip ("This is an image-only DrawableButton");
  330. db->onClick = popupMessageCallback;
  331. }
  332. {
  333. // create an image-on-button-shape button from the same drawables..
  334. auto db = addToList (new DrawableButton ("Button 3", DrawableButton::ImageOnButtonBackground));
  335. db->setImages (&normal, 0, 0);
  336. db->setBounds (260, 160, 110, 25);
  337. db->setTooltip ("This is a DrawableButton on a standard button background");
  338. db->onClick = popupMessageCallback;
  339. }
  340. {
  341. auto db = addToList (new DrawableButton ("Button 4", DrawableButton::ImageOnButtonBackground));
  342. db->setImages (&normal, &over, &down);
  343. db->setClickingTogglesState (true);
  344. db->setColour (DrawableButton::backgroundColourId, Colours::white);
  345. db->setColour (DrawableButton::backgroundOnColourId, Colours::yellow);
  346. db->setBounds (400, 150, 50, 50);
  347. db->setTooltip ("This is a DrawableButton on a standard button background");
  348. db->onClick = popupMessageCallback;
  349. }
  350. {
  351. auto sb = addToList (new ShapeButton ("ShapeButton",
  352. getRandomDarkColour(),
  353. getRandomDarkColour(),
  354. getRandomDarkColour()));
  355. sb->setShape (getJUCELogoPath(), false, true, false);
  356. sb->setBounds (260, 220, 200, 120);
  357. }
  358. {
  359. auto ib = addToList (new ImageButton ("ImageButton"));
  360. auto juceImage = getImageFromAssets ("juce_icon.png");
  361. ib->setImages (true, true, true,
  362. juceImage, 0.7f, Colours::transparentBlack,
  363. juceImage, 1.0f, Colours::transparentBlack,
  364. juceImage, 1.0f, getRandomBrightColour().withAlpha (0.8f),
  365. 0.5f);
  366. ib->setBounds (260, 350, 100, 100);
  367. ib->setTooltip ("ImageButton - showing alpha-channel hit-testing and colour overlay when clicked");
  368. }
  369. }
  370. private:
  371. OwnedArray<Component> components;
  372. std::unique_ptr<BubbleMessageComponent> bubbleMessage;
  373. // This little function avoids a bit of code-duplication by adding a component to
  374. // our list as well as calling addAndMakeVisible on it..
  375. template <typename ComponentType>
  376. ComponentType* addToList (ComponentType* newComp)
  377. {
  378. components.add (newComp);
  379. addAndMakeVisible (newComp);
  380. return newComp;
  381. }
  382. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonsPage)
  383. };
  384. //==============================================================================
  385. struct MiscPage : public Component
  386. {
  387. MiscPage()
  388. {
  389. addAndMakeVisible (textEditor1);
  390. textEditor1.setBounds (10, 25, 200, 24);
  391. textEditor1.setText ("Single-line text box");
  392. addAndMakeVisible (textEditor2);
  393. textEditor2.setBounds (10, 55, 200, 24);
  394. textEditor2.setText ("Password");
  395. addAndMakeVisible (comboBox);
  396. comboBox.setBounds (10, 85, 200, 24);
  397. comboBox.setEditableText (true);
  398. comboBox.setJustificationType (Justification::centred);
  399. for (int i = 1; i < 100; ++i)
  400. comboBox.addItem ("combo box item " + String (i), i);
  401. comboBox.setSelectedId (1);
  402. }
  403. void lookAndFeelChanged() override
  404. {
  405. textEditor1.applyFontToAllText (textEditor1.getFont());
  406. textEditor2.applyFontToAllText (textEditor2.getFont());
  407. }
  408. TextEditor textEditor1,
  409. textEditor2 { "Password", (juce_wchar) 0x2022 };
  410. ComboBox comboBox { "Combo" };
  411. };
  412. //==============================================================================
  413. class ToolbarDemoComp : public Component,
  414. private Slider::Listener
  415. {
  416. public:
  417. ToolbarDemoComp()
  418. {
  419. // Create and add the toolbar...
  420. addAndMakeVisible (toolbar);
  421. // And use our item factory to add a set of default icons to it...
  422. toolbar.addDefaultItems (factory);
  423. // Now we'll just create the other sliders and buttons on the demo page, which adjust
  424. // the toolbar's properties...
  425. addAndMakeVisible (infoLabel);
  426. infoLabel.setJustificationType (Justification::topLeft);
  427. infoLabel.setBounds (80, 80, 450, 100);
  428. infoLabel.setInterceptsMouseClicks (false, false);
  429. addAndMakeVisible (depthSlider);
  430. depthSlider.setRange (10.0, 200.0, 1.0);
  431. depthSlider.setValue (50, dontSendNotification);
  432. depthSlider.addListener (this);
  433. depthSlider.setBounds (80, 210, 300, 22);
  434. depthLabel.attachToComponent (&depthSlider, false);
  435. addAndMakeVisible (orientationButton);
  436. orientationButton.onClick = [this] { toolbar.setVertical (! toolbar.isVertical()); resized(); };
  437. orientationButton.changeWidthToFitText (22);
  438. orientationButton.setTopLeftPosition (depthSlider.getX(), depthSlider.getBottom() + 20);
  439. addAndMakeVisible (customiseButton);
  440. customiseButton.onClick = [this] { toolbar.showCustomisationDialog (factory); };
  441. customiseButton.changeWidthToFitText (22);
  442. customiseButton.setTopLeftPosition (orientationButton.getRight() + 20, orientationButton.getY());
  443. }
  444. void resized() override
  445. {
  446. auto toolbarThickness = (int) depthSlider.getValue();
  447. if (toolbar.isVertical())
  448. toolbar.setBounds (getLocalBounds().removeFromLeft (toolbarThickness));
  449. else
  450. toolbar.setBounds (getLocalBounds().removeFromTop (toolbarThickness));
  451. }
  452. void sliderValueChanged (Slider*) override
  453. {
  454. resized();
  455. }
  456. private:
  457. Toolbar toolbar;
  458. Slider depthSlider { Slider::LinearHorizontal, Slider::TextBoxLeft };
  459. Label depthLabel { {}, "Toolbar depth:" },
  460. infoLabel { {}, "As well as showing off toolbars, this demo illustrates how to store "
  461. "a set of SVG files in a Zip file, embed that in your application, and read "
  462. "them back in at runtime.\n\nThe icon images here are taken from the open-source "
  463. "Tango icon project."};
  464. TextButton orientationButton { "Vertical/Horizontal" },
  465. customiseButton { "Customise..." };
  466. //==============================================================================
  467. class DemoToolbarItemFactory : public ToolbarItemFactory
  468. {
  469. public:
  470. DemoToolbarItemFactory() {}
  471. //==============================================================================
  472. // Each type of item a toolbar can contain must be given a unique ID. These
  473. // are the ones we'll use in this demo.
  474. enum DemoToolbarItemIds
  475. {
  476. doc_new = 1,
  477. doc_open = 2,
  478. doc_save = 3,
  479. doc_saveAs = 4,
  480. edit_copy = 5,
  481. edit_cut = 6,
  482. edit_paste = 7,
  483. juceLogoButton = 8,
  484. customComboBox = 9
  485. };
  486. void getAllToolbarItemIds (Array<int>& ids) override
  487. {
  488. // This returns the complete list of all item IDs that are allowed to
  489. // go in our toolbar. Any items you might want to add must be listed here. The
  490. // order in which they are listed will be used by the toolbar customisation panel.
  491. ids.add (doc_new);
  492. ids.add (doc_open);
  493. ids.add (doc_save);
  494. ids.add (doc_saveAs);
  495. ids.add (edit_copy);
  496. ids.add (edit_cut);
  497. ids.add (edit_paste);
  498. ids.add (juceLogoButton);
  499. ids.add (customComboBox);
  500. // If you're going to use separators, then they must also be added explicitly
  501. // to the list.
  502. ids.add (separatorBarId);
  503. ids.add (spacerId);
  504. ids.add (flexibleSpacerId);
  505. }
  506. void getDefaultItemSet (Array<int>& ids) override
  507. {
  508. // This returns an ordered list of the set of items that make up a
  509. // toolbar's default set. Not all items need to be on this list, and
  510. // items can appear multiple times (e.g. the separators used here).
  511. ids.add (doc_new);
  512. ids.add (doc_open);
  513. ids.add (doc_save);
  514. ids.add (doc_saveAs);
  515. ids.add (spacerId);
  516. ids.add (separatorBarId);
  517. ids.add (edit_copy);
  518. ids.add (edit_cut);
  519. ids.add (edit_paste);
  520. ids.add (separatorBarId);
  521. ids.add (flexibleSpacerId);
  522. ids.add (customComboBox);
  523. ids.add (flexibleSpacerId);
  524. ids.add (separatorBarId);
  525. ids.add (juceLogoButton);
  526. }
  527. ToolbarItemComponent* createItem (int itemId) override
  528. {
  529. switch (itemId)
  530. {
  531. case doc_new: return createButtonFromZipFileSVG (itemId, "new", "document-new.svg");
  532. case doc_open: return createButtonFromZipFileSVG (itemId, "open", "document-open.svg");
  533. case doc_save: return createButtonFromZipFileSVG (itemId, "save", "document-save.svg");
  534. case doc_saveAs: return createButtonFromZipFileSVG (itemId, "save as", "document-save-as.svg");
  535. case edit_copy: return createButtonFromZipFileSVG (itemId, "copy", "edit-copy.svg");
  536. case edit_cut: return createButtonFromZipFileSVG (itemId, "cut", "edit-cut.svg");
  537. case edit_paste: return createButtonFromZipFileSVG (itemId, "paste", "edit-paste.svg");
  538. case juceLogoButton:
  539. {
  540. auto* drawable = new DrawableImage();
  541. drawable->setImage (getImageFromAssets ("juce_icon.png"));
  542. return new ToolbarButton (itemId, "juce!", drawable, 0);
  543. }
  544. case customComboBox: return new CustomToolbarComboBox (itemId);
  545. default: break;
  546. }
  547. return nullptr;
  548. }
  549. private:
  550. StringArray iconNames;
  551. OwnedArray<Drawable> iconsFromZipFile;
  552. // This is a little utility to create a button with one of the SVG images in
  553. // our embedded ZIP file "icons.zip"
  554. ToolbarButton* createButtonFromZipFileSVG (const int itemId, const String& text, const String& filename)
  555. {
  556. if (iconsFromZipFile.size() == 0)
  557. {
  558. // If we've not already done so, load all the images from the zip file..
  559. ZipFile icons (createAssetInputStream ("icons.zip"), true);
  560. for (int i = 0; i < icons.getNumEntries(); ++i)
  561. {
  562. std::unique_ptr<InputStream> svgFileStream (icons.createStreamForEntry (i));
  563. if (svgFileStream.get() != nullptr)
  564. {
  565. iconNames.add (icons.getEntry (i)->filename);
  566. iconsFromZipFile.add (Drawable::createFromImageDataStream (*svgFileStream));
  567. }
  568. }
  569. }
  570. auto* image = iconsFromZipFile[iconNames.indexOf (filename)]->createCopy();
  571. return new ToolbarButton (itemId, text, image, 0);
  572. }
  573. // Demonstrates how to put a custom component into a toolbar - this one contains
  574. // a ComboBox.
  575. class CustomToolbarComboBox : public ToolbarItemComponent
  576. {
  577. public:
  578. CustomToolbarComboBox (const int toolbarItemId)
  579. : ToolbarItemComponent (toolbarItemId, "Custom Toolbar Item", false)
  580. {
  581. addAndMakeVisible (comboBox);
  582. for (int i = 1; i < 20; ++i)
  583. comboBox.addItem ("Toolbar ComboBox item " + String (i), i);
  584. comboBox.setSelectedId (1);
  585. comboBox.setEditableText (true);
  586. }
  587. bool getToolbarItemSizes (int /*toolbarDepth*/, bool isVertical,
  588. int& preferredSize, int& minSize, int& maxSize) override
  589. {
  590. if (isVertical)
  591. return false;
  592. preferredSize = 250;
  593. minSize = 80;
  594. maxSize = 300;
  595. return true;
  596. }
  597. void paintButtonArea (Graphics&, int, int, bool, bool) override
  598. {
  599. }
  600. void contentAreaChanged (const Rectangle<int>& newArea) override
  601. {
  602. comboBox.setSize (newArea.getWidth() - 2,
  603. jmin (newArea.getHeight() - 2, 22));
  604. comboBox.setCentrePosition (newArea.getCentreX(), newArea.getCentreY());
  605. }
  606. private:
  607. ComboBox comboBox { "demo toolbar combo box" };
  608. };
  609. };
  610. DemoToolbarItemFactory factory;
  611. };
  612. //==============================================================================
  613. /**
  614. This class shows how to implement a TableListBoxModel to show in a TableListBox.
  615. */
  616. class TableDemoComponent : public Component,
  617. public TableListBoxModel
  618. {
  619. public:
  620. TableDemoComponent()
  621. {
  622. // Load some data from an embedded XML file..
  623. loadData();
  624. // Create our table component and add it to this component..
  625. addAndMakeVisible (table);
  626. table.setModel (this);
  627. // give it a border
  628. table.setColour (ListBox::outlineColourId, Colours::grey);
  629. table.setOutlineThickness (1);
  630. // Add some columns to the table header, based on the column list in our database..
  631. forEachXmlChildElement (*columnList, columnXml)
  632. {
  633. table.getHeader().addColumn (columnXml->getStringAttribute ("name"),
  634. columnXml->getIntAttribute ("columnId"),
  635. columnXml->getIntAttribute ("width"),
  636. 50, 400,
  637. TableHeaderComponent::defaultFlags);
  638. }
  639. // we could now change some initial settings..
  640. table.getHeader().setSortColumnId (1, true); // sort forwards by the ID column
  641. table.getHeader().setColumnVisible (7, false); // hide the "length" column until the user shows it
  642. // un-comment this line to have a go of stretch-to-fit mode
  643. // table.getHeader().setStretchToFitActive (true);
  644. table.setMultipleSelectionEnabled (true);
  645. }
  646. // This is overloaded from TableListBoxModel, and must return the total number of rows in our table
  647. int getNumRows() override
  648. {
  649. return numRows;
  650. }
  651. // This is overloaded from TableListBoxModel, and should fill in the background of the whole row
  652. void paintRowBackground (Graphics& g, int rowNumber, int /*width*/, int /*height*/, bool rowIsSelected) override
  653. {
  654. auto alternateColour = getLookAndFeel().findColour (ListBox::backgroundColourId)
  655. .interpolatedWith (getLookAndFeel().findColour (ListBox::textColourId), 0.03f);
  656. if (rowIsSelected)
  657. g.fillAll (Colours::lightblue);
  658. else if (rowNumber % 2)
  659. g.fillAll (alternateColour);
  660. }
  661. // This is overloaded from TableListBoxModel, and must paint any cells that aren't using custom
  662. // components.
  663. void paintCell (Graphics& g, int rowNumber, int columnId,
  664. int width, int height, bool /*rowIsSelected*/) override
  665. {
  666. g.setColour (getLookAndFeel().findColour (ListBox::textColourId));
  667. g.setFont (font);
  668. if (auto* rowElement = dataList->getChildElement (rowNumber))
  669. {
  670. auto text = rowElement->getStringAttribute (getAttributeNameForColumnId (columnId));
  671. g.drawText (text, 2, 0, width - 4, height, Justification::centredLeft, true);
  672. }
  673. g.setColour (getLookAndFeel().findColour (ListBox::backgroundColourId));
  674. g.fillRect (width - 1, 0, 1, height);
  675. }
  676. // This is overloaded from TableListBoxModel, and tells us that the user has clicked a table header
  677. // to change the sort order.
  678. void sortOrderChanged (int newSortColumnId, bool isForwards) override
  679. {
  680. if (newSortColumnId != 0)
  681. {
  682. DemoDataSorter sorter (getAttributeNameForColumnId (newSortColumnId), isForwards);
  683. dataList->sortChildElements (sorter);
  684. table.updateContent();
  685. }
  686. }
  687. // This is overloaded from TableListBoxModel, and must update any custom components that we're using
  688. Component* refreshComponentForCell (int rowNumber, int columnId, bool /*isRowSelected*/,
  689. Component* existingComponentToUpdate) override
  690. {
  691. if (columnId == 1 || columnId == 7) // The ID and Length columns do not have a custom component
  692. {
  693. jassert (existingComponentToUpdate == nullptr);
  694. return nullptr;
  695. }
  696. if (columnId == 5) // For the ratings column, we return the custom combobox component
  697. {
  698. auto* ratingsBox = static_cast<RatingColumnCustomComponent*> (existingComponentToUpdate);
  699. // If an existing component is being passed-in for updating, we'll re-use it, but
  700. // if not, we'll have to create one.
  701. if (ratingsBox == nullptr)
  702. ratingsBox = new RatingColumnCustomComponent (*this);
  703. ratingsBox->setRowAndColumn (rowNumber, columnId);
  704. return ratingsBox;
  705. }
  706. // The other columns are editable text columns, for which we use the custom Label component
  707. auto* textLabel = static_cast<EditableTextCustomComponent*> (existingComponentToUpdate);
  708. // same as above...
  709. if (textLabel == nullptr)
  710. textLabel = new EditableTextCustomComponent (*this);
  711. textLabel->setRowAndColumn (rowNumber, columnId);
  712. return textLabel;
  713. }
  714. // This is overloaded from TableListBoxModel, and should choose the best width for the specified
  715. // column.
  716. int getColumnAutoSizeWidth (int columnId) override
  717. {
  718. if (columnId == 5)
  719. return 100; // (this is the ratings column, containing a custom combobox component)
  720. int widest = 32;
  721. // find the widest bit of text in this column..
  722. for (int i = getNumRows(); --i >= 0;)
  723. {
  724. if (auto* rowElement = dataList->getChildElement (i))
  725. {
  726. auto text = rowElement->getStringAttribute (getAttributeNameForColumnId (columnId));
  727. widest = jmax (widest, font.getStringWidth (text));
  728. }
  729. }
  730. return widest + 8;
  731. }
  732. // A couple of quick methods to set and get cell values when the user changes them
  733. int getRating (const int rowNumber) const
  734. {
  735. return dataList->getChildElement (rowNumber)->getIntAttribute ("Rating");
  736. }
  737. void setRating (const int rowNumber, const int newRating)
  738. {
  739. dataList->getChildElement (rowNumber)->setAttribute ("Rating", newRating);
  740. }
  741. String getText (const int columnNumber, const int rowNumber) const
  742. {
  743. return dataList->getChildElement (rowNumber)->getStringAttribute ( getAttributeNameForColumnId(columnNumber));
  744. }
  745. void setText (const int columnNumber, const int rowNumber, const String& newText)
  746. {
  747. auto columnName = table.getHeader().getColumnName (columnNumber);
  748. dataList->getChildElement (rowNumber)->setAttribute (columnName, newText);
  749. }
  750. //==============================================================================
  751. void resized() override
  752. {
  753. // position our table with a gap around its edge
  754. table.setBoundsInset (BorderSize<int> (8));
  755. }
  756. private:
  757. TableListBox table; // the table component itself
  758. Font font { 14.0f };
  759. std::unique_ptr<XmlElement> demoData; // This is the XML document loaded from the embedded file "demo table data.xml"
  760. XmlElement* columnList = nullptr; // A pointer to the sub-node of demoData that contains the list of columns
  761. XmlElement* dataList = nullptr; // A pointer to the sub-node of demoData that contains the list of data rows
  762. int numRows; // The number of rows of data we've got
  763. //==============================================================================
  764. // This is a custom Label component, which we use for the table's editable text columns.
  765. class EditableTextCustomComponent : public Label
  766. {
  767. public:
  768. EditableTextCustomComponent (TableDemoComponent& td) : owner (td)
  769. {
  770. // double click to edit the label text; single click handled below
  771. setEditable (false, true, false);
  772. }
  773. void mouseDown (const MouseEvent& event) override
  774. {
  775. // single click on the label should simply select the row
  776. owner.table.selectRowsBasedOnModifierKeys (row, event.mods, false);
  777. Label::mouseDown (event);
  778. }
  779. void textWasEdited() override
  780. {
  781. owner.setText (columnId, row, getText());
  782. }
  783. // Our demo code will call this when we may need to update our contents
  784. void setRowAndColumn (const int newRow, const int newColumn)
  785. {
  786. row = newRow;
  787. columnId = newColumn;
  788. setText (owner.getText(columnId, row), dontSendNotification);
  789. }
  790. void paint (Graphics& g) override
  791. {
  792. auto& lf = getLookAndFeel();
  793. if (! dynamic_cast<LookAndFeel_V4*> (&lf))
  794. lf.setColour (textColourId, Colours::black);
  795. Label::paint (g);
  796. }
  797. private:
  798. TableDemoComponent& owner;
  799. int row, columnId;
  800. Colour textColour;
  801. };
  802. //==============================================================================
  803. // This is a custom component containing a combo box, which we're going to put inside
  804. // our table's "rating" column.
  805. class RatingColumnCustomComponent : public Component
  806. {
  807. public:
  808. RatingColumnCustomComponent (TableDemoComponent& td) : owner (td)
  809. {
  810. // just put a combo box inside this component
  811. addAndMakeVisible (comboBox);
  812. comboBox.addItem ("fab", 1);
  813. comboBox.addItem ("groovy", 2);
  814. comboBox.addItem ("hep", 3);
  815. comboBox.addItem ("mad for it", 4);
  816. comboBox.addItem ("neat", 5);
  817. comboBox.addItem ("swingin", 6);
  818. comboBox.addItem ("wild", 7);
  819. comboBox.onChange = [this] { owner.setRating (row, comboBox.getSelectedId()); };
  820. comboBox.setWantsKeyboardFocus (false);
  821. }
  822. void resized() override
  823. {
  824. comboBox.setBoundsInset (BorderSize<int> (2));
  825. }
  826. // Our demo code will call this when we may need to update our contents
  827. void setRowAndColumn (int newRow, int newColumn)
  828. {
  829. row = newRow;
  830. columnId = newColumn;
  831. comboBox.setSelectedId (owner.getRating (row), dontSendNotification);
  832. }
  833. private:
  834. TableDemoComponent& owner;
  835. ComboBox comboBox;
  836. int row, columnId;
  837. };
  838. //==============================================================================
  839. // A comparator used to sort our data when the user clicks a column header
  840. class DemoDataSorter
  841. {
  842. public:
  843. DemoDataSorter (const String& attributeToSortBy, bool forwards)
  844. : attributeToSort (attributeToSortBy),
  845. direction (forwards ? 1 : -1)
  846. {
  847. }
  848. int compareElements (XmlElement* first, XmlElement* second) const
  849. {
  850. auto result = first->getStringAttribute (attributeToSort)
  851. .compareNatural (second->getStringAttribute (attributeToSort));
  852. if (result == 0)
  853. result = first->getStringAttribute ("ID")
  854. .compareNatural (second->getStringAttribute ("ID"));
  855. return direction * result;
  856. }
  857. private:
  858. String attributeToSort;
  859. int direction;
  860. };
  861. //==============================================================================
  862. // this loads the embedded database XML file into memory
  863. void loadData()
  864. {
  865. demoData.reset (XmlDocument::parse (loadEntireAssetIntoString ("demo table data.xml")));
  866. dataList = demoData->getChildByName ("DATA");
  867. columnList = demoData->getChildByName ("COLUMNS");
  868. numRows = dataList->getNumChildElements();
  869. }
  870. // (a utility method to search our XML for the attribute that matches a column ID)
  871. String getAttributeNameForColumnId (const int columnId) const
  872. {
  873. forEachXmlChildElement (*columnList, columnXml)
  874. {
  875. if (columnXml->getIntAttribute ("columnId") == columnId)
  876. return columnXml->getStringAttribute ("name");
  877. }
  878. return {};
  879. }
  880. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TableDemoComponent)
  881. };
  882. //==============================================================================
  883. class DragAndDropDemo : public Component,
  884. public DragAndDropContainer
  885. {
  886. public:
  887. DragAndDropDemo()
  888. {
  889. setName ("Drag-and-Drop");
  890. sourceListBox.setModel (&sourceModel);
  891. sourceListBox.setMultipleSelectionEnabled (true);
  892. addAndMakeVisible (sourceListBox);
  893. addAndMakeVisible (target);
  894. }
  895. void resized() override
  896. {
  897. auto r = getLocalBounds().reduced (8);
  898. sourceListBox.setBounds (r.withSize (250, 180));
  899. target .setBounds (r.removeFromBottom (150).removeFromRight (250));
  900. }
  901. private:
  902. //==============================================================================
  903. struct SourceItemListboxContents : public ListBoxModel
  904. {
  905. // The following methods implement the necessary virtual functions from ListBoxModel,
  906. // telling the listbox how many rows there are, painting them, etc.
  907. int getNumRows() override
  908. {
  909. return 30;
  910. }
  911. void paintListBoxItem (int rowNumber, Graphics& g,
  912. int width, int height, bool rowIsSelected) override
  913. {
  914. if (rowIsSelected)
  915. g.fillAll (Colours::lightblue);
  916. g.setColour (LookAndFeel::getDefaultLookAndFeel().findColour (Label::textColourId));
  917. g.setFont (height * 0.7f);
  918. g.drawText ("Draggable Thing #" + String (rowNumber + 1),
  919. 5, 0, width, height,
  920. Justification::centredLeft, true);
  921. }
  922. var getDragSourceDescription (const SparseSet<int>& selectedRows) override
  923. {
  924. // for our drag description, we'll just make a comma-separated list of the selected row
  925. // numbers - this will be picked up by the drag target and displayed in its box.
  926. StringArray rows;
  927. for (int i = 0; i < selectedRows.size(); ++i)
  928. rows.add (String (selectedRows[i] + 1));
  929. return rows.joinIntoString (", ");
  930. }
  931. };
  932. //==============================================================================
  933. // and this is a component that can have things dropped onto it..
  934. class DragAndDropDemoTarget : public Component,
  935. public DragAndDropTarget,
  936. public FileDragAndDropTarget,
  937. public TextDragAndDropTarget
  938. {
  939. public:
  940. DragAndDropDemoTarget() {}
  941. void paint (Graphics& g) override
  942. {
  943. g.fillAll (Colours::green.withAlpha (0.2f));
  944. // draw a red line around the comp if the user's currently dragging something over it..
  945. if (somethingIsBeingDraggedOver)
  946. {
  947. g.setColour (Colours::red);
  948. g.drawRect (getLocalBounds(), 3);
  949. }
  950. g.setColour (getLookAndFeel().findColour (Label::textColourId));
  951. g.setFont (14.0f);
  952. g.drawFittedText (message, getLocalBounds().reduced (10, 0), Justification::centred, 4);
  953. }
  954. //==============================================================================
  955. // These methods implement the DragAndDropTarget interface, and allow our component
  956. // to accept drag-and-drop of objects from other JUCE components..
  957. bool isInterestedInDragSource (const SourceDetails& /*dragSourceDetails*/) override
  958. {
  959. // normally you'd check the sourceDescription value to see if it's the
  960. // sort of object that you're interested in before returning true, but for
  961. // the demo, we'll say yes to anything..
  962. return true;
  963. }
  964. void itemDragEnter (const SourceDetails& /*dragSourceDetails*/) override
  965. {
  966. somethingIsBeingDraggedOver = true;
  967. repaint();
  968. }
  969. void itemDragMove (const SourceDetails& /*dragSourceDetails*/) override
  970. {
  971. }
  972. void itemDragExit (const SourceDetails& /*dragSourceDetails*/) override
  973. {
  974. somethingIsBeingDraggedOver = false;
  975. repaint();
  976. }
  977. void itemDropped (const SourceDetails& dragSourceDetails) override
  978. {
  979. message = "Items dropped: " + dragSourceDetails.description.toString();
  980. somethingIsBeingDraggedOver = false;
  981. repaint();
  982. }
  983. //==============================================================================
  984. // These methods implement the FileDragAndDropTarget interface, and allow our component
  985. // to accept drag-and-drop of files..
  986. bool isInterestedInFileDrag (const StringArray& /*files*/) override
  987. {
  988. // normally you'd check these files to see if they're something that you're
  989. // interested in before returning true, but for the demo, we'll say yes to anything..
  990. return true;
  991. }
  992. void fileDragEnter (const StringArray& /*files*/, int /*x*/, int /*y*/) override
  993. {
  994. somethingIsBeingDraggedOver = true;
  995. repaint();
  996. }
  997. void fileDragMove (const StringArray& /*files*/, int /*x*/, int /*y*/) override
  998. {
  999. }
  1000. void fileDragExit (const StringArray& /*files*/) override
  1001. {
  1002. somethingIsBeingDraggedOver = false;
  1003. repaint();
  1004. }
  1005. void filesDropped (const StringArray& files, int /*x*/, int /*y*/) override
  1006. {
  1007. message = "Files dropped: " + files.joinIntoString ("\n");
  1008. somethingIsBeingDraggedOver = false;
  1009. repaint();
  1010. }
  1011. //==============================================================================
  1012. // These methods implement the TextDragAndDropTarget interface, and allow our component
  1013. // to accept drag-and-drop of text..
  1014. bool isInterestedInTextDrag (const String& /*text*/) override
  1015. {
  1016. return true;
  1017. }
  1018. void textDragEnter (const String& /*text*/, int /*x*/, int /*y*/) override
  1019. {
  1020. somethingIsBeingDraggedOver = true;
  1021. repaint();
  1022. }
  1023. void textDragMove (const String& /*text*/, int /*x*/, int /*y*/) override
  1024. {
  1025. }
  1026. void textDragExit (const String& /*text*/) override
  1027. {
  1028. somethingIsBeingDraggedOver = false;
  1029. repaint();
  1030. }
  1031. void textDropped (const String& text, int /*x*/, int /*y*/) override
  1032. {
  1033. message = "Text dropped:\n" + text;
  1034. somethingIsBeingDraggedOver = false;
  1035. repaint();
  1036. }
  1037. private:
  1038. String message { "Drag-and-drop some rows from the top-left box onto this component!\n\n"
  1039. "You can also drag-and-drop files and text from other apps"};
  1040. bool somethingIsBeingDraggedOver = false;
  1041. };
  1042. //==============================================================================
  1043. ListBox sourceListBox { "D+D source", nullptr };
  1044. SourceItemListboxContents sourceModel;
  1045. DragAndDropDemoTarget target;
  1046. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DragAndDropDemo)
  1047. };
  1048. //==============================================================================
  1049. struct DemoTabbedComponent : public TabbedComponent
  1050. {
  1051. DemoTabbedComponent()
  1052. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  1053. {
  1054. auto colour = findColour (ResizableWindow::backgroundColourId);
  1055. addTab ("Buttons", colour, new ButtonsPage(), true);
  1056. addTab ("Sliders", colour, new SlidersPage(), true);
  1057. addTab ("Toolbars", colour, new ToolbarDemoComp(), true);
  1058. addTab ("Misc", colour, new MiscPage(), true);
  1059. addTab ("Tables", colour, new TableDemoComponent(), true);
  1060. addTab ("Drag & Drop", colour, new DragAndDropDemo(), true);
  1061. getTabbedButtonBar().getTabButton (5)->setExtraComponent (new CustomTabButton(), TabBarButton::afterText);
  1062. }
  1063. // This is a small star button that is put inside one of the tabs. You can
  1064. // use this technique to create things like "close tab" buttons, etc.
  1065. class CustomTabButton : public Component
  1066. {
  1067. public:
  1068. CustomTabButton()
  1069. {
  1070. setSize (20, 20);
  1071. }
  1072. void paint (Graphics& g) override
  1073. {
  1074. Path star;
  1075. star.addStar ({}, 7, 1.0f, 2.0f);
  1076. g.setColour (Colours::green);
  1077. g.fillPath (star, star.getTransformToScaleToFit (getLocalBounds().reduced (2).toFloat(), true));
  1078. }
  1079. void mouseDown (const MouseEvent&) override
  1080. {
  1081. showBubbleMessage (*this,
  1082. "This is a custom tab component\n"
  1083. "\n"
  1084. "You can use these to implement things like close-buttons "
  1085. "or status displays for your tabs.",
  1086. bubbleMessage);
  1087. }
  1088. private:
  1089. std::unique_ptr<BubbleMessageComponent> bubbleMessage;
  1090. };
  1091. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DemoTabbedComponent)
  1092. };
  1093. //==============================================================================
  1094. struct WidgetsDemo : public Component
  1095. {
  1096. WidgetsDemo()
  1097. {
  1098. setOpaque (true);
  1099. addAndMakeVisible (tabs);
  1100. setSize (700, 500);
  1101. }
  1102. void paint (Graphics& g) override
  1103. {
  1104. g.fillAll (Colours::lightgrey);
  1105. }
  1106. void resized() override
  1107. {
  1108. tabs.setBounds (getLocalBounds().reduced (4));
  1109. }
  1110. DemoTabbedComponent tabs;
  1111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WidgetsDemo)
  1112. };