From b4b95f7b45ecdfd3a18171ebe8d6049ace5e821c Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 20 May 2017 22:43:55 +0200 Subject: [PATCH] Recalculate the horizontal FListBox scroll bar size on lazy conversion --- ChangeLog | 4 +++ src/flistbox.cpp | 76 ++++++++++++++++++++++++++++++------------------ src/flistbox.h | 4 +++ test/listbox.cpp | 2 +- 4 files changed, 56 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4fff985e..f5123f5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-05-20 Markus Gans + * Recalculate the horizontal FListBox scroll bar size + on lazy conversion + 2017-05-19 Markus Gans * FListBox: Import of data from a container via "lazy conversion" during item print diff --git a/src/flistbox.cpp b/src/flistbox.cpp index b9d79328..205f2c65 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -274,37 +274,14 @@ void FListBox::hide() //---------------------------------------------------------------------- void FListBox::insert (FListBoxItem listItem) { - int len, element_count; - - len = int(listItem.text.getLength()); - - if ( listItem.brackets ) - len += 2; - - if ( len > max_line_width ) - { - max_line_width = len; - - if ( len >= getWidth() - nf_offset - 3 ) - { - hbar->setMaximum(max_line_width - getWidth() + nf_offset + 4); - hbar->setPageSize(max_line_width, getWidth() - nf_offset - 4); - hbar->calculateSliderValues(); - - if ( ! hbar->isVisible() ) - hbar->setVisible(); - } - } + int len = int(listItem.text.getLength()); + bool has_brackets = bool(listItem.brackets); + recalculateHorizontalBar(len, has_brackets); data.push_back (listItem); - element_count = int(getCount()); - vbar->setMaximum(element_count - getHeight() + 2); - vbar->setPageSize(element_count, getHeight() - 2); - vbar->calculateSliderValues(); - - if ( ! vbar->isVisible() && element_count >= getHeight() - 1 ) - vbar->setVisible(); + int element_count = int(getCount()); + recalculateVerticalBar(element_count); } //---------------------------------------------------------------------- @@ -1625,14 +1602,22 @@ void FListBox::drawList() for (uInt y=start; y < end; y++) { - setPrintPos (2, 2 + int(y)); bool serach_mark = false; bool lineHasBrackets = hasBrackets(iter); bool isLineSelected = isSelected(iter); bool isCurrentLine = bool(y + uInt(yoffset) + 1 == uInt(current)); if ( conv_type == lazy_convert && iter->getText().isNull() ) + { convertToItem (*iter, source_container, int(y) + yoffset); + int len = int(iter->text.getLength()); + recalculateHorizontalBar(len, lineHasBrackets); + + if ( hbar->isVisible() ) + hbar->redraw(); + } + + setPrintPos (2, 2 + int(y)); if ( isLineSelected ) { @@ -1848,6 +1833,39 @@ void FListBox::drawList() last_current = current; } +//---------------------------------------------------------------------- +void FListBox::recalculateHorizontalBar(int len, bool has_brackets) +{ + if ( has_brackets ) + len += 2; + + if ( len > max_line_width ) + { + max_line_width = len; + + if ( len >= getWidth() - nf_offset - 3 ) + { + hbar->setMaximum(max_line_width - getWidth() + nf_offset + 4); + hbar->setPageSize(max_line_width, getWidth() - nf_offset - 4); + hbar->calculateSliderValues(); + + if ( ! hbar->isVisible() ) + hbar->setVisible(); + } + } +} + +//---------------------------------------------------------------------- +void FListBox::recalculateVerticalBar(int element_count) +{ + vbar->setMaximum (element_count - getHeight() + 2); + vbar->setPageSize (element_count, getHeight() - 2); + vbar->calculateSliderValues(); + + if ( ! vbar->isVisible() && element_count >= getHeight() - 1 ) + vbar->setVisible(); +} + //---------------------------------------------------------------------- void FListBox::processClick() { diff --git a/src/flistbox.h b/src/flistbox.h index 6f15e0a9..be92859b 100644 --- a/src/flistbox.h +++ b/src/flistbox.h @@ -229,6 +229,8 @@ class FListBox : public FWidget void draw(); void drawLabel(); void drawList(); + void recalculateHorizontalBar (int, bool); + void recalculateVerticalBar (int); void processClick(); void processSelect(); void processChanged(); @@ -467,6 +469,8 @@ void FListBox::insert (Container container, LazyConverter convert) if ( size > 0 ) data.resize(size); + + recalculateVerticalBar(int(size)); } //---------------------------------------------------------------------- diff --git a/test/listbox.cpp b/test/listbox.cpp index 0611781f..1c054847 100644 --- a/test/listbox.cpp +++ b/test/listbox.cpp @@ -1,4 +1,4 @@ -// File: ui.cpp +// File: listbox.cpp #include #include