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.

125 lines
4.2KB

  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 && JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
  22. struct GridDemo : public Component
  23. {
  24. GridDemo()
  25. {
  26. addGridItemPanel (Colours::aquamarine, "0");
  27. addGridItemPanel (Colours::red, "1");
  28. addGridItemPanel (Colours::blue, "2");
  29. addGridItemPanel (Colours::green, "3");
  30. addGridItemPanel (Colours::orange, "4");
  31. addGridItemPanel (Colours::white, "5");
  32. addGridItemPanel (Colours::aquamarine, "6");
  33. addGridItemPanel (Colours::red, "7");
  34. addGridItemPanel (Colours::blue, "8");
  35. addGridItemPanel (Colours::green, "9");
  36. addGridItemPanel (Colours::orange, "10");
  37. addGridItemPanel (Colours::white, "11");
  38. }
  39. void addGridItemPanel (Colour colour, const char* text)
  40. {
  41. addAndMakeVisible (items.add (new GridItemPanel (colour, text)));
  42. }
  43. void paint (Graphics& g) override
  44. {
  45. g.fillAll (Colours::black);
  46. }
  47. void resized() override
  48. {
  49. Grid grid;
  50. grid.rowGap = 20_px;
  51. grid.columnGap = 20_px;
  52. using Track = Grid::TrackInfo;
  53. grid.templateRows = { Track (1_fr), Track (1_fr), Track (1_fr) };
  54. grid.templateColumns = { Track (1_fr),
  55. Track (1_fr),
  56. Track (1_fr) };
  57. grid.autoColumns = Track (1_fr);
  58. grid.autoRows = Track (1_fr);
  59. grid.autoFlow = Grid::AutoFlow::column;
  60. grid.items.addArray ({ GridItem (items[0]).withArea (2, 2, 4, 4),
  61. GridItem (items[1]),
  62. GridItem (items[2]).withArea ({}, 3),
  63. GridItem (items[3]),
  64. GridItem (items[4]).withArea (GridItem::Span (2), {}),
  65. GridItem (items[5]),
  66. GridItem (items[6]),
  67. GridItem (items[7]),
  68. GridItem (items[8]),
  69. GridItem (items[9]),
  70. GridItem (items[10]),
  71. GridItem (items[11])
  72. });
  73. grid.performLayout (getLocalBounds());
  74. }
  75. //==============================================================================
  76. struct GridItemPanel : public Component
  77. {
  78. GridItemPanel (Colour colourToUse, const String& textToUse)
  79. : colour (colourToUse),
  80. text (textToUse)
  81. {}
  82. void paint (Graphics& g) override
  83. {
  84. g.fillAll (colour.withAlpha (0.5f));
  85. g.setColour (Colours::black);
  86. g.drawText (text, getLocalBounds().withSizeKeepingCentre (100, 100), Justification::centred, false);
  87. }
  88. Colour colour;
  89. String text;
  90. };
  91. OwnedArray<GridItemPanel> items;
  92. };
  93. // This static object will register this demo type in a global list of demos..
  94. static JuceDemoType<GridDemo> demo ("10 Components: GridDemo");
  95. #endif