Add setCurrentItem() to the FComboBox widget class

This commit is contained in:
Markus Gans 2020-01-09 19:21:16 +01:00
parent 0ea63fa1c8
commit c0b1dc5924
7 changed files with 85 additions and 63 deletions

View File

@ -1,3 +1,7 @@
2020-01-09 Markus Gans <guru.mail@muenster.de>
* The setCurrentItem() method was added to the FComboBox widget class.
Thanks cybin for the sample code
2020-01-03 Markus Gans <guru.mail@muenster.de>
* Illustrations to explain the widget layout

View File

@ -570,13 +570,13 @@
<text
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.88055563px;font-family:FreeSans, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', 'Open Sans', sans-serif;-inkscape-font-specification:'FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458299"
font-size="3.88055611"
x="57.889885"
x="57.5"
y="15.47997"
id="text89-30">
<tspan
style="stroke-width:0.26458299"
y="15.47997"
x="57.889885"
x="57.5"
sodipodi:role="line"
id="tspan4726-3">= FPoint(25,6), FPoint(56,17)</tspan>
</text>
@ -609,13 +609,13 @@
<text
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.88055587px;font-family:FreeSans, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', 'Open Sans', sans-serif;-inkscape-font-specification:'FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458299"
font-size="3.88055611"
x="57.889893"
x="57.5"
y="26.094063"
id="text89-30-4">
<tspan
style="stroke-width:0.26458299"
y="26.094063"
x="57.889893"
x="57.5"
sodipodi:role="line"
id="tspan4726-3-0">= FPoint(25,6), FPoint(56,17)</tspan>
</text>
@ -648,13 +648,13 @@
<text
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.88055587px;font-family:FreeSans, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', 'Open Sans', sans-serif;-inkscape-font-specification:'FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458299"
font-size="3.88055611"
x="57.882675"
x="57.3"
y="118.13409"
id="text89-30-4-0-2">
<tspan
style="stroke-width:0.26458299"
y="118.13409"
x="57.882675"
x="57.3"
sodipodi:role="line"
id="tspan4726-3-0-9-5">= FPoint(25,6), FPoint(58,18)</tspan>
</text>
@ -674,13 +674,13 @@
<text
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.88055587px;font-family:FreeSans, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', 'Open Sans', sans-serif;-inkscape-font-specification:'FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458299"
font-size="3.88055611"
x="57.893173"
x="57.3"
y="128.8925"
id="text89-30-4-0-2-5">
<tspan
style="stroke-width:0.26458299"
y="128.8925"
x="57.893173"
x="57.3"
sodipodi:role="line"
id="tspan4726-3-0-9-5-9">= FPoint(25,6), FPoint(58,18)</tspan>
</text>
@ -700,13 +700,13 @@
<text
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.88055587px;font-family:FreeSans, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', 'Open Sans', sans-serif;-inkscape-font-specification:'FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458299"
font-size="3.88055611"
x="173.40904"
x="173.0"
y="15.480049"
id="text89-30-5">
<tspan
style="stroke-width:0.26458299"
y="15.480049"
x="173.40904"
x="173.0"
sodipodi:role="line"
id="tspan4726-3-4">= FPoint(19,8), FPoint(28,8)</tspan>
</text>
@ -739,13 +739,13 @@
<text
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.88055587px;font-family:FreeSans, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', 'Open Sans', sans-serif;-inkscape-font-specification:'FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458299"
font-size="3.88055611"
x="173.40904"
x="173.0"
y="26.094126"
id="text89-30-4-9">
<tspan
style="stroke-width:0.26458299"
y="26.094126"
x="173.40904"
x="173.0"
sodipodi:role="line"
id="tspan4726-3-0-3">= FPoint(44,15), FPoint(53,15)</tspan>
</text>
@ -778,13 +778,13 @@
<text
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.88055587px;font-family:FreeSans, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', 'Open Sans', sans-serif;-inkscape-font-specification:'FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458299"
font-size="3.88055611"
x="173.40181"
x="173.0"
y="118.13422"
id="text89-30-4-0-2-1">
<tspan
style="stroke-width:0.26458299"
y="118.13422"
x="173.40181"
x="173.0"
sodipodi:role="line"
id="tspan4726-3-0-9-5-0">= FPoint(19,8), FPoint(29,9)</tspan>
</text>
@ -804,13 +804,13 @@
<text
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.88055587px;font-family:FreeSans, Arial, 'Bitstream Vera Sans', 'DejaVu Sans', 'Open Sans', sans-serif;-inkscape-font-specification:'FreeSans, Arial, Bitstream Vera Sans, DejaVu Sans, Open Sans, sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458299"
font-size="3.88055611"
x="173.41237"
x="173.0"
y="128.89259"
id="text89-30-4-0-2-5-1">
<tspan
style="stroke-width:0.26458299"
y="128.89259"
x="173.41237"
x="173.0"
sodipodi:role="line"
id="tspan4726-3-0-9-5-9-0">= FPoint(44,15), FPoint(54,16)</tspan>
</text>

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -250,6 +250,23 @@ bool FComboBox::setEditable (bool enable)
return (is_editable = enable);
}
//----------------------------------------------------------------------
void FComboBox::setCurrentItem (std::size_t index)
{
if ( index > getCount() )
index = getCount();
else if ( index < 1 )
index = 1;
if ( index == list_window.list.currentItem() )
return;
list_window.list.setCurrentItem(index);
input_field = list_window.list.getItem(index).getText();
input_field.redraw();
processChanged();
}
//----------------------------------------------------------------------
void FComboBox::setMaxVisibleItems (std::size_t items)
{
@ -277,8 +294,8 @@ void FComboBox::remove (std::size_t item)
if ( ! list_window.isEmpty() )
{
std::size_t i = list_window.list.currentItem();
input_field = list_window.list.getItem(i).getText();
std::size_t index = list_window.list.currentItem();
input_field = list_window.list.getItem(index).getText();
input_field.redraw();
}
@ -552,15 +569,15 @@ void FComboBox::draw()
//----------------------------------------------------------------------
void FComboBox::onePosUp()
{
std::size_t i = list_window.list.currentItem();
std::size_t index = list_window.list.currentItem();
if ( i > 1 )
i--;
if ( index > 1 )
index--;
else
return;
list_window.list.setCurrentItem(i);
input_field = list_window.list.getItem(i).getText();
list_window.list.setCurrentItem(index);
input_field = list_window.list.getItem(index).getText();
input_field.redraw();
processChanged();
}
@ -568,15 +585,15 @@ void FComboBox::onePosUp()
//----------------------------------------------------------------------
void FComboBox::onePosDown()
{
std::size_t i = list_window.list.currentItem();
std::size_t index = list_window.list.currentItem();
if ( i < list_window.list.getCount() )
i++;
if ( index < getCount() )
index++;
else
return;
list_window.list.setCurrentItem(i);
input_field = list_window.list.getItem(i).getText();
list_window.list.setCurrentItem(index);
input_field = list_window.list.getItem(index).getText();
input_field.redraw();
processChanged();
}
@ -620,8 +637,8 @@ void FComboBox::processChanged()
void FComboBox::cb_setInputField (FWidget*, FDataPtr)
{
auto& list = list_window.list;
std::size_t i = list.currentItem();
input_field = list.getItem(i).getText();
std::size_t index = list.currentItem();
input_field = list.getItem(index).getText();
input_field.redraw();
processChanged();
}

View File

@ -520,34 +520,6 @@ void FWidget::setRightPadding (int right, bool adjust)
}
}
//----------------------------------------------------------------------
void FWidget::setParentOffset()
{
auto p = getParentWidget();
if ( p )
woffset = p->wclient_offset;
}
//----------------------------------------------------------------------
void FWidget::setTermOffset()
{
auto r = getRootWidget();
int w = int(r->getWidth());
int h = int(r->getHeight());
woffset.setCoordinates (0, 0, w - 1, h - 1);
}
//----------------------------------------------------------------------
void FWidget::setTermOffsetWithPadding()
{
auto r = getRootWidget();
woffset.setCoordinates ( r->getLeftPadding()
, r->getTopPadding()
, int(r->getWidth()) - 1 - r->getRightPadding()
, int(r->getHeight()) - 1 - r->getBottomPadding() );
}
//----------------------------------------------------------------------
void FWidget::setTermSize (const FSize& size)
{
@ -1273,6 +1245,34 @@ void FWidget::setMenuBar (FMenuBar* mbar)
menubar = mbar;
}
//----------------------------------------------------------------------
void FWidget::setParentOffset()
{
auto p = getParentWidget();
if ( p )
woffset = p->wclient_offset;
}
//----------------------------------------------------------------------
void FWidget::setTermOffset()
{
auto r = getRootWidget();
int w = int(r->getWidth());
int h = int(r->getHeight());
woffset.setCoordinates (0, 0, w - 1, h - 1);
}
//----------------------------------------------------------------------
void FWidget::setTermOffsetWithPadding()
{
auto r = getRootWidget();
woffset.setCoordinates ( r->getLeftPadding()
, r->getTopPadding()
, int(r->getWidth()) - 1 - r->getRightPadding()
, int(r->getHeight()) - 1 - r->getBottomPadding() );
}
//----------------------------------------------------------------------
void FWidget::adjustSize()
{

View File

@ -175,6 +175,7 @@ class FComboBox : public FWidget
bool setEditable (bool);
bool setEditable();
bool unsetEditable();
void setCurrentItem (std::size_t);
void setMaxVisibleItems (std::size_t);
void setLabelText (const FString&);
void setLabelOrientation (const FLineEdit::label_o);
@ -252,8 +253,8 @@ inline FString FComboBox::getText() const
//----------------------------------------------------------------------
inline FDataPtr FComboBox::getItemData()
{
std::size_t i = list_window.list.currentItem();
return list_window.list.getItem(i).getData();
std::size_t index = list_window.list.currentItem();
return list_window.list.getItem(index).getData();
}
//----------------------------------------------------------------------

View File

@ -278,9 +278,6 @@ class FWidget : public FVTerm, public FObject
void setLeftPadding (int, bool = true);
void setBottomPadding (int, bool = true);
void setRightPadding (int, bool = true);
void setParentOffset();
void setTermOffset();
void setTermOffsetWithPadding();
void setTermSize (const FSize&);
virtual void setGeometry (const FRect&, bool = true);
virtual void setGeometry (const FPoint&, const FSize&, bool = true);
@ -376,6 +373,9 @@ class FWidget : public FVTerm, public FObject
virtual void setMenuBar (FMenuBar*);
FWidgetColors& setFWidgetColors();
static uInt& setModalDialogCounter();
void setParentOffset();
void setTermOffset();
void setTermOffsetWithPadding();
// Methods
virtual void adjustSize();