Skip to content

Commit 5818d13

Browse files
author
bjn
committed
Formatting changes
1 parent 2c32407 commit 5818d13

File tree

2 files changed

+72
-72
lines changed

2 files changed

+72
-72
lines changed

lib/include/elements/support/rect.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ namespace cycfi { namespace elements
236236
r.bottom = 0.0;
237237
}
238238

239-
inline constexpr float axis_delta(rect const &r, axis a)
239+
inline constexpr float axis_extent(rect const &r, axis a)
240240
{
241241
return a == axis::x ? r.width() : r.height();
242242
}
@@ -263,7 +263,7 @@ namespace cycfi { namespace elements
263263

264264
inline constexpr auto make_rect(axis a, float this_axis_min, float other_axis_min, float this_axis_max, float other_axis_max) -> rect
265265
{
266-
if(a == axis::x) {
266+
if (a == axis::x) {
267267
return rect(this_axis_min, other_axis_min, this_axis_max, other_axis_max);
268268
}
269269
else {

lib/src/element/tile.cpp

+70-70
Original file line numberDiff line numberDiff line change
@@ -91,80 +91,80 @@ namespace cycfi::elements
9191
[](layout_info lhs, layout_info rhs){ return lhs.index < rhs.index; });
9292
}
9393

94-
template<axis Axis, class TileElement, axis OtherAxis = other(Axis)>
95-
CYCFI_FORCE_INLINE auto compute_limits(basic_context const& ctx, const TileElement &tile) -> view_limits
96-
{
97-
view_limits limits{{0.0, 0.0},
98-
{Axis == axis::x ? 0.0 : full_extent,
99-
Axis == axis::x ? full_extent : 0.0}};
100-
for (std::size_t i = 0; i != tile.size(); ++i)
94+
template <axis Axis, class TileElement, axis OtherAxis = other(Axis)>
95+
CYCFI_FORCE_INLINE auto compute_limits(basic_context const& ctx, const TileElement &tile) -> view_limits
96+
{
97+
view_limits limits{{0.0, 0.0},
98+
{Axis == axis::x ? 0.0 : full_extent,
99+
Axis == axis::x ? full_extent : 0.0}};
100+
for (std::size_t i = 0; i != tile.size(); ++i)
101101
{
102-
auto el = tile.at(i).limits(ctx);
102+
auto el = tile.at(i).limits(ctx);
103+
104+
limits.min[Axis] += el.min[Axis];
105+
limits.max[Axis] += el.max[Axis];
106+
clamp_min(limits.min[OtherAxis], el.min[OtherAxis]);
107+
clamp_max(limits.max[OtherAxis], el.max[OtherAxis]);
108+
}
109+
110+
clamp_min(limits.max[OtherAxis], limits.min[OtherAxis]);
111+
clamp_max(limits.max[Axis], full_extent);
112+
return limits;
113+
}
114+
115+
template <axis Axis, class TileElement, axis OtherAxis = other(Axis)>
116+
CYCFI_FORCE_INLINE auto compute_layout(context const& ctx, TileElement &tile, std::vector<float> &tile_offsets) -> void
117+
{
118+
auto const sz = tile.size();
103119

104-
limits.min[Axis] += el.min[Axis];
105-
limits.max[Axis] += el.max[Axis];
106-
clamp_min(limits.min[OtherAxis], el.min[OtherAxis]);
107-
clamp_max(limits.max[OtherAxis], el.max[OtherAxis]);
120+
// Collect min, max, and stretch information from each element.
121+
// Initially set the allocation sizes of each element to its minimum.
122+
std::vector<layout_info> info(sz);
123+
for (std::size_t i = 0; i != sz; ++i)
124+
{
125+
auto& elem = tile.at(i);
126+
auto limits = elem.limits(ctx);
127+
info[i].stretch = elem.stretch()[Axis];
128+
info[i].min = limits.min[Axis];
129+
info[i].max = limits.max[Axis];
130+
info[i].alloc = limits.min[Axis];
131+
info[i].index = i;
108132
}
109133

110-
clamp_min(limits.max[OtherAxis], limits.min[OtherAxis]);
111-
clamp_max(limits.max[Axis], full_extent);
112-
return limits;
113-
}
114-
115-
template<axis Axis, class TileElement, axis OtherAxis = other(Axis)>
116-
CYCFI_FORCE_INLINE auto compute_layout(context const& ctx, TileElement &tile, std::vector<float> &tile_offsets) -> void
117-
{
118-
auto const sz = tile.size();
119-
120-
// Collect min, max, and stretch information from each element.
121-
// Initially set the allocation sizes of each element to its minimum.
122-
std::vector<layout_info> info(sz);
123-
for (std::size_t i = 0; i != sz; ++i)
124-
{
125-
auto& elem = tile.at(i);
126-
auto limits = elem.limits(ctx);
127-
info[i].stretch = elem.stretch()[Axis];
128-
info[i].min = limits.min[Axis];
129-
info[i].max = limits.max[Axis];
130-
info[i].alloc = limits.min[Axis];
131-
info[i].index = i;
132-
}
133-
134-
auto const other_axis_min = axis_min(ctx.bounds, OtherAxis);
135-
auto const other_axis_max = axis_max(ctx.bounds, OtherAxis);
136-
auto const my_axis_min = axis_min(ctx.bounds, Axis);
137-
auto const my_axis_delta = axis_delta(ctx.bounds, Axis);
138-
// Compute the best fit for all elements
139-
allocate(my_axis_delta, info);
140-
141-
// Now we have the final layout. We can now layout the individual
142-
// elements.
143-
tile_offsets.resize(sz);
144-
auto curr = 0.0f;
145-
for (std::size_t i = 0; i != sz; ++i)
146-
{
147-
tile_offsets[i] = curr + info[i].alloc;
148-
auto const prev = curr;
149-
curr += info[i].alloc;
150-
151-
auto& elem = tile.at(i);
152-
auto ebounds = make_rect(Axis, prev+my_axis_min, other_axis_min, curr+my_axis_min, other_axis_max);
153-
154-
elem.layout(context{ctx, &elem, ebounds});
155-
}
156-
}
157-
158-
template<axis Axis, axis OtherAxis = other(Axis)>
159-
CYCFI_FORCE_INLINE auto compute_bounds_of(rect const& bounds, std::size_t index, const std::vector<float> &tile_offsets) -> rect
160-
{
161-
if (index >= tile_offsets.size())
162-
return {};
163-
auto const other_axis_min = axis_min(bounds, OtherAxis);
164-
auto const other_axis_max = axis_max(bounds, OtherAxis);
165-
auto const my_axis_min = axis_min(bounds, Axis);
166-
return make_rect(Axis, (index? tile_offsets[index-1] : 0)+my_axis_min, other_axis_min, tile_offsets[index]+my_axis_min, other_axis_max);
167-
}
134+
auto const other_axis_min = axis_min(ctx.bounds, OtherAxis);
135+
auto const other_axis_max = axis_max(ctx.bounds, OtherAxis);
136+
auto const my_axis_min = axis_min(ctx.bounds, Axis);
137+
auto const my_axis_extent = axis_extent(ctx.bounds, Axis);
138+
// Compute the best fit for all elements
139+
allocate(my_axis_extent, info);
140+
141+
// Now we have the final layout. We can now layout the individual
142+
// elements.
143+
tile_offsets.resize(sz);
144+
auto curr = 0.0f;
145+
for (std::size_t i = 0; i != sz; ++i)
146+
{
147+
tile_offsets[i] = curr + info[i].alloc;
148+
auto const prev = curr;
149+
curr += info[i].alloc;
150+
151+
auto& elem = tile.at(i);
152+
auto ebounds = make_rect(Axis, prev+my_axis_min, other_axis_min, curr+my_axis_min, other_axis_max);
153+
154+
elem.layout(context{ctx, &elem, ebounds});
155+
}
156+
}
157+
158+
template <axis Axis, axis OtherAxis = other(Axis)>
159+
CYCFI_FORCE_INLINE auto compute_bounds_of(rect const& bounds, std::size_t index, const std::vector<float> &tile_offsets) -> rect
160+
{
161+
if (index >= tile_offsets.size())
162+
return {};
163+
auto const other_axis_min = axis_min(bounds, OtherAxis);
164+
auto const other_axis_max = axis_max(bounds, OtherAxis);
165+
auto const my_axis_min = axis_min(bounds, Axis);
166+
return make_rect(Axis, (index? tile_offsets[index-1] : 0)+my_axis_min, other_axis_min, tile_offsets[index]+my_axis_min, other_axis_max);
167+
}
168168
}
169169

170170
////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)