diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-03-09 14:54:27 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-03-09 14:54:27 +0100 |
commit | 6a1d23cf994844a39e5a1860c97276780903fb34 (patch) | |
tree | 77dd2d78ae38e3558f5f0ffde59ceab3b554f7b0 /plugingui/listbox.cc | |
parent | b3541d31093fe9f4ccd77303b6b375acb3127ac6 (diff) |
Implement somewhat functional arrow-key navigation in listbox widget.
Diffstat (limited to 'plugingui/listbox.cc')
-rw-r--r-- | plugingui/listbox.cc | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/plugingui/listbox.cc b/plugingui/listbox.cc index f917368..3dec8bc 100644 --- a/plugingui/listbox.cc +++ b/plugingui/listbox.cc @@ -134,9 +134,58 @@ void GUI::ListBox::scrollEvent(ScrollEvent *e) repaintEvent(NULL); } +void GUI::ListBox::keyEvent(GUI::KeyEvent *e) +{ + // printf("!\n"); + + if(e->direction == -1) { + switch(e->keycode) { + case GUI::KeyEvent::KEY_UP: + { + std::map<std::string, std::string>::reverse_iterator i = items.rbegin(); + while(i != items.rend()) { + if(i->second == selected) break; + i++; + } + i++; + scroll_offset--; + if(scroll_offset < 0) scroll_offset = 0; + selected = i->second; + } + break; + case GUI::KeyEvent::KEY_DOWN: + { + std::map<std::string, std::string>::iterator i = items.begin(); + while(i != items.end()) { + if(i->second == selected) break; + i++; + } + i++; + scroll_offset++; + if(scroll_offset > (items.size() - 1)) + scroll_offset = (items.size() - 1); + selected = i->second; + } + break; + case GUI::KeyEvent::KEY_HOME: + selected = items.begin()->second; + break; + case GUI::KeyEvent::KEY_END: + selected = items.rbegin()->second; + break; + default: + break; + } + + // printf("sel: %s\n", selected.c_str()); + + repaintEvent(NULL); + } + +} + void GUI::ListBox::buttonEvent(ButtonEvent *e) { - //printf("click %d %d [dc: %d]\n", e->x, e->y, e->doubleclick); if(e->direction == 1) { if(e->x > (width() - btn_size) && e->y < (width() - 1)) { if(e->y > 0 && e->y < btn_size) { @@ -173,7 +222,7 @@ void GUI::ListBox::buttonEvent(ButtonEvent *e) } repaintEvent(NULL); - - if(e->doubleclick && dblclk_handler) dblclk_handler(ptr); } + + if(e->doubleclick && dblclk_handler) dblclk_handler(ptr); } |