@@ -91,80 +91,80 @@ namespace cycfi::elements
91
91
[](layout_info lhs, layout_info rhs){ return lhs.index < rhs.index ; });
92
92
}
93
93
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)
101
101
{
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 ();
103
119
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;
108
132
}
109
133
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
+ }
168
168
}
169
169
170
170
// //////////////////////////////////////////////////////////////////////////
0 commit comments