Browse Source

Fixed a crash when performing layout on an empty Grid using auto flow and added a few Margin convenience constructors

tags/2021-05-28
hogliux 8 years ago
parent
commit
88c734d28d
3 changed files with 17 additions and 4 deletions
  1. +9
    -4
      modules/juce_gui_basics/layout/juce_Grid.cpp
  2. +6
    -0
      modules/juce_gui_basics/layout/juce_GridItem.cpp
  3. +2
    -0
      modules/juce_gui_basics/layout/juce_GridItem.h

+ 9
- 4
modules/juce_gui_basics/layout/juce_Grid.cpp View File

@@ -310,8 +310,9 @@ struct Grid::PlacementHelpers
for (const auto& areaString : areasStrings)
strings.add (juce::StringArray::fromTokens (areaString, false));
for (auto s : strings)
jassert (s.size() == strings[0].size()); // all rows must have the same number of columns
if (strings.size() > 0)
for (auto s : strings)
jassert (s.size() == strings[0].size()); // all rows must have the same number of columns
return strings;
}
@@ -629,8 +630,12 @@ struct Grid::AutoPlacement
int getHighestCrossDimension() const
{
return std::max (getCrossDimension ({ occupiedCells.crbegin()->column, occupiedCells.crbegin()->row }),
highestCrossDimension);
Cell cell { 1, 1 };
if (occupiedCells.size() > 0)
cell = { occupiedCells.crbegin()->column, occupiedCells.crbegin()->row };
return std::max (getCrossDimension (cell), highestCrossDimension);
}
Cell advance (Cell cell) const


+ 6
- 0
modules/juce_gui_basics/layout/juce_GridItem.cpp View File

@@ -61,9 +61,15 @@ GridItem::Property::Property (Span spanToUse) noexcept
GridItem::Margin::Margin() noexcept : left(), right(), top(), bottom()
{}
GridItem::Margin::Margin (int v) noexcept : GridItem::Margin::Margin (static_cast<float> (v))
{}
GridItem::Margin::Margin (float v) noexcept : left (v), right (v), top (v), bottom (v)
{}
GridItem::Margin::Margin (float t, float r, float b, float l) noexcept : left (l), right (r), top (t), bottom (b)
{}
//==============================================================================
GridItem::GridItem() noexcept {}
GridItem::~GridItem() noexcept {}


+ 2
- 0
modules/juce_gui_basics/layout/juce_GridItem.h View File

@@ -160,7 +160,9 @@ public:
struct Margin
{
Margin() noexcept;
Margin (int size) noexcept;
Margin (float size) noexcept;
Margin (float top, float right, float bottom, float left) noexcept; /**< Creates a margin with these sizes. */
float left;
float right;


Loading…
Cancel
Save