Skip to content

Commit dbf40d0

Browse files
committed
add highlighted widget option to list_provider
1 parent 479f386 commit dbf40d0

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/ruis/widget/base/list_widget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ list_provider::list_provider(utki::shared_ref<ruis::context> context) :
2727
context(std::move(context))
2828
{}
2929

30+
utki::shared_ref<widget> list_provider::get_highlighted_widget(size_t index)
31+
{
32+
return this->get_widget(index);
33+
}
34+
3035
void list_provider::notify_model_change()
3136
{
3237
if (!this->owner) {

src/ruis/widget/base/list_widget.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ class list_provider
6868
*/
6969
virtual utki::shared_ref<widget> get_widget(size_t index) = 0;
7070

71+
/**
72+
* @brief Get widget for a highlighted item.
73+
* Default implemetation just falls back to calling get_widget().
74+
* @param index - index of the item to provide widget for.
75+
* @return Widget for requested item.
76+
*/
77+
virtual utki::shared_ref<widget> get_highlighted_widget(size_t index);
78+
7179
/**
7280
* @brief Notify about change of items model.
7381
* The user is supposed to invoke this function when items model change.

src/ruis/widget/button/selection_box.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void selection_box::handle_model_change()
5353
return;
5454
}
5555

56-
this->selection_container.push_back(this->get_provider().get_widget(this->get_selection()));
56+
this->selection_container.push_back(this->get_provider().get_highlighted_widget(this->get_selection()));
5757
}
5858

5959
void selection_box::set_selection(size_t i)

tests/touch/src/scroll_area_page.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,30 @@ class theme_selection_provider : public ruis::list_provider
6464

6565
utki::shared_ref<ruis::widget> get_widget(size_t index) override
6666
{
67-
return m::text(this->context, {}, this->items.at(index));
67+
// clang-format off
68+
return m::text(this->context,
69+
{
70+
.color_params{
71+
.color = this->context.get().style().get_color_text_normal()
72+
}
73+
},
74+
this->items.at(index)
75+
);
76+
// clang-format on
77+
}
78+
79+
utki::shared_ref<ruis::widget> get_highlighted_widget(size_t index) override
80+
{
81+
// clang-format off
82+
return m::text(this->context,
83+
{
84+
.color_params{
85+
.color = this->context.get().style().get_color_highlight()
86+
}
87+
},
88+
this->items.at(index)
89+
);
90+
// clang-format on
6891
}
6992
};
7093

0 commit comments

Comments
 (0)