GUI2/Listbox: remove any_rows_shown

Instead, return the number of rows shown from filter_rows_by. We might re-add any_rows_shown in the future, but for now this covers the intended usecase.
This commit is contained in:
Charles Dang 2024-12-18 02:45:26 -05:00
parent edb4331d56
commit 2be41a4f85
3 changed files with 14 additions and 23 deletions

View file

@ -442,15 +442,14 @@ void unit_recall::post_show()
void unit_recall::filter_text_changed(const std::string& text)
{
auto& list = find_widget<listbox>("recall_list");
list.filter_rows_by([this, match = translation::make_ci_matcher(text)](std::size_t row) {
return match(filter_options_[row]);
});
const std::size_t shown = find_widget<listbox>("recall_list")
.filter_rows_by([this, match = translation::make_ci_matcher(text)](std::size_t row) {
return match(filter_options_[row]);
});
// Disable rename and dismiss buttons if no units are shown
const bool any_shown = list.any_rows_shown();
find_widget<button>("rename").set_active(any_shown);
find_widget<button>("dismiss").set_active(any_shown);
find_widget<button>("rename").set_active(shown > 0);
find_widget<button>("dismiss").set_active(shown > 0);
}
} // namespace dialogs

View file

@ -246,7 +246,7 @@ void listbox::set_row_shown(const boost::dynamic_bitset<>& shown)
}
}
void listbox::filter_rows_by(const std::function<bool(std::size_t)>& filter)
std::size_t listbox::filter_rows_by(const std::function<bool(std::size_t)>& filter)
{
boost::dynamic_bitset<> mask;
mask.resize(get_item_count(), true);
@ -256,6 +256,7 @@ void listbox::filter_rows_by(const std::function<bool(std::size_t)>& filter)
}
set_row_shown(mask);
return mask.count();
}
boost::dynamic_bitset<> listbox::get_rows_shown() const
@ -263,17 +264,6 @@ boost::dynamic_bitset<> listbox::get_rows_shown() const
return generator_->get_items_shown();
}
bool listbox::any_rows_shown() const
{
for(std::size_t i = 0; i < get_item_count(); i++) {
if(generator_->get_item_shown(i)) {
return true;
}
}
return false;
}
const grid* listbox::get_row_grid(const unsigned row) const
{
assert(generator_);

View file

@ -132,8 +132,12 @@ public:
*/
void set_row_shown(const boost::dynamic_bitset<>& shown);
/** Hides all rows for which the given predicate returns false. */
void filter_rows_by(const std::function<bool(std::size_t)>& filter);
/**
* Hides all rows for which the given predicate returns false.
*
* @returns The number of rows now visible.
*/
std::size_t filter_rows_by(const std::function<bool(std::size_t)>& filter);
/**
* Returns a list of visible rows
@ -142,8 +146,6 @@ public:
*/
boost::dynamic_bitset<> get_rows_shown() const;
bool any_rows_shown() const;
/**
* Returns the grid of the wanted row.
*