Cache computed row & column shapes in grid_layout
This commit is contained in:
parent
884a7c745b
commit
de352705f4
2 changed files with 15 additions and 11 deletions
|
|
@ -49,6 +49,10 @@ namespace psemek::ui
|
||||||
|
|
||||||
~grid_layout() override;
|
~grid_layout() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::vector<geom::interval<float>> row_shape_;
|
||||||
|
std::vector<geom::interval<float>> column_shape_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
util::array<std::shared_ptr<element>, 2> children_;
|
util::array<std::shared_ptr<element>, 2> children_;
|
||||||
std::vector<element *> children_range_;
|
std::vector<element *> children_range_;
|
||||||
|
|
|
||||||
|
|
@ -228,15 +228,15 @@ namespace psemek::ui
|
||||||
float const row_weight_sum = std::accumulate(row_weight_.begin(), row_weight_.end(), 0.f);
|
float const row_weight_sum = std::accumulate(row_weight_.begin(), row_weight_.end(), 0.f);
|
||||||
float const column_weight_sum = std::accumulate(column_weight_.begin(), column_weight_.end(), 0.f);
|
float const column_weight_sum = std::accumulate(column_weight_.begin(), column_weight_.end(), 0.f);
|
||||||
|
|
||||||
std::vector<geom::interval<float>> row_shape(row_count());
|
row_shape_.resize(row_count());
|
||||||
std::vector<geom::interval<float>> column_shape(column_count());
|
column_shape_.resize(column_count());
|
||||||
|
|
||||||
// First, allocate minimized rows
|
// First, allocate minimized rows
|
||||||
for (std::size_t i = 0; i < row_count(); ++i)
|
for (std::size_t i = 0; i < row_count(); ++i)
|
||||||
{
|
{
|
||||||
if (row_weight_[i] == 0.f)
|
if (row_weight_[i] == 0.f)
|
||||||
{
|
{
|
||||||
row_shape[i] = {0.f, row_size[i].min};
|
row_shape_[i] = {0.f, row_size[i].min};
|
||||||
available_height -= row_size[i].min;
|
available_height -= row_size[i].min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -250,16 +250,16 @@ namespace psemek::ui
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float const row_height = available_height * row_weight_[i] / row_weight_sum;
|
float const row_height = available_height * row_weight_[i] / row_weight_sum;
|
||||||
row_shape[i] = {0.f, row_height};
|
row_shape_[i] = {0.f, row_height};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, move rows one after another
|
// Finally, move rows one after another
|
||||||
for (std::size_t i = 0; i < row_count(); ++i)
|
for (std::size_t i = 0; i < row_count(); ++i)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
row_shape[i] += bbox[1].min + (outer_margin_ ? margin : 0.f);
|
row_shape_[i] += bbox[1].min + (outer_margin_ ? margin : 0.f);
|
||||||
else
|
else
|
||||||
row_shape[i] += row_shape[i - 1].max + margin;
|
row_shape_[i] += row_shape_[i - 1].max + margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, allocate minimized columns
|
// First, allocate minimized columns
|
||||||
|
|
@ -267,7 +267,7 @@ namespace psemek::ui
|
||||||
{
|
{
|
||||||
if (column_weight_[i] == 0.f)
|
if (column_weight_[i] == 0.f)
|
||||||
{
|
{
|
||||||
column_shape[i] = {0.f, column_size[i].min};
|
column_shape_[i] = {0.f, column_size[i].min};
|
||||||
available_width -= column_size[i].min;
|
available_width -= column_size[i].min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -281,16 +281,16 @@ namespace psemek::ui
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float const column_width = available_width * column_weight_[i] / column_weight_sum;
|
float const column_width = available_width * column_weight_[i] / column_weight_sum;
|
||||||
column_shape[i] = {0.f, column_width};
|
column_shape_[i] = {0.f, column_width};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, move rows one after another
|
// Finally, move rows one after another
|
||||||
for (std::size_t i = 0; i < column_count(); ++i)
|
for (std::size_t i = 0; i < column_count(); ++i)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
column_shape[i] += bbox[0].min + (outer_margin_ ? margin : 0.f);
|
column_shape_[i] += bbox[0].min + (outer_margin_ ? margin : 0.f);
|
||||||
else
|
else
|
||||||
column_shape[i] += column_shape[i - 1].max + margin;
|
column_shape_[i] += column_shape_[i - 1].max + margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply calculated shapes
|
// Apply calculated shapes
|
||||||
|
|
@ -300,7 +300,7 @@ namespace psemek::ui
|
||||||
{
|
{
|
||||||
if (!get(i, j)) continue;
|
if (!get(i, j)) continue;
|
||||||
|
|
||||||
get(i, j)->reshape({{column_shape[j], row_shape[i]}});
|
get(i, j)->reshape({{column_shape_[j], row_shape_[i]}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue