@@ -113,7 +113,7 @@ namespace cycfi::elements
113
113
}
114
114
115
115
template <bool IS_X_AXIS, class TILE_ELEMENT >
116
- [[gnu::always_inline]] inline auto compute_layout (context const & ctx, TILE_ELEMENT &tile, std::vector<float > &tilePos ) -> void
116
+ [[gnu::always_inline]] inline auto compute_layout (context const & ctx, TILE_ELEMENT &tile, std::vector<float > &tile_offsets ) -> void
117
117
{
118
118
auto const sz = tile.size ();
119
119
@@ -131,43 +131,53 @@ namespace cycfi::elements
131
131
info[i].index = i;
132
132
}
133
133
134
- auto const otherMin = ctx.bounds .axisMin (not IS_X_AXIS);
135
- auto const otherMax = ctx.bounds .axisMax (not IS_X_AXIS);
136
- auto const myMin = ctx.bounds .axisMin (IS_X_AXIS);
137
- auto const myDelta = ctx.bounds .axisDelta (IS_X_AXIS);
134
+ auto const other_axis_min = ctx.bounds .axisMin (not IS_X_AXIS);
135
+ auto const other_axis_max = ctx.bounds .axisMax (not IS_X_AXIS);
136
+ auto const my_axis_min = ctx.bounds .axisMin (IS_X_AXIS);
137
+ auto const my_axis_delta = ctx.bounds .axisDelta (IS_X_AXIS);
138
138
// Compute the best fit for all elements
139
- allocate (myDelta , info);
139
+ allocate (my_axis_delta , info);
140
140
141
141
// Now we have the final layout. We can now layout the individual
142
142
// elements.
143
- tilePos .resize (sz);
143
+ tile_offsets .resize (sz);
144
144
auto curr = 0 .0f ;
145
145
for (std::size_t i = 0 ; i != sz; ++i)
146
146
{
147
- tilePos [i] = curr + info[i].alloc ;
147
+ tile_offsets [i] = curr + info[i].alloc ;
148
148
auto const prev = curr;
149
149
curr += info[i].alloc ;
150
150
151
151
auto & elem = tile.at (i);
152
- auto ebounds = IS_X_AXIS
153
- ? rect{prev+myMin, otherMin, curr+myMin, otherMax}
154
- : rect{otherMin, prev+myMin, otherMax, curr+myMin};
152
+ auto ebounds = rect (IS_X_AXIS, prev+my_axis_min, other_axis_min, curr+my_axis_min, other_axis_max);
153
+
155
154
elem.layout (context{ctx, &elem, ebounds});
156
155
}
157
156
}
157
+
158
+ template <bool IS_X_AXIS>
159
+ [[gnu::always_inline]] 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 = bounds.axisMin (not IS_X_AXIS);
164
+ auto const other_axis_max = bounds.axisMax (not IS_X_AXIS);
165
+ auto const my_axis_min = bounds.axisMin (IS_X_AXIS);
166
+ return rect{IS_X_AXIS, (index ? tile_offsets[index -1 ] : 0 )+my_axis_min, other_axis_min, tile_offsets[index ]+my_axis_min, other_axis_max};
167
+ }
158
168
}
159
169
160
170
// //////////////////////////////////////////////////////////////////////////
161
171
// Vertical Tiles
162
172
// //////////////////////////////////////////////////////////////////////////
163
173
view_limits vtile_element::limits (basic_context const & ctx) const
164
174
{
165
- return compute_limits<false >(ctx, *this );
175
+ return compute_limits<false >(ctx, *this );
166
176
}
167
177
168
178
void vtile_element::layout (context const & ctx)
169
179
{
170
- compute_layout<false >(ctx, *this , _tiles);
180
+ compute_layout<false >(ctx, *this , _tiles);
171
181
}
172
182
173
183
void vtile_element::draw (context const & ctx)
@@ -179,25 +189,20 @@ namespace cycfi::elements
179
189
180
190
rect vtile_element::bounds_of (context const & ctx, std::size_t index) const
181
191
{
182
- if (index >= _tiles.size ())
183
- return {};
184
- auto const left = ctx.bounds .left ;
185
- auto const right = ctx.bounds .right ;
186
- auto const top = ctx.bounds .top ;
187
- return rect{left, (index ? _tiles[index -1 ] : 0 )+top, right, _tiles[index ]+top};
192
+ return compute_bounds_of<false >(ctx.bounds , index , _tiles);
188
193
}
189
194
190
195
// //////////////////////////////////////////////////////////////////////////
191
196
// Horizontal Tiles
192
197
// //////////////////////////////////////////////////////////////////////////
193
198
view_limits htile_element::limits (basic_context const & ctx) const
194
199
{
195
- return compute_limits<true >(ctx, *this );
200
+ return compute_limits<true >(ctx, *this );
196
201
}
197
202
198
203
void htile_element::layout (context const & ctx)
199
204
{
200
- compute_layout<true >(ctx, *this , _tiles);
205
+ compute_layout<true >(ctx, *this , _tiles);
201
206
}
202
207
203
208
void htile_element::draw (context const & ctx)
@@ -209,11 +214,6 @@ namespace cycfi::elements
209
214
210
215
rect htile_element::bounds_of (context const & ctx, std::size_t index) const
211
216
{
212
- if (index >= _tiles.size ())
213
- return {};
214
- auto const top = ctx.bounds .top ;
215
- auto const bottom = ctx.bounds .bottom ;
216
- auto const left = ctx.bounds .left ;
217
- return rect{(index ? _tiles[index -1 ] : 0 )+left, top, _tiles[index ]+left, bottom};
217
+ return compute_bounds_of<true >(ctx.bounds , index , _tiles);
218
218
}
219
219
}
0 commit comments