diff --git a/ChangeLog b/ChangeLog index 737f1392..d8bc288b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2019-12-23 Markus Gans + * Better setSize() implementation in some widgets + 2019-12-20 Markus Gans * Fixed the drawing of FLabel widget with the default size of 1×1 character. diff --git a/src/fcombobox.cpp b/src/fcombobox.cpp index b6090388..428de30c 100644 --- a/src/fcombobox.cpp +++ b/src/fcombobox.cpp @@ -181,6 +181,15 @@ FComboBox::~FComboBox() // destructor // 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 , bool adjust ) diff --git a/src/flineedit.cpp b/src/flineedit.cpp index c4226d5e..e1143787 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -254,6 +254,15 @@ void FLineEdit::setLabelOrientation (const label_o o) 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 , bool adjust ) diff --git a/src/flistbox.cpp b/src/flistbox.cpp index f6a3f00e..adfcbd2b 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -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 , bool adjust ) { - // Set the widget geometry - - FWidget::setGeometry(pos, size, adjust); - - 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)); - } + FWidget::setGeometry (pos, size, adjust); + changeOnResize(); } //---------------------------------------------------------------------- @@ -1718,6 +1713,21 @@ void FListBox::processChanged() 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) { diff --git a/src/flistview.cpp b/src/flistview.cpp index a781e553..229bf1ca 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -649,24 +649,19 @@ fc::sorting_type FListView::getColumnSortType (int column) const return type; } +//---------------------------------------------------------------------- +void FListView::setSize (const FSize& size, bool adjust) +{ + FWidget::setSize (size, adjust); + changeOnResize(); +} + //---------------------------------------------------------------------- void FListView::setGeometry ( const FPoint& pos, const FSize& size , bool adjust) { - // Set the widget geometry - - FWidget::setGeometry(pos, size, adjust); - - 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)); - } + FWidget::setGeometry (pos, size, adjust); + changeOnResize(); } //---------------------------------------------------------------------- @@ -2245,6 +2240,21 @@ void FListView::processChanged() 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() { diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 749625c5..92ca4b2c 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -69,11 +69,20 @@ void FProgressbar::setPercentage (std::size_t percentage_value) 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 , bool adjust ) { - // Set the progress bar geometry + // Sets the progress bar geometry FWidget::setGeometry (pos, size, adjust); bar_length = size.getWidth(); diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index 6e2bab09..0608d349 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -146,6 +146,15 @@ void FScrollbar::setOrientation (fc::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 , bool adjust ) @@ -153,23 +162,7 @@ void FScrollbar::setGeometry ( const FPoint& pos, const FSize& size // Set the scrollbar geometry FWidget::setGeometry (pos, size, adjust); - - 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(); + changeOnResize(); } //---------------------------------------------------------------------- @@ -802,4 +795,26 @@ void FScrollbar::processScroll() 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 diff --git a/src/fspinbox.cpp b/src/fspinbox.cpp index 7b82503e..799540bd 100644 --- a/src/fspinbox.cpp +++ b/src/fspinbox.cpp @@ -53,6 +53,15 @@ FSpinBox::~FSpinBox() // destructor // 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 , bool adjust ) diff --git a/src/ftextview.cpp b/src/ftextview.cpp index bf0f2107..d87827f7 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -85,29 +85,23 @@ const FString FTextView::getText() const 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 , bool adjust) { - // Set the text view geometry + // Sets the text view geometry FWidget::setGeometry(pos, size, adjust); - 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(); + changeOnResize(); } //---------------------------------------------------------------------- @@ -728,6 +722,27 @@ void FTextView::processChanged() 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) { diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 0ec66d91..5a8a3ddc 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -80,6 +80,21 @@ FToggleButton::~FToggleButton() // destructor // 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 , bool adjust ) @@ -87,19 +102,13 @@ void FToggleButton::setGeometry ( const FPoint& pos, const FSize& s // Set the toggle button geometry FSize size(s); - 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); - + correctSize(size); const FRect geometry(pos, size); if ( hasGroup() ) getGroup()->checkScrollSize(geometry); - FWidget::setGeometry(pos, size, adjust); + FWidget::setGeometry (pos, size, adjust); } //---------------------------------------------------------------------- @@ -547,4 +556,15 @@ void FToggleButton::drawText (FString&& label_text, std::size_t hotkeypos) 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 diff --git a/src/include/final/fcombobox.h b/src/include/final/fcombobox.h index 1871391e..8a876531 100644 --- a/src/include/final/fcombobox.h +++ b/src/include/final/fcombobox.h @@ -159,6 +159,7 @@ class FComboBox : public FWidget FLineEdit::label_o getLabelOrientation(); // Mutators + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; bool setEnable (bool) override; diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index 6f57a2df..028c5e40 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -125,6 +125,7 @@ class FLineEdit : public FWidget void setInputType (const inputType); void setLabelOrientation (const label_o); void setLabelAssociatedWidget (FWidget*); + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; bool setEnable (bool) override; diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index 45af5f2e..c6e1b1b9 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -184,6 +184,7 @@ class FListBox : public FWidget void showInsideBrackets (std::size_t, fc::brackets_type); void showNoBrackets (std::size_t); void showNoBrackets (listBoxItems::iterator); + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; void setMultiSelection (bool); @@ -308,6 +309,7 @@ class FListBox : public FWidget void processClick(); void processSelect(); void processChanged(); + void changeOnResize(); void lazyConvert (listBoxItems::iterator, int); listBoxItems::iterator index2iterator (std::size_t); listBoxItems::const_iterator index2iterator (std::size_t index) const; diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 257b5cd7..6e7d3f20 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -285,6 +285,7 @@ class FListView : public FWidget FListViewItem* getCurrentItem(); // Mutators + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; void setColumnAlignment (int, fc::text_alignment); @@ -419,6 +420,7 @@ class FListView : public FWidget iterator appendItem (FListViewItem*); void processClick(); void processChanged(); + void changeOnResize(); void toggleCheckbox(); void collapseAndScrollLeft(); void expandAndScrollRight(); diff --git a/src/include/final/fprogressbar.h b/src/include/final/fprogressbar.h index 56dc9e68..ee46d590 100644 --- a/src/include/final/fprogressbar.h +++ b/src/include/final/fprogressbar.h @@ -79,6 +79,7 @@ class FProgressbar : public FWidget // Mutators void setPercentage (std::size_t); + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; bool setShadow (bool); diff --git a/src/include/final/fscrollbar.h b/src/include/final/fscrollbar.h index 08e6bdb4..48962c2c 100644 --- a/src/include/final/fscrollbar.h +++ b/src/include/final/fscrollbar.h @@ -115,6 +115,7 @@ class FScrollbar : public FWidget void setSteps (double); void setPageSize (int, int); void setOrientation (fc::orientation); + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; @@ -148,6 +149,7 @@ class FScrollbar : public FWidget void jumpToClickPos (int); void avoidScrollOvershoot(); void processScroll(); + void changeOnResize(); // Data members sType scroll_type{FScrollbar::noScroll}; diff --git a/src/include/final/fspinbox.h b/src/include/final/fspinbox.h index c891d35f..1567c7ee 100644 --- a/src/include/final/fspinbox.h +++ b/src/include/final/fspinbox.h @@ -90,6 +90,7 @@ class FSpinBox : public FWidget FLineEdit::label_o getLabelOrientation(); // Mutators + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; bool setEnable (bool) override; diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index d58ceb0b..f0fc9edc 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -101,6 +101,7 @@ class FTextView : public FWidget const FStringList& getLines() const; // Mutators + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; void setText (const FString&); @@ -158,6 +159,7 @@ class FTextView : public FWidget bool useFDialogBorder(); bool isPrintable (wchar_t); void processChanged(); + void changeOnResize(); // Callback methods void cb_VBarChange (FWidget*, FDataPtr); diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 0787bfa0..13d07469 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -88,6 +88,7 @@ class FToggleButton : public FWidget FString& getText(); // Mutators + void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; bool setNoUnderline (bool); @@ -152,6 +153,7 @@ class FToggleButton : public FWidget // Methods void init(); void drawText (FString&&, std::size_t); + void correctSize (FSize&); // Data members FButtonGroup* button_group{nullptr}; diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 639990a1..613d6c13 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -850,7 +850,10 @@ inline void FWidget::setBackgroundColor (FColor color) //---------------------------------------------------------------------- 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) @@ -875,7 +878,10 @@ inline void FWidget::setMinimumHeight (std::size_t min_height) //---------------------------------------------------------------------- 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) @@ -887,11 +893,16 @@ inline void FWidget::setMaximumHeight (std::size_t max_height) //---------------------------------------------------------------------- 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) { + // Sets the minimum and maximum size limit to fixed sizes to prevent + // the widget resizing size_hints.setMinimum (size); size_hints.setMaximum (size); }