Skip to content

Commit 4096103

Browse files
committed
doxygen
1 parent abf72e3 commit 4096103

File tree

3 files changed

+98
-16
lines changed

3 files changed

+98
-16
lines changed

config/rel.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include $(config_dir)base/base.mk
22

3-
# TODO: compilation with -O3 currently fails with unjjustified "maybe used uninitialized" error
3+
# TODO: compilation with -O3 currently fails with unjustified "maybe used uninitialized" error
44
# when building with "g++ (Debian 12.2.0-14) 12.2.0",
55
# have't tried it with clang++. Need to restore -O3 when GCC is fixed.
66
this_cxxflags += -O1

src/ruis/widget/group/tree_view.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ void tree_view::set_provider(std::shared_ptr<provider> item_provider)
8888
// is a private base of tree_view::provider, so not possible
8989
// to use std::static_pointer_cast() because it does not see the
9090
// private base class
91-
std::shared_ptr<list_provider>(item_provider, item_provider.get())
91+
std::shared_ptr<list_provider>(
92+
item_provider, //
93+
item_provider.get()
94+
)
9295
);
9396
}
9497

@@ -386,7 +389,7 @@ utki::shared_ref<widget> tree_view::provider::get_widget(size_t index)
386389
}
387390

388391
if (is_collapsed) {
389-
this->uncollapse(utki::make_span(path));
392+
this->expand(utki::make_span(path));
390393
} else {
391394
this->collapse(utki::make_span(path));
392395
}
@@ -423,7 +426,7 @@ utki::shared_ref<widget> tree_view::provider::get_widget(
423426
widget_list prefix_widgets
424427
)
425428
{
426-
prefix_widgets.push_back(this->get_widget(index, is_collapsed));
429+
prefix_widgets.emplace_back(this->get_widget(index, is_collapsed));
427430

428431
return make::row(
429432
this->context, //
@@ -524,10 +527,9 @@ void tree_view::provider::set_children(decltype(iter) i, size_t num_children)
524527
i->value.subtree_size = num_children;
525528
}
526529

527-
void tree_view::provider::uncollapse(utki::span<const size_t> index)
530+
void tree_view::provider::expand(utki::span<const size_t> index)
528531
{
529532
auto num_children = this->count(index);
530-
// TRACE(<< "tree_view::provider::uncollapse(): s = " << s << std::endl)
531533
if (num_children == 0) {
532534
return;
533535
}

src/ruis/widget/group/tree_view.hpp

Lines changed: 90 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class tree_view :
5858

5959
~tree_view() override = default;
6060

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+
*/
6166
// NOLINTNEXTLINE(bugprone-incorrect-enable-shared-from-this, "std::shared_from_this is public via utki::shared")
6267
class provider :
6368
public virtual utki::shared, //
@@ -92,45 +97,95 @@ class tree_view :
9297
void set_children(decltype(iter) i, size_t num_children);
9398

9499
public:
100+
/**
101+
* @brief Get stored ruis context.
102+
* @return The stored ruis context.
103+
*/
95104
const utki::shared_ref<ruis::context>& get_context() noexcept
96105
{
97106
return this->context;
98107
}
99108

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+
*/
100113
provider(utki::shared_ref<ruis::context> context) :
101114
list_provider(std::move(context))
102115
{}
103116

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+
*/
104126
virtual utki::shared_ref<widget> get_widget(
105127
utki::span<const size_t> index, //
106128
bool is_collapsed,
107129
widget_list prefix_widgets
108130
);
109131

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+
*/
110139
virtual utki::shared_ref<widget> get_widget(
111140
utki::span<const size_t> index, //
112-
bool is_collapsed
141+
bool is_collapsed // TODO: is this argument needed?
113142
) = 0;
114143

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+
*/
115151
virtual void recycle(
116152
utki::span<const size_t> index, //
117153
const utki::shared_ref<widget>& w
118154
)
119155
{}
120156

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+
*/
121163
virtual size_t count(utki::span<const size_t> index) const noexcept = 0;
122164

123165
/**
124166
* @brief Reload callback.
125-
* Called from owner tree_view's on_reload().
167+
* Called by owner tree_view's on_reload().
126168
*/
127169
void on_reload() override {}
128170

129-
void uncollapse(utki::span<const size_t> index);
171+
void expand(utki::span<const size_t> index);
130172
void collapse(utki::span<const size_t> index);
131173

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+
*/
132179
void notify_model_change();
133180

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+
*/
134189
void notify_item_change();
135190

136191
/**
@@ -145,45 +200,70 @@ class tree_view :
145200
* to an item before which a new item has been added.
146201
*/
147202
void notify_item_add(utki::span<const size_t> index);
148-
149-
private:
150203
};
151204

152-
public:
153205
/**
154206
* @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.
156208
*/
157209
std::function<void(tree_view&)> scroll_change_handler;
158210

211+
/**
212+
* @brief Set items provider.
213+
* @param provider - items provider.
214+
*/
159215
void set_provider(std::shared_ptr<provider> provider = nullptr);
160216

217+
/**
218+
* @brief Set vertical scroll position by factor.
219+
* @param factor - new scroll position specified by factor from [0:1].
220+
*/
161221
void set_vertical_scroll_factor(real factor)
162222
{
163223
this->item_list.get().set_scroll_factor(factor);
164224
}
165225

226+
/**
227+
* @brief Set horizontal scroll position by factor.
228+
* @param factor - new scroll position specified by factor from [0:1].
229+
*/
166230
void set_horizontal_scroll_factor(real factor)
167231
{
168232
this->set_scroll_factor(vector2(factor, 0));
169233
}
170234

235+
/**
236+
* @brief Get scroll position.
237+
* @return Vector of (horizontal scroll factor, vertical scroll factor).
238+
*/
171239
vector2 get_scroll_factor() const
172240
{
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+
);
174245
}
175246

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+
*/
176253
vector2 get_scroll_band() const noexcept
177254
{
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+
);
179259
}
180260

181261
private:
182262
void notify_view_change();
183263
};
184264

185265
namespace make {
186-
inline utki::shared_ref<tree_view> tree_view(
266+
inline utki::shared_ref<ruis::tree_view> tree_view(
187267
utki::shared_ref<ruis::context> context, //
188268
ruis::tree_view::all_parameters params
189269
)

0 commit comments

Comments
 (0)