Browse Source

Grid demo formatting

tags/2021-05-28
ed 7 years ago
parent
commit
550b547d73
1 changed files with 91 additions and 91 deletions
  1. +91
    -91
      examples/Demo/Source/Demos/GridDemo.cpp

+ 91
- 91
examples/Demo/Source/Demos/GridDemo.cpp View File

@@ -29,94 +29,94 @@
// these classes are C++11-only
#if JUCE_HAS_CONSTEXPR && JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
struct GridDemo : public Component
{
GridDemo()
{
addGridItemPanel (Colours::aquamarine, "0");
addGridItemPanel (Colours::aquamarine, "0");
addGridItemPanel (Colours::red, "1");
addGridItemPanel (Colours::blue, "2");
addGridItemPanel (Colours::green, "3");
addGridItemPanel (Colours::orange, "4");
addGridItemPanel (Colours::white, "5");
addGridItemPanel (Colours::aquamarine, "6");
addGridItemPanel (Colours::red, "7");
addGridItemPanel (Colours::blue, "8");
addGridItemPanel (Colours::green, "9");
addGridItemPanel (Colours::orange, "10");
addGridItemPanel (Colours::white, "11");
}
void addGridItemPanel (Colour colour, const char* text)
{
addAndMakeVisible (items.add (new GridItemPanel (colour, text)));
}
void paint (Graphics& g) override
{
g.fillAll (Colours::black);
}
void resized() override
{
Grid grid;
grid.rowGap = 20_px;
grid.columnGap = 20_px;
using Track = Grid::TrackInfo;
grid.templateRows = { Track (1_fr), Track (1_fr), Track (1_fr) };
grid.templateColumns = { Track (1_fr),
Track (1_fr),
Track (1_fr) };
grid.autoColumns = Track (1_fr);
grid.autoRows = Track (1_fr);
grid.autoFlow = Grid::AutoFlow::column;
grid.items.addArray ({ GridItem (items[0]).withArea (2, 2, 4, 4),
GridItem (items[1]),
GridItem (items[2]).withArea ({}, 3),
GridItem (items[3]),
GridItem (items[4]).withArea (GridItem::Span (2), {}),
GridItem (items[5]),
GridItem (items[6]),
GridItem (items[7]),
GridItem (items[8])
});
grid.performLayout (getLocalBounds());
}
//==============================================================================
struct GridItemPanel : public Component
{
GridItemPanel (Colour colourToUse, const String& textToUse)
: colour (colourToUse),
text (textToUse)
{}
void paint (Graphics& g) override
{
g.fillAll (colour.withAlpha (0.5f));
g.setColour (Colours::black);
g.drawText (text, getLocalBounds().withSizeKeepingCentre (100, 100), Justification::centred, false);
}
Colour colour;
String text;
};
OwnedArray<GridItemPanel> items;
};
// This static object will register this demo type in a global list of demos..
static JuceDemoType<GridDemo> demo ("10 Components: GridDemo");
#endif // JUCE_HAS_CONSTEXPR
struct GridDemo : public Component
{
GridDemo()
{
addGridItemPanel (Colours::aquamarine, "0");
addGridItemPanel (Colours::aquamarine, "0");
addGridItemPanel (Colours::red, "1");
addGridItemPanel (Colours::blue, "2");
addGridItemPanel (Colours::green, "3");
addGridItemPanel (Colours::orange, "4");
addGridItemPanel (Colours::white, "5");
addGridItemPanel (Colours::aquamarine, "6");
addGridItemPanel (Colours::red, "7");
addGridItemPanel (Colours::blue, "8");
addGridItemPanel (Colours::green, "9");
addGridItemPanel (Colours::orange, "10");
addGridItemPanel (Colours::white, "11");
}
void addGridItemPanel (Colour colour, const char* text)
{
addAndMakeVisible (items.add (new GridItemPanel (colour, text)));
}
void paint (Graphics& g) override
{
g.fillAll (Colours::black);
}
void resized() override
{
Grid grid;
grid.rowGap = 20_px;
grid.columnGap = 20_px;
using Track = Grid::TrackInfo;
grid.templateRows = { Track (1_fr), Track (1_fr), Track (1_fr) };
grid.templateColumns = { Track (1_fr),
Track (1_fr),
Track (1_fr) };
grid.autoColumns = Track (1_fr);
grid.autoRows = Track (1_fr);
grid.autoFlow = Grid::AutoFlow::column;
grid.items.addArray ({ GridItem (items[0]).withArea (2, 2, 4, 4),
GridItem (items[1]),
GridItem (items[2]).withArea ({}, 3),
GridItem (items[3]),
GridItem (items[4]).withArea (GridItem::Span (2), {}),
GridItem (items[5]),
GridItem (items[6]),
GridItem (items[7]),
GridItem (items[8])
});
grid.performLayout (getLocalBounds());
}
//==============================================================================
struct GridItemPanel : public Component
{
GridItemPanel (Colour colourToUse, const String& textToUse)
: colour (colourToUse),
text (textToUse)
{}
void paint (Graphics& g) override
{
g.fillAll (colour.withAlpha (0.5f));
g.setColour (Colours::black);
g.drawText (text, getLocalBounds().withSizeKeepingCentre (100, 100), Justification::centred, false);
}
Colour colour;
String text;
};
OwnedArray<GridItemPanel> items;
};
// This static object will register this demo type in a global list of demos..
static JuceDemoType<GridDemo> demo ("10 Components: GridDemo");
#endif

Loading…
Cancel
Save