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.

123 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../JuceDemoHeader.h"
  20. // these classes are C++11-only
  21. #if JUCE_HAS_CONSTEXPR
  22. struct GridDemo : public Component
  23. {
  24. GridDemo()
  25. {
  26. addGridItemPanel (Colours::aquamarine, "0");
  27. addGridItemPanel (Colours::aquamarine, "0");
  28. addGridItemPanel (Colours::red, "1");
  29. addGridItemPanel (Colours::blue, "2");
  30. addGridItemPanel (Colours::green, "3");
  31. addGridItemPanel (Colours::orange, "4");
  32. addGridItemPanel (Colours::white, "5");
  33. addGridItemPanel (Colours::aquamarine, "6");
  34. addGridItemPanel (Colours::red, "7");
  35. addGridItemPanel (Colours::blue, "8");
  36. addGridItemPanel (Colours::green, "9");
  37. addGridItemPanel (Colours::orange, "10");
  38. addGridItemPanel (Colours::white, "11");
  39. }
  40. void addGridItemPanel (Colour colour, const char* text)
  41. {
  42. addAndMakeVisible (items.add (new GridItemPanel (colour, text)));
  43. }
  44. void paint (Graphics& g) override
  45. {
  46. g.fillAll (Colours::black);
  47. }
  48. void resized() override
  49. {
  50. Grid grid;
  51. grid.rowGap = 20_px;
  52. grid.columnGap = 20_px;
  53. using Track = Grid::TrackInfo;
  54. grid.templateRows = { Track (1_fr), Track (1_fr), Track (1_fr) };
  55. grid.templateColumns = { Track (1_fr),
  56. Track (1_fr),
  57. Track (1_fr) };
  58. grid.autoColumns = Track (1_fr);
  59. grid.autoRows = Track (1_fr);
  60. grid.autoFlow = Grid::AutoFlow::column;
  61. grid.items.addArray ({ GridItem (items[0]).withArea (2, 2, 4, 4),
  62. GridItem (items[1]),
  63. GridItem (items[2]).withArea ({}, 3),
  64. GridItem (items[3]),
  65. GridItem (items[4]).withArea (GridItem::Span (2), {}),
  66. GridItem (items[5]),
  67. GridItem (items[6]),
  68. GridItem (items[7]),
  69. GridItem (items[8])
  70. });
  71. grid.performLayout (getLocalBounds());
  72. }
  73. //==============================================================================
  74. struct GridItemPanel : public Component
  75. {
  76. GridItemPanel (Colour colourToUse, const String& textToUse)
  77. : colour (colourToUse),
  78. text (textToUse)
  79. {}
  80. void paint (Graphics& g) override
  81. {
  82. g.fillAll (colour.withAlpha (0.5f));
  83. g.setColour (Colours::black);
  84. g.drawText (text, getLocalBounds().withSizeKeepingCentre (100, 100), Justification::centred, false);
  85. }
  86. Colour colour;
  87. String text;
  88. };
  89. OwnedArray<GridItemPanel> items;
  90. };
  91. // This static object will register this demo type in a global list of demos..
  92. static JuceDemoType<GridDemo> demo ("10 Components: GridDemo");
  93. #endif // JUCE_HAS_CONSTEXPR