Recalculate the horizontal FListBox scroll bar size on lazy conversion

This commit is contained in:
Markus Gans 2017-05-20 22:43:55 +02:00
parent baea344b3c
commit b4b95f7b45
4 changed files with 56 additions and 30 deletions

View File

@ -1,3 +1,7 @@
2017-05-20 Markus Gans <guru.mail@muenster.de>
* Recalculate the horizontal FListBox scroll bar size
on lazy conversion
2017-05-19 Markus Gans <guru.mail@muenster.de> 2017-05-19 Markus Gans <guru.mail@muenster.de>
* FListBox: Import of data from a container via * FListBox: Import of data from a container via
"lazy conversion" during item print "lazy conversion" during item print

View File

@ -274,37 +274,14 @@ void FListBox::hide()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::insert (FListBoxItem listItem) void FListBox::insert (FListBoxItem listItem)
{ {
int len, element_count; int len = int(listItem.text.getLength());
bool has_brackets = bool(listItem.brackets);
len = int(listItem.text.getLength()); recalculateHorizontalBar(len, has_brackets);
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();
}
}
data.push_back (listItem); data.push_back (listItem);
element_count = int(getCount()); int element_count = int(getCount());
vbar->setMaximum(element_count - getHeight() + 2); recalculateVerticalBar(element_count);
vbar->setPageSize(element_count, getHeight() - 2);
vbar->calculateSliderValues();
if ( ! vbar->isVisible() && element_count >= getHeight() - 1 )
vbar->setVisible();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1625,14 +1602,22 @@ void FListBox::drawList()
for (uInt y=start; y < end; y++) for (uInt y=start; y < end; y++)
{ {
setPrintPos (2, 2 + int(y));
bool serach_mark = false; bool serach_mark = false;
bool lineHasBrackets = hasBrackets(iter); bool lineHasBrackets = hasBrackets(iter);
bool isLineSelected = isSelected(iter); bool isLineSelected = isSelected(iter);
bool isCurrentLine = bool(y + uInt(yoffset) + 1 == uInt(current)); bool isCurrentLine = bool(y + uInt(yoffset) + 1 == uInt(current));
if ( conv_type == lazy_convert && iter->getText().isNull() ) if ( conv_type == lazy_convert && iter->getText().isNull() )
{
convertToItem (*iter, source_container, int(y) + yoffset); 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 ) if ( isLineSelected )
{ {
@ -1848,6 +1833,39 @@ void FListBox::drawList()
last_current = current; 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() void FListBox::processClick()
{ {

View File

@ -229,6 +229,8 @@ class FListBox : public FWidget
void draw(); void draw();
void drawLabel(); void drawLabel();
void drawList(); void drawList();
void recalculateHorizontalBar (int, bool);
void recalculateVerticalBar (int);
void processClick(); void processClick();
void processSelect(); void processSelect();
void processChanged(); void processChanged();
@ -467,6 +469,8 @@ void FListBox::insert (Container container, LazyConverter convert)
if ( size > 0 ) if ( size > 0 )
data.resize(size); data.resize(size);
recalculateVerticalBar(int(size));
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
// File: ui.cpp // File: listbox.cpp
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>