Better setSize() implementation in some widgets

This commit is contained in:
Markus Gans 2019-12-23 03:53:32 +01:00
parent b7639f5301
commit 3a391f5fe5
20 changed files with 208 additions and 74 deletions

View File

@ -1,3 +1,6 @@
2019-12-23 Markus Gans <guru.mail@muenster.de>
* Better setSize() implementation in some widgets
2019-12-20 Markus Gans <guru.mail@muenster.de> 2019-12-20 Markus Gans <guru.mail@muenster.de>
* Fixed the drawing of FLabel widget with the default size * Fixed the drawing of FLabel widget with the default size
of 1×1 character. of 1×1 character.

View File

@ -181,6 +181,15 @@ FComboBox::~FComboBox() // destructor
// public methods of FComboBox // public methods of FComboBox
//----------------------------------------------------------------------
void FComboBox::setSize (const FSize& size, bool adjust)
{
FWidget::setSize (size, adjust);
FSize input_field_size(size);
input_field_size.scaleBy(-(1 + nf), 0);
input_field.setSize (input_field_size, adjust);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FComboBox::setGeometry ( const FPoint& pos, const FSize& size void FComboBox::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust ) , bool adjust )

View File

@ -254,6 +254,15 @@ void FLineEdit::setLabelOrientation (const label_o o)
adjustLabel(); adjustLabel();
} }
//----------------------------------------------------------------------
void FLineEdit::setSize (const FSize& size, bool adjust)
{
FWidget::setSize (size, adjust);
if ( isShown() )
adjustTextOffset();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::setGeometry ( const FPoint& pos, const FSize& size void FLineEdit::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust ) , bool adjust )

View File

