Skip to content

Commit

Permalink
GUI2/Listbox: removed callback interface
Browse files Browse the repository at this point in the history
Do note the removal of the extra precondition of a valid callback before NOTIFED_MODIFED events
were fired in two cases is probably a bugfix on aaa5e0b.
  • Loading branch information
Vultraz committed Aug 25, 2017
1 parent e58bbd7 commit d7de5a6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 46 deletions.
20 changes: 2 additions & 18 deletions src/gui/widgets/listbox.cpp
Expand Up @@ -69,7 +69,6 @@ listbox::listbox(const implementation::builder_styled_widget& builder,
, generator_(generator_base::build(has_minimum, has_maximum, placement, select))
, is_horizontal_(placement == generator_base::horizontal_list)
, list_builder_(nullptr)
, callback_value_changed_()
, need_layout_(false)
, orders_()
{
Expand Down Expand Up @@ -179,9 +178,7 @@ void listbox::set_row_shown(const unsigned row, const bool shown)
set_is_dirty(true);
}

if(selected_row != get_selected_row() && callback_value_changed_) {
callback_value_changed_(*this);

if(selected_row != get_selected_row()) {
fire(event::NOTIFY_MODIFIED, *this, nullptr);
}
}
Expand Down Expand Up @@ -221,9 +218,7 @@ void listbox::set_row_shown(const boost::dynamic_bitset<>& shown)
set_is_dirty(true);
}

if(selected_row != get_selected_row() && callback_value_changed_) {
callback_value_changed_(*this);

if(selected_row != get_selected_row()) {
fire(event::NOTIFY_MODIFIED, *this, nullptr);
}
}
Expand Down Expand Up @@ -304,13 +299,6 @@ void listbox::list_item_clicked(widget& caller)
generator_->toggle_item(i);
}

if(callback_item_changed_) {
callback_item_changed_(i);
}
if(callback_value_changed_) {
callback_value_changed_(*this);
}

fire(event::NOTIFY_MODIFIED, *this, nullptr);
return;
}
Expand Down Expand Up @@ -473,10 +461,6 @@ void listbox::update_visible_area_on_key_event(const bool key_direction_vertical

show_content_rect(rect);

if(callback_value_changed_) {
callback_value_changed_(*this);
}

fire(event::NOTIFY_MODIFIED, *this, nullptr);
}

Expand Down
29 changes: 1 addition & 28 deletions src/gui/widgets/listbox.hpp
Expand Up @@ -256,17 +256,6 @@ class listbox : public scrollbar_container
const std::vector<widget*>& call_stack) override;

/***** ***** ***** setters / getters for members ***** ****** *****/
void
set_callback_item_change(const std::function<void(size_t)>& callback)
{
callback_item_changed_ = callback;
}

void
set_callback_value_change(const std::function<void(widget&)>& callback)
{
callback_value_changed_ = callback;
}

void set_list_builder(builder_grid_ptr list_builder)
{
Expand Down Expand Up @@ -325,7 +314,7 @@ class listbox : public scrollbar_container
void handle_key_right_arrow(SDL_Keymod modifier, bool& handled) override;

private:
/** Helper to update visible area after a key event. */
/** Helper to update visible area after a key event. */
void update_visible_area_on_key_event(const bool key_direction_vertical);

/**
Expand Down Expand Up @@ -367,22 +356,6 @@ class listbox : public scrollbar_container
/** Contains the builder for the new items. */
builder_grid_const_ptr list_builder_;

/**
* This callback is called when a list item is clicked (toggled).
*
* The function is passed the index of the toggled item.
*/
std::function<void(size_t)> callback_item_changed_;

/**
* This callback is called when the value in the listbox changes.
*
* @todo the implementation of the callback hasn't been tested a lot and
* there might be too many calls. That might happen if an arrow up didn't
* change the selected item.
*/
std::function<void(widget&)> callback_value_changed_;

bool need_layout_;

typedef std::vector<std::pair<selectable_item*, generator_sort_array > > torder_list;
Expand Down

0 comments on commit d7de5a6

Please sign in to comment.