From 5d76d943eca9734f7df2dc351871815385c571b3 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 31 Oct 2015 14:44:23 +0100 Subject: Font refactoring. Some rendering optimizations on ScrollBar, LineEdit and ListBoxBasic. --- plugingui/listboxbasic.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'plugingui/listboxbasic.cc') 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 &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); -- cgit v1.2.3