@@ -91,29 +91,29 @@ namespace cycfi::elements
91
91
[](layout_info lhs, layout_info rhs){ return lhs.index < rhs.index ; });
92
92
}
93
93
94
- template <bool IS_X_AXIS , class TILE_ELEMENT >
95
- [[gnu::always_inline]] inline auto compute_limits (basic_context const & ctx, const TILE_ELEMENT &tile) -> view_limits
94
+ template <axis Axis , class TileElement , axis OtherAxis = other(Axis) >
95
+ [[gnu::always_inline]] inline auto compute_limits (basic_context const & ctx, const TileElement &tile) -> view_limits
96
96
{
97
- view_limits limits{{0.0 , 0.0 },
98
- {IS_X_AXIS ? 0.0 : full_extent,
99
- IS_X_AXIS ? full_extent : 0.0 }};
100
- for (std::size_t i = 0 ; i != tile.size (); ++i)
101
- {
102
- auto el = tile.at (i).limits (ctx);
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)
101
+ {
102
+ auto el = tile.at (i).limits (ctx);
103
103
104
- limits.min . coord (IS_X_AXIS) += el.min . coord (IS_X_AXIS) ;
105
- limits.max . coord (IS_X_AXIS) += el.max . coord (IS_X_AXIS) ;
106
- clamp_min (limits.min . coord (! IS_X_AXIS) , el.min . coord (! IS_X_AXIS) );
107
- clamp_max (limits.max . coord (! IS_X_AXIS) , el.max . coord (! IS_X_AXIS) );
108
- }
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
109
110
- clamp_min (limits.max . coord (! IS_X_AXIS) , limits.min . coord (! IS_X_AXIS) );
111
- clamp_max (limits.max . coord (IS_X_AXIS) , full_extent);
112
- return limits;
110
+ clamp_min (limits.max [OtherAxis] , limits.min [OtherAxis] );
111
+ clamp_max (limits.max [Axis] , full_extent);
112
+ return limits;
113
113
}
114
114
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 > &tile_offsets) -> void
115
+ template <axis Axis , class TileElement , axis OtherAxis = other(Axis) >
116
+ [[gnu::always_inline]] inline auto compute_layout (context const & ctx, TileElement &tile, std::vector<float > &tile_offsets) -> void
117
117
{
118
118
auto const sz = tile.size ();
119
119
@@ -124,17 +124,17 @@ namespace cycfi::elements
124
124
{
125
125
auto & elem = tile.at (i);
126
126
auto limits = elem.limits (ctx);
127
- info[i].stretch = elem.stretch (). coord (IS_X_AXIS) ;
128
- info[i].min = limits.min . coord (IS_X_AXIS) ;
129
- info[i].max = limits.max . coord (IS_X_AXIS) ;
130
- info[i].alloc = limits.min . coord (IS_X_AXIS) ;
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
131
info[i].index = i;
132
132
}
133
133
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 );
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
138
// Compute the best fit for all elements
139
139
allocate (my_axis_delta, info);
140
140
@@ -149,21 +149,21 @@ namespace cycfi::elements
149
149
curr += info[i].alloc ;
150
150
151
151
auto & elem = tile.at (i);
152
- auto ebounds = rect (IS_X_AXIS , prev+my_axis_min, other_axis_min, curr+my_axis_min, other_axis_max);
152
+ auto ebounds = make_rect (Axis , prev+my_axis_min, other_axis_min, curr+my_axis_min, other_axis_max);
153
153
154
154
elem.layout (context{ctx, &elem, ebounds});
155
155
}
156
156
}
157
157
158
- template <bool IS_X_AXIS >
158
+ template <axis Axis, axis OtherAxis = other(Axis) >
159
159
[[gnu::always_inline]] inline auto compute_bounds_of (rect const & bounds, std::size_t index, const std::vector<float > &tile_offsets) -> rect
160
160
{
161
161
if (index >= tile_offsets.size ())
162
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} ;
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
167
}
168
168
}
169
169
@@ -172,12 +172,12 @@ namespace cycfi::elements
172
172
// //////////////////////////////////////////////////////////////////////////
173
173
view_limits vtile_element::limits (basic_context const & ctx) const
174
174
{
175
- return compute_limits<false >(ctx, *this );
175
+ return compute_limits<axis::y >(ctx, *this );
176
176
}
177
177
178
178
void vtile_element::layout (context const & ctx)
179
179
{
180
- compute_layout<false >(ctx, *this , _tiles);
180
+ compute_layout<axis::y >(ctx, *this , _tiles);
181
181
}
182
182
183
183
void vtile_element::draw (context const & ctx)
@@ -189,20 +189,20 @@ namespace cycfi::elements
189
189
190
190
rect vtile_element::bounds_of (context const & ctx, std::size_t index) const
191
191
{
192
- return compute_bounds_of<false >(ctx.bounds , index , _tiles);
192
+ return compute_bounds_of<axis::y >(ctx.bounds , index , _tiles);
193
193
}
194
194
195
195
// //////////////////////////////////////////////////////////////////////////
196
196
// Horizontal Tiles
197
197
// //////////////////////////////////////////////////////////////////////////
198
198
view_limits htile_element::limits (basic_context const & ctx) const
199
199
{
200
- return compute_limits<true >(ctx, *this );
200
+ return compute_limits<axis::x >(ctx, *this );
201
201
}
202
202
203
203
void htile_element::layout (context const & ctx)
204
204
{
205
- compute_layout<true >(ctx, *this , _tiles);
205
+ compute_layout<axis::x >(ctx, *this , _tiles);
206
206
}
207
207
208
208
void htile_element::draw (context const & ctx)
@@ -214,6 +214,6 @@ namespace cycfi::elements
214
214
215
215
rect htile_element::bounds_of (context const & ctx, std::size_t index) const
216
216
{
217
- return compute_bounds_of<true >(ctx.bounds , index , _tiles);
217
+ return compute_bounds_of<axis::x >(ctx.bounds , index , _tiles);
218
218
}
219
219
}
0 commit comments