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.

119 lines
3.9KB

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