diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-10-31 14:44:23 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-10-31 14:44:23 +0100 |
commit | 5d76d943eca9734f7df2dc351871815385c571b3 (patch) | |
tree | 6f395e870283b43702e75e320dd53ed316e22db9 /plugingui/listboxbasic.cc | |
parent | bc931baa7a31857b971b9ac6543b2af20cdd1bf1 (diff) |
Font refactoring. Some rendering optimizations on ScrollBar, LineEdit and ListBoxBasic.
Diffstat (limited to 'plugingui/listboxbasic.cc')
-rw-r--r-- | plugingui/listboxbasic.cc | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/plugingui/listboxbasic.cc b/plugingui/listboxbasic.cc index bf75684..fa1601f 100644 --- a/plugingui/listboxbasic.cc +++ b/plugingui/listboxbasic.cc @@ -91,6 +91,7 @@ void ListBoxBasic::addItems(std::vector<ListBoxBasic::Item> &newItems) int numitems = height() / (font.textHeight() + padding); scroll.setRange(numitems); scroll.setMaximum(items.size()); + repaintEvent(nullptr); } void ListBoxBasic::clear() @@ -163,7 +164,7 @@ void ListBoxBasic::repaintEvent(RepaintEvent *e) for(int idx = skip; (idx < (int)items.size()) && (idx < (skip + numitems)); idx++) { - ListBoxBasic::Item *i = &items[idx]; + auto& item = items[idx]; if(idx == selected) { p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 0.5)); @@ -183,7 +184,7 @@ void ListBoxBasic::repaintEvent(RepaintEvent *e) p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); - p.drawText(2, yoffset + font.textHeight(), font, i->name); + p.drawText(2, yoffset + font.textHeight(), font, item.name); yoffset += font.textHeight() + padding; } } @@ -202,12 +203,13 @@ void ListBoxBasic::keyEvent(KeyEvent *e) switch(e->keycode) { case KeyEvent::KeyUp: - marked--; - if(marked < 0) + if(marked == 0) { - marked = 0; + return; } + marked--; + if(marked < scroll.value()) { scroll.setValue(marked); @@ -219,12 +221,13 @@ void ListBoxBasic::keyEvent(KeyEvent *e) // Number of items that can be displayed at a time. int numitems = height() / (font.textHeight() + padding); - marked++; - if(marked > ((int)items.size() - 1)) + if(marked == ((int)items.size() - 1)) { - marked = (int)items.size() - 1; + return; } + marked++; + if(marked > (scroll.value() + numitems - 1)) { scroll.setValue(marked - numitems + 1); |