When performing the layout juce::Grid hangs if the height doesn’t allow to put the rows.
Sadly in video below i can’t show the spinning pinwheel.
In my app i need to arrange variable number of components (with different span/size) in a grid.
#include "MainComponent.hpp"
// -----------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------
// MARK: -
MainComponent::MainComponent()
{
for (int i = 0; i < numberOfItems_; ++i) { items_.push_back (std::make_unique<ItemComponent> (i)); }
for (const auto& p : items_) { addChildComponent (*p); }
setSize (600, 400);
}
MainComponent::~MainComponent()
{
}
This file has been truncated. show original
Are your sure your number of rows is always at least 1? Looks like you’re dynamically calculating the number of rows and columns so you probably want to ensure both are always at least 1.
1 Like
{
juce::Array<juce::Grid::TrackInfo> t;
t.insertMultiple (-1, track, n);
return t;
}
juce::Array<juce::Grid::TrackInfo> getRows (const juce::Rectangle<int>& bounds)
{
const int n = bounds.getHeight() / (MainComponent::gap_ + MainComponent::size_);
return getTracks (n, getRowTrack());
}
juce::Array<juce::Grid::TrackInfo> getColumns (const juce::Rectangle<int>& bounds)
{
const int n = bounds.getWidth() / (MainComponent::gap_ + MainComponent::size_);
return getTracks (n, getColumnTrack());
}
This will come out as 0 if the height is less than gap + size.
1 Like
Thanks, i’ll check that.
But i would expected juce::Grid
to handle that edge case properly instead of hanging.
At least an assertion.
In CSS if you don’t specify a grid-template-columns
or grid-template-rows
they’ll each default to auto
. So juce::Grid::templateColumns
and juce::Grid::templateRows
should really be defaulted to { TrackInfo{} };
.
Since it’s not valid to have 0 columns or 0 rows, performLayout
should probably have an assertion if the size of either is 0 - or just silently handle it and default them back to an auto track info.
I get exactly the same problem with rows & columns forced to be at least one.
Note that my components in that example use a span of 2.
}
juce::Array<juce::GridItem> getGridItems (const std::vector<std::unique_ptr<ItemComponent>>& components)
{
juce::Array<juce::GridItem> items;
for (const auto& p : components) {
//
const int size = static_cast<int> (MainComponent::size_ * 1.5);
const juce::GridItem::Span span (2);
p->setVisible (true);
items.add (juce::GridItem (*p).withArea (span, span).withSize (size, size));
//
}
return items;
}
It seems that it bugs with 1 default row and components with span of 2 (or more).
Is auto rows/columns supposed to work in that case?
reuk
June 27, 2022, 9:18am
8
Thanks for reporting, a fix has been added to develop:
committed 05:53PM - 24 Jun 22 UTC
Previously, positioning such an item would hang while trying to find an
appropri… ate position for the item, because no position in the grid was
suitable, and implicit cells in the layout direction would be added
until a viable position was found.
We now ensure that there are enough cells in the cross direction to hold
each of the auto-placement items before trying to position those items.
2 Likes