diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2014-05-03 18:08:46 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-05-03 18:08:46 -0300 |
commit | 4939468df0265e57b26ba240715b75cbe15676c3 (patch) | |
tree | 221fbc2925aaf393f3f58571520b2b593e62058f /Panel.c | |
parent | 7f92c589163cacb8a0cbd881f83cdfe51d7b8a03 (diff) |
Fix crash when scrolling in a filter view with no processes. Closes #76.
Diffstat (limited to 'Panel.c')
-rw-r--r-- | Panel.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -234,7 +234,9 @@ int Panel_size(Panel* this) { void Panel_setSelected(Panel* this, int selected) { assert (this != NULL); - selected = MAX(0, MIN(Vector_size(this->items) - 1, selected)); + selected = MIN(Vector_size(this->items) - 1, selected); + if (selected < 0) + selected = 0; this->selected = selected; if (Panel_eventHandlerFn(this)) { Panel_eventHandler(this, EVENT_SETSELECTED); @@ -260,12 +262,14 @@ void Panel_draw(Panel* this, bool focus) { } if (this->selected >= last) { last = MIN(itemCount, this->selected + 1); - first = MAX(0, last - this->h); + first = last - this->h; this->scrollV = first; this->needsRedraw = true; } - assert(first >= 0); - assert(last <= itemCount); + if (first < 0) + first = 0; + if (last > itemCount) + last = itemCount; int headerLen = RichString_sizeVal(this->header); if (headerLen > 0) { @@ -398,6 +402,8 @@ bool Panel_onKey(Panel* this, int key) { case KEY_NPAGE: this->selected += (this->h - 1); int size = Vector_size(this->items); + if (this->selected < 0) + this->selected = 0; if (this->selected >= size) this->selected = size - 1; this->scrollV += (this->h - 1); |