@@ -58,6 +58,11 @@ class tree_view :
58
58
59
59
~tree_view () override = default ;
60
60
61
+ /* *
62
+ * @brief tree_view item provider base class.
63
+ * User subclasses this class to provide tree_view an access to the tree data model
64
+ * and provide a way to represent the data as widgets.
65
+ */
61
66
// NOLINTNEXTLINE(bugprone-incorrect-enable-shared-from-this, "std::shared_from_this is public via utki::shared")
62
67
class provider :
63
68
public virtual utki::shared, //
@@ -92,45 +97,95 @@ class tree_view :
92
97
void set_children (decltype (iter) i, size_t num_children);
93
98
94
99
public:
100
+ /* *
101
+ * @brief Get stored ruis context.
102
+ * @return The stored ruis context.
103
+ */
95
104
const utki::shared_ref<ruis::context>& get_context () noexcept
96
105
{
97
106
return this ->context ;
98
107
}
99
108
109
+ /* *
110
+ * @brief Construct tree_view items provider.
111
+ * @param context - ruis context to store. The context can be obtained using the get_context() member function.
112
+ */
100
113
provider (utki::shared_ref<ruis::context> context) :
101
114
list_provider (std::move(context))
102
115
{}
103
116
117
+ /* *
118
+ * @brief Create item widget.
119
+ * The tree_view will call this function when it needs an item widget for the given index.
120
+ * @param index - index into the data model to create an item widget for.
121
+ * @param is_collapsed - whether the item is collapsed or not.
122
+ * @param prefix_widgets - a list of tree_view specific widgets, i.e. colapse/expande button and path indicators.
123
+ * To be placed inside of a row.
124
+ * @return The item widget.
125
+ */
104
126
virtual utki::shared_ref<widget> get_widget (
105
127
utki::span<const size_t > index, //
106
128
bool is_collapsed,
107
129
widget_list prefix_widgets
108
130
);
109
131
132
+ /* *
133
+ * @brief Create item widget.
134
+ * This function is called by the get_widghet(index, is_collapsed, prefix_widgets) overload.
135
+ * @param index - index into the data model to create an item widget for.
136
+ * @param is_collapsed - whether the item is collapsed or not.
137
+ * @return The item widget.
138
+ */
110
139
virtual utki::shared_ref<widget> get_widget (
111
140
utki::span<const size_t > index, //
112
- bool is_collapsed
141
+ bool is_collapsed // TODO: is this argument needed?
113
142
) = 0;
114
143
144
+ /* *
145
+ * @brief Recycle item widget.
146
+ * The tree_view will call this function when it no longer needs the item widget.
147
+ * This happens when the item widget goes beyond the tree_view bounds due to scrolling.
148
+ * @param index - index into the data model for which the widget is to be recycled.
149
+ * @param w - the widget to be recycled.
150
+ */
115
151
virtual void recycle (
116
152
utki::span<const size_t > index, //
117
153
const utki::shared_ref<widget>& w
118
154
)
119
155
{}
120
156
157
+ /* *
158
+ * @brief Get number of tree node's children.
159
+ * The tree_view will call this function when it needs to know the number of
160
+ * children of a tree node.
161
+ * @param index - index of the tree node to gen number of children for.
162
+ */
121
163
virtual size_t count (utki::span<const size_t > index) const noexcept = 0;
122
164
123
165
/* *
124
166
* @brief Reload callback.
125
- * Called from owner tree_view's on_reload().
167
+ * Called by owner tree_view's on_reload().
126
168
*/
127
169
void on_reload () override {}
128
170
129
- void uncollapse (utki::span<const size_t > index);
171
+ void expand (utki::span<const size_t > index);
130
172
void collapse (utki::span<const size_t > index);
131
173
174
+ /* *
175
+ * @brief Notify about any model change.
176
+ * Calling this function will cause the tree_view to re-create and
177
+ * re-layout it's contents.
178
+ */
132
179
void notify_model_change ();
133
180
181
+ /* *
182
+ * @brief Notify about tree item contents change.
183
+ * Use this function to notify about changes to the tree data which do not involve
184
+ * adding new items or removing items. I.e. when tree topology does not chnage.
185
+ * Calling this function will cause the tree_view to re-create and
186
+ * re-layout it's contents.
187
+ * This operation should be faster than notify_model_change().
188
+ */
134
189
void notify_item_change ();
135
190
136
191
/* *
@@ -145,45 +200,70 @@ class tree_view :
145
200
* to an item before which a new item has been added.
146
201
*/
147
202
void notify_item_add (utki::span<const size_t > index);
148
-
149
- private:
150
203
};
151
204
152
- public:
153
205
/* *
154
206
* @brief Scroll position changed signal.
155
- * Emitted when list's scroll position has changed.
207
+ * Emitted when tree_view's vertical or horizontal scroll position has changed.
156
208
*/
157
209
std::function<void (tree_view&)> scroll_change_handler;
158
210
211
+ /* *
212
+ * @brief Set items provider.
213
+ * @param provider - items provider.
214
+ */
159
215
void set_provider (std::shared_ptr<provider> provider = nullptr );
160
216
217
+ /* *
218
+ * @brief Set vertical scroll position by factor.
219
+ * @param factor - new scroll position specified by factor from [0:1].
220
+ */
161
221
void set_vertical_scroll_factor (real factor)
162
222
{
163
223
this ->item_list .get ().set_scroll_factor (factor);
164
224
}
165
225
226
+ /* *
227
+ * @brief Set horizontal scroll position by factor.
228
+ * @param factor - new scroll position specified by factor from [0:1].
229
+ */
166
230
void set_horizontal_scroll_factor (real factor)
167
231
{
168
232
this ->set_scroll_factor (vector2 (factor, 0 ));
169
233
}
170
234
235
+ /* *
236
+ * @brief Get scroll position.
237
+ * @return Vector of (horizontal scroll factor, vertical scroll factor).
238
+ */
171
239
vector2 get_scroll_factor () const
172
240
{
173
- return vector2 (this ->scroll_area ::get_scroll_factor ().x (), this ->item_list .get ().get_scroll_factor ());
241
+ return vector2 (
242
+ this ->scroll_area ::get_scroll_factor ().x (), //
243
+ this ->item_list .get ().get_scroll_factor ()
244
+ );
174
245
}
175
246
247
+ /* *
248
+ * @brief Get scroll band.
249
+ * Get scroll band size.
250
+ * The scroll band size is a fraction of [0:1] interval.
251
+ * @return Vector of (horizontal scroll band, vertical scroll band).
252
+ */
176
253
vector2 get_scroll_band () const noexcept
177
254
{
178
- return vector2 (this ->scroll_area ::get_visible_area_fraction ().x (), this ->item_list .get ().get_scroll_band ());
255
+ return vector2 (
256
+ this ->scroll_area ::get_visible_area_fraction ().x (), //
257
+ this ->item_list .get ().get_scroll_band ()
258
+ );
179
259
}
180
260
181
261
private:
182
262
void notify_view_change ();
183
263
};
184
264
185
265
namespace make {
186
- inline utki::shared_ref<tree_view> tree_view (
266
+ inline utki::shared_ref<ruis:: tree_view> tree_view (
187
267
utki::shared_ref<ruis::context> context, //
188
268
ruis::tree_view::all_parameters params
189
269
)
0 commit comments