@ -160,24 +160,19 @@ void FListBox::showInsideBrackets ( std::size_t index
} }
} }
//----------------------------------------------------------------------
void FListBox::setSize (const FSize& size, bool adjust)
{
FWidget::setSize (size, adjust);
changeOnResize();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::setGeometry ( const FPoint& pos, const FSize& size void FListBox::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust ) , bool adjust )
{ {
// Set the widget geometry
FWidget::setGeometry (pos, size, adjust); FWidget::setGeometry (pos, size, adjust);
changeOnResize();
if ( isNewFont() )
{
vbar->setGeometry (FPoint(int(getWidth()), 2), FSize(2, getHeight() - 2));
hbar->setGeometry (FPoint(1, int(getHeight())), FSize(getWidth() - 2, 1));
}
else
{
vbar->setGeometry (FPoint(int(getWidth()), 2), FSize(1, getHeight() - 2));
hbar->setGeometry (FPoint(2, int(getHeight())), FSize(getWidth() - 2, 1));
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1718,6 +1713,21 @@ void FListBox::processChanged()
emitCallback("row-changed"); emitCallback("row-changed");
} }
//----------------------------------------------------------------------
void FListBox::changeOnResize()
{
if ( isNewFont() )
{
vbar->setGeometry (FPoint(int(getWidth()), 2), FSize(2, getHeight() - 2));
hbar->setGeometry (FPoint(1, int(getHeight())), FSize(getWidth() - 2, 1));
}
else
{
vbar->setGeometry (FPoint(int(getWidth()), 2), FSize(1, getHeight() - 2));
hbar->setGeometry (FPoint(2, int(getHeight())), FSize(getWidth() - 2, 1));
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::lazyConvert(listBoxItems::iterator iter, int y) void FListBox::lazyConvert(listBoxItems::iterator iter, int y)
{ {

View File

@ -649,24 +649,19 @@ fc::sorting_type FListView::getColumnSortType (int column) const
return type; return type;
} }
//----------------------------------------------------------------------
void FListView::setSize (const FSize& size, bool adjust)
{
FWidget::setSize (size, adjust);
changeOnResize();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::setGeometry ( const FPoint& pos, const FSize& size void FListView::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust) , bool adjust)
{ {
// Set the widget geometry
FWidget::setGeometry (pos, size, adjust); FWidget::setGeometry (pos, size, adjust);
changeOnResize();
if ( isNewFont() )
{
vbar->setGeometry (FPoint(int(getWidth()), 2), FSize(2, getHeight() - 2));
hbar->setGeometry (FPoint(1, int(getHeight())), FSize(getWidth() - 2, 1));
}
else
{
vbar->setGeometry (FPoint(int(getWidth()), 2), FSize(1, getHeight() - 2));
hbar->setGeometry (FPoint(2, int(getHeight())), FSize(getWidth() - 2, 1));
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -2245,6 +2240,21 @@ void FListView::processChanged()
emitCallback("row-changed"); emitCallback("row-changed");
} }
//----------------------------------------------------------------------
void FListView::changeOnResize()
{
if ( isNewFont() )
{
vbar->setGeometry (FPoint(int(getWidth()), 2), FSize(2, getHeight() - 2));
hbar->setGeometry (FPoint(1, int(getHeight())), FSize(getWidth() - 2, 1));
}
else
{
vbar->setGeometry (FPoint(int(getWidth()), 2), FSize(1, getHeight() - 2));
hbar->setGeometry (FPoint(2, int(getHeight())), FSize(getWidth() - 2, 1));
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListView::toggleCheckbox() inline void FListView::toggleCheckbox()
{ {

View File

@ -69,11 +69,20 @@ void FProgressbar::setPercentage (std::size_t percentage_value)
updateTerminal(); updateTerminal();
} }
//----------------------------------------------------------------------
void FProgressbar::setSize (const FSize& size, bool adjust)
{
// Sets the progress bar size
FWidget::setSize (size, adjust);
bar_length = size.getWidth();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FProgressbar::setGeometry ( const FPoint& pos, const FSize& size void FProgressbar::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust ) , bool adjust )
{ {
// Set the progress bar geometry // Sets the progress bar geometry
FWidget::setGeometry (pos, size, adjust); FWidget::setGeometry (pos, size, adjust);
bar_length = size.getWidth(); bar_length = size.getWidth();

View File

@ -146,6 +146,15 @@ void FScrollbar::setOrientation (fc::orientation o)
bar_orientation = o; bar_orientation = o;
} }
//----------------------------------------------------------------------
void FScrollbar::setSize (const FSize& size, bool adjust)
{
// Set the scrollbar size
FWidget::setSize (size, adjust);
changeOnResize();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollbar::setGeometry ( const FPoint& pos, const FSize& size void FScrollbar::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust ) , bool adjust )
@ -153,23 +162,7 @@ void FScrollbar::setGeometry ( const FPoint& pos, const FSize& size
// Set the scrollbar geometry // Set the scrollbar geometry
FWidget::setGeometry (pos, size, adjust); FWidget::setGeometry (pos, size, adjust);
changeOnResize();
std::size_t w = size.getWidth();
std::size_t h = size.getHeight();
length = ( bar_orientation == fc::vertical ) ? h : w;
if ( bar_orientation == fc::vertical )
{
setWidth(isNewFont() ? 2 : 1);
setHeight(length);
}
else // horizontal
{
setWidth(length);
setHeight(1);
}
calculateSliderValues();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -802,4 +795,26 @@ void FScrollbar::processScroll()
avoidScrollOvershoot(); avoidScrollOvershoot();
} }
//----------------------------------------------------------------------
void FScrollbar::changeOnResize()
{
const FSize& size = getSize();
std::size_t w = size.getWidth();
std::size_t h = size.getHeight();
length = ( bar_orientation == fc::vertical ) ? h : w;
if ( bar_orientation == fc::vertical )
{
setWidth(isNewFont() ? 2 : 1);
setHeight(length);
}
else // horizontal
{
setWidth(length);
setHeight(1);
}
calculateSliderValues();
}
} // namespace finalcut } // namespace finalcut

View File

@ -53,6 +53,15 @@ FSpinBox::~FSpinBox() // destructor
// public methods of FSpinBox // public methods of FSpinBox
//----------------------------------------------------------------------
void FSpinBox::setSize (const FSize& size, bool adjust)
{
FWidget::setSize (size, adjust);
FSize input_field_size(size);
input_field_size.scaleBy(-2, 0);
input_field.setSize (input_field_size, adjust);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FSpinBox::setGeometry ( const FPoint& pos, const FSize& size void FSpinBox::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust ) , bool adjust )

View File

@ -85,29 +85,23 @@ const FString FTextView::getText() const
return s; return s;
} }
//----------------------------------------------------------------------
void FTextView::setSize (const FSize& size, bool adjust)
{
// Sets the text view size
FWidget::setSize (size, adjust);
changeOnResize();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::setGeometry ( const FPoint& pos, const FSize& size void FTextView::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust) , bool adjust)
{ {
// Set the text view geometry // Sets the text view geometry
FWidget::setGeometry(pos, size, adjust); FWidget::setGeometry(pos, size, adjust);
std::size_t width = getWidth(); changeOnResize();
std::size_t height = getHeight();
if ( isNewFont() )
{
vbar->setGeometry (FPoint(int(width), 1), FSize(2, height - 1));
hbar->setGeometry (FPoint(1, int(height)), FSize(width - 2, 1));
}
else
{
vbar->setGeometry (FPoint(int(width), 2), FSize(1, height - 2));
hbar->setGeometry (FPoint(2, int(height)), FSize(width - 2, 1));
}
vbar->resize();
hbar->resize();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -728,6 +722,27 @@ void FTextView::processChanged()
emitCallback("changed"); emitCallback("changed");
} }
//----------------------------------------------------------------------
void FTextView::changeOnResize()
{
std::size_t width = getWidth();
std::size_t height = getHeight();
if ( isNewFont() )
{
vbar->setGeometry (FPoint(int(width), 1), FSize(2, height - 1));
hbar->setGeometry (FPoint(1, int(height)), FSize(width - 2, 1));
}
else
{
vbar->setGeometry (FPoint(int(width), 2), FSize(1, height - 2));
hbar->setGeometry (FPoint(2, int(height)), FSize(width - 2, 1));
}
vbar->resize();
hbar->resize();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::cb_VBarChange (FWidget*, FDataPtr) void FTextView::cb_VBarChange (FWidget*, FDataPtr)
{ {

View File

@ -80,6 +80,21 @@ FToggleButton::~FToggleButton() // destructor
// public methods of FToggleButton // public methods of FToggleButton
//----------------------------------------------------------------------
void FToggleButton::setSize (const FSize& s, bool adjust)
{
// Set the toggle button size
FSize size(s);
correctSize(size);
const FRect geometry(getPos(), size);
if ( hasGroup() )
getGroup()->checkScrollSize(geometry);
FWidget::setSize (size, adjust);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::setGeometry ( const FPoint& pos, const FSize& s void FToggleButton::setGeometry ( const FPoint& pos, const FSize& s
, bool adjust ) , bool adjust )
@ -87,13 +102,7 @@ void FToggleButton::setGeometry ( const FPoint& pos, const FSize& s
// Set the toggle button geometry // Set the toggle button geometry
FSize size(s); FSize size(s);
std::size_t hotkey_mark = ( getHotkey(text) ) ? 1 : 0; correctSize(size);
std::size_t column_width = getColumnWidth(text);
std::size_t min_width = button_width + column_width - hotkey_mark;
if ( size.getWidth() < min_width )
size.setWidth(min_width);
const FRect geometry(pos, size); const FRect geometry(pos, size);
if ( hasGroup() ) if ( hasGroup() )
@ -547,4 +556,15 @@ void FToggleButton::drawText (FString&& label_text, std::size_t hotkeypos)
setReverse(false); setReverse(false);
} }
//----------------------------------------------------------------------
void FToggleButton::correctSize (FSize& size)
{
std::size_t hotkey_mark = ( getHotkey(text) ) ? 1 : 0;
std::size_t column_width = getColumnWidth(text);
std::size_t min_width = button_width + column_width - hotkey_mark;
if ( size.getWidth() < min_width )
size.setWidth(min_width);
}
} // namespace finalcut } // namespace finalcut

View File

@ -159,6 +159,7 @@ class FComboBox : public FWidget
FLineEdit::label_o getLabelOrientation(); FLineEdit::label_o getLabelOrientation();
// Mutators // Mutators
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
bool setEnable (bool) override; bool setEnable (bool) override;

View File

@ -125,6 +125,7 @@ class FLineEdit : public FWidget
void setInputType (const inputType); void setInputType (const inputType);
void setLabelOrientation (const label_o); void setLabelOrientation (const label_o);
void setLabelAssociatedWidget (FWidget*); void setLabelAssociatedWidget (FWidget*);
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
bool setEnable (bool) override; bool setEnable (bool) override;

View File

@ -184,6 +184,7 @@ class FListBox : public FWidget
void showInsideBrackets (std::size_t, fc::brackets_type); void showInsideBrackets (std::size_t, fc::brackets_type);
void showNoBrackets (std::size_t); void showNoBrackets (std::size_t);
void showNoBrackets (listBoxItems::iterator); void showNoBrackets (listBoxItems::iterator);
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
void setMultiSelection (bool); void setMultiSelection (bool);
@ -308,6 +309,7 @@ class FListBox : public FWidget
void processClick(); void processClick();
void processSelect(); void processSelect();
void processChanged(); void processChanged();
void changeOnResize();
void lazyConvert (listBoxItems::iterator, int); void lazyConvert (listBoxItems::iterator, int);
listBoxItems::iterator index2iterator (std::size_t); listBoxItems::iterator index2iterator (std::size_t);
listBoxItems::const_iterator index2iterator (std::size_t index) const; listBoxItems::const_iterator index2iterator (std::size_t index) const;

View File

@ -285,6 +285,7 @@ class FListView : public FWidget
FListViewItem* getCurrentItem(); FListViewItem* getCurrentItem();
// Mutators // Mutators
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
void setColumnAlignment (int, fc::text_alignment); void setColumnAlignment (int, fc::text_alignment);
@ -419,6 +420,7 @@ class FListView : public FWidget
iterator appendItem (FListViewItem*); iterator appendItem (FListViewItem*);
void processClick(); void processClick();
void processChanged(); void processChanged();
void changeOnResize();
void toggleCheckbox(); void toggleCheckbox();
void collapseAndScrollLeft(); void collapseAndScrollLeft();
void expandAndScrollRight(); void expandAndScrollRight();

View File

@ -79,6 +79,7 @@ class FProgressbar : public FWidget
// Mutators // Mutators
void setPercentage (std::size_t); void setPercentage (std::size_t);
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
bool setShadow (bool); bool setShadow (bool);

View File

@ -115,6 +115,7 @@ class FScrollbar : public FWidget
void setSteps (double); void setSteps (double);
void setPageSize (int, int); void setPageSize (int, int);
void setOrientation (fc::orientation); void setOrientation (fc::orientation);
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
@ -148,6 +149,7 @@ class FScrollbar : public FWidget
void jumpToClickPos (int); void jumpToClickPos (int);
void avoidScrollOvershoot(); void avoidScrollOvershoot();
void processScroll(); void processScroll();
void changeOnResize();
// Data members // Data members
sType scroll_type{FScrollbar::noScroll}; sType scroll_type{FScrollbar::noScroll};

View File

@ -90,6 +90,7 @@ class FSpinBox : public FWidget
FLineEdit::label_o getLabelOrientation(); FLineEdit::label_o getLabelOrientation();
// Mutators // Mutators
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
bool setEnable (bool) override; bool setEnable (bool) override;

View File

@ -101,6 +101,7 @@ class FTextView : public FWidget
const FStringList& getLines() const; const FStringList& getLines() const;
// Mutators // Mutators
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
void setText (const FString&); void setText (const FString&);
@ -158,6 +159,7 @@ class FTextView : public FWidget
bool useFDialogBorder(); bool useFDialogBorder();
bool isPrintable (wchar_t); bool isPrintable (wchar_t);
void processChanged(); void processChanged();
void changeOnResize();
// Callback methods // Callback methods
void cb_VBarChange (FWidget*, FDataPtr); void cb_VBarChange (FWidget*, FDataPtr);

View File

@ -88,6 +88,7 @@ class FToggleButton : public FWidget
FString& getText(); FString& getText();
// Mutators // Mutators
void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
bool setNoUnderline (bool); bool setNoUnderline (bool);
@ -152,6 +153,7 @@ class FToggleButton : public FWidget
// Methods // Methods
void init(); void init();
void drawText (FString&&, std::size_t); void drawText (FString&&, std::size_t);
void correctSize (FSize&);
// Data members // Data members
FButtonGroup* button_group{nullptr}; FButtonGroup* button_group{nullptr};

View File

@ -850,7 +850,10 @@ inline void FWidget::setBackgroundColor (FColor color)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FWidget::FWidgetFlags& FWidget::setFlags() inline FWidget::FWidgetFlags& FWidget::setFlags()
{ return flags; } {
// Gives direct access to the widget flags
return flags;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::setGeometry (const FRect& box, bool adjust) inline void FWidget::setGeometry (const FRect& box, bool adjust)
@ -875,7 +878,10 @@ inline void FWidget::setMinimumHeight (std::size_t min_height)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::setMinimumSize (const FSize& size) inline void FWidget::setMinimumSize (const FSize& size)
{ size_hints.setMinimum (size); } {
// Sets the lower size limit to which the widget can be resized
size_hints.setMinimum (size);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::setMaximumWidth (std::size_t max_width) inline void FWidget::setMaximumWidth (std::size_t max_width)
@ -887,11 +893,16 @@ inline void FWidget::setMaximumHeight (std::size_t max_height)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::setMaximumSize (const FSize& size) inline void FWidget::setMaximumSize (const FSize& size)
{ size_hints.setMaximum (size); } {
// Sets the upper size limit to which the widget can be resized
size_hints.setMaximum (size);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::setFixedSize (const FSize& size) inline void FWidget::setFixedSize (const FSize& size)
{ {
// Sets the minimum and maximum size limit to fixed sizes to prevent
// the widget resizing
size_hints.setMinimum (size); size_hints.setMinimum (size);
size_hints.setMaximum (size); size_hints.setMaximum (size);
} }