Skip to content

Commit

Permalink
GUI2/Listbox: use an enum for update_visible_area_on_key_event's argu…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
Vultraz committed Aug 25, 2017
1 parent dc008bf commit 058ffd5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/gui/widgets/listbox.cpp
Expand Up @@ -449,13 +449,13 @@ void listbox::child_populate_dirty_list(window& caller, const std::vector<widget
generator_->populate_dirty_list(caller, child_call_stack);
}

void listbox::update_visible_area_on_key_event(const bool key_direction_vertical)
void listbox::update_visible_area_on_key_event(const KEY_SCROLL_DIRECTION direction)
{
const SDL_Rect& visible = content_visible_area();
SDL_Rect rect = generator_->item(generator_->get_selected_item()).get_rectangle();

// When scrolling make sure the new items are visible...
if(key_direction_vertical) {
if(direction == KEY_VERTICAL) {
// ...but leave the horizontal scrollbar position.
rect.x = visible.x;
rect.w = visible.w;
Expand All @@ -477,7 +477,7 @@ void listbox::handle_key_up_arrow(SDL_Keymod modifier, bool& handled)
generator_->handle_key_up_arrow(modifier, handled);

if(handled) {
update_visible_area_on_key_event(true);
update_visible_area_on_key_event(KEY_VERTICAL);
} else {
// Inherited.
scrollbar_container::handle_key_up_arrow(modifier, handled);
Expand All @@ -491,7 +491,7 @@ void listbox::handle_key_down_arrow(SDL_Keymod modifier, bool& handled)
generator_->handle_key_down_arrow(modifier, handled);

if(handled) {
update_visible_area_on_key_event(true);
update_visible_area_on_key_event(KEY_VERTICAL);
} else {
// Inherited.
scrollbar_container::handle_key_up_arrow(modifier, handled);
Expand All @@ -506,7 +506,7 @@ void listbox::handle_key_left_arrow(SDL_Keymod modifier, bool& handled)

// Inherited.
if(handled) {
update_visible_area_on_key_event(false);
update_visible_area_on_key_event(KEY_HORIZONTAL);
} else {
scrollbar_container::handle_key_left_arrow(modifier, handled);
}
Expand All @@ -520,7 +520,7 @@ void listbox::handle_key_right_arrow(SDL_Keymod modifier, bool& handled)

// Inherited.
if(handled) {
update_visible_area_on_key_event(false);
update_visible_area_on_key_event(KEY_HORIZONTAL);
} else {
scrollbar_container::handle_key_left_arrow(modifier, handled);
}
Expand Down
4 changes: 3 additions & 1 deletion src/gui/widgets/listbox.hpp
Expand Up @@ -304,8 +304,10 @@ class listbox : public scrollbar_container
void handle_key_right_arrow(SDL_Keymod modifier, bool& handled) override;

private:
enum KEY_SCROLL_DIRECTION { KEY_VERTICAL, KEY_HORIZONTAL };

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

/**
* @todo A listbox must have the following config parameters in the
Expand Down

0 comments on commit 058ffd5

Please sign in to comment.