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.

142 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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: GridDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Responsive layouts using Grid.
  24. dependencies: juce_core, juce_data_structures, juce_events, juce_graphics,
  25. juce_gui_basics
  26. exporters: xcode_mac, vs2022, linux_make, androidstudio, xcode_iphone
  27. moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
  28. type: Component
  29. mainClass: GridDemo
  30. useLocalCopy: 1
  31. END_JUCE_PIP_METADATA
  32. *******************************************************************************/
  33. #pragma once
  34. #include "../Assets/DemoUtilities.h"
  35. //==============================================================================
  36. struct GridDemo final : public Component
  37. {
  38. GridDemo()
  39. {
  40. addGridItemPanel (Colours::aquamarine, "0");
  41. addGridItemPanel (Colours::red, "1");
  42. addGridItemPanel (Colours::blue, "2");
  43. addGridItemPanel (Colours::green, "3");
  44. addGridItemPanel (Colours::orange, "4");
  45. addGridItemPanel (Colours::white, "5");
  46. addGridItemPanel (Colours::aquamarine, "6");
  47. addGridItemPanel (Colours::red, "7");
  48. addGridItemPanel (Colours::blue, "8");
  49. addGridItemPanel (Colours::green, "9");
  50. addGridItemPanel (Colours::orange, "10");
  51. addGridItemPanel (Colours::white, "11");
  52. setSize (750, 750);
  53. }
  54. void addGridItemPanel (Colour colour, const char* text)
  55. {
  56. addAndMakeVisible (items.add (new GridItemPanel (colour, text)));
  57. }
  58. void paint (Graphics& g) override
  59. {
  60. g.fillAll (Colours::black);
  61. }
  62. void resized() override
  63. {
  64. Grid grid;
  65. grid.rowGap = 20_px;
  66. grid.columnGap = 20_px;
  67. using Track = Grid::TrackInfo;
  68. grid.templateRows = { Track (1_fr), Track (1_fr), Track (1_fr) };
  69. grid.templateColumns = { Track (1_fr),
  70. Track (1_fr),
  71. Track (1_fr) };
  72. grid.autoColumns = Track (1_fr);
  73. grid.autoRows = Track (1_fr);
  74. grid.autoFlow = Grid::AutoFlow::column;
  75. grid.items.addArray ({ GridItem (items[0]).withArea (2, 2, 4, 4),
  76. GridItem (items[1]),
  77. GridItem (items[2]).withArea ({}, 3),
  78. GridItem (items[3]),
  79. GridItem (items[4]).withArea (GridItem::Span (2), {}),
  80. GridItem (items[5]),
  81. GridItem (items[6]),
  82. GridItem (items[7]),
  83. GridItem (items[8]),
  84. GridItem (items[9]),
  85. GridItem (items[10]),
  86. GridItem (items[11])
  87. });
  88. grid.performLayout (getLocalBounds());
  89. }
  90. //==============================================================================
  91. struct GridItemPanel : public Component
  92. {
  93. GridItemPanel (Colour colourToUse, const String& textToUse)
  94. : colour (colourToUse),
  95. text (textToUse)
  96. {}
  97. void paint (Graphics& g) override
  98. {
  99. g.fillAll (colour.withAlpha (0.5f));
  100. g.setColour (Colours::black);
  101. g.drawText (text, getLocalBounds().withSizeKeepingCentre (100, 100), Justification::centred, false);
  102. }
  103. Colour colour;
  104. String text;
  105. };
  106. OwnedArray<GridItemPanel> items;
  107. };