Skip to content

Commit

Permalink
GUI2/Listbox: added select_row_at function
Browse files Browse the repository at this point in the history
See header docs for explanation.
  • Loading branch information
Vultraz committed Aug 9, 2017
1 parent 193baf2 commit 6d15eee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/gui/widgets/listbox.cpp
Expand Up @@ -261,6 +261,13 @@ bool listbox::select_row(const unsigned row, const bool select)
return before != generator_->get_selected_item_count();
}

bool listbox::select_row_at(const unsigned row, const bool select)
{
assert(generator_);

return select_row(generator_->get_item_at_ordered(row), select);
}

bool listbox::row_selected(const unsigned row)
{
assert(generator_);
Expand Down Expand Up @@ -636,7 +643,7 @@ void listbox::set_active_sorting_option(const order_pair& sort_by, const bool se
order_by_column(sort_by.first, dynamic_cast<widget&>(wgt));

if(select_first && generator_->get_item_count() > 0) {
select_row(generator_->get_item_at_ordered(0));
select_row_at(0);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/gui/widgets/listbox.hpp
Expand Up @@ -184,6 +184,24 @@ class listbox : public scrollbar_container
*/
bool select_row(const unsigned row, const bool select = true);

/**
* Selects a row at the given position, regardless of sorting order.
*
* When using @ref select_row the relevant row is located by index regardless
* of its actual position in the list, which could differ if the list had been
* sorted. In that case, `select_row(0)` would not select the list's first row
* as displayed.
*
* This function allows row selection based on position. `select_row_at(0)` will
* always select the list's first row, regardless of sorting order.
*
* @param row The row to select.
* @param select Select or deselect the row.
*
* @returns True if the operation succeeded.
*/
bool select_row_at(const unsigned row, const bool select = true);

/**
* Check if a row is selected
* @param row The row to test
Expand Down

0 comments on commit 6d15eee

Please sign in to comment.