diff --git a/ChangeLog b/ChangeLog index a6d2a1ef..ed364116 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-12-28 Markus Gans + * Text scrolling in FTextView was broken since February 17th! + 2018-12-28 Markus Gans * Add the assignment operator (=) for FButton to set the button text * Corrected shortening of overlong texts in the title bar of FDialog diff --git a/examples/listbox.cpp b/examples/listbox.cpp index 172195dc..13403034 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -30,7 +30,7 @@ using namespace finalcut; // Global application object -static std::shared_ptr temp_str { nullptr }; +static std::weak_ptr temp_str; // Function prototypes @@ -57,13 +57,15 @@ void doubleToItem ( FListBoxItem& item // Import converter functions FString& doubleToString (std::list::const_iterator iter) { - return temp_str->setNumber(*iter); + auto temp = temp_str.lock(); + return temp->setNumber(*iter); } FString& mapToString ( std::map::const_iterator iter ) { - return *temp_str = iter->first + ": " + iter->second; + auto temp = temp_str.lock(); + return *temp = iter->first + ": " + iter->second; } @@ -106,7 +108,8 @@ class Listbox : public FDialog Listbox::Listbox (FWidget* parent) : FDialog(parent) { - temp_str = std::make_shared(); + auto temp = std::make_shared(); + temp_str = temp; // listbox 1 //---------- diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 87f2989b..dee3a45a 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -143,7 +143,7 @@ void FTextView::scrollTo (int x, int y) if ( ! isVisible() || ! (changeX || changeY) ) return; - if ( xoffset != x ) + if ( changeX && isHorizontallyScrollable() ) { int xoffset_end = int(maxLineWidth - getTextWidth()); xoffset = x; @@ -151,7 +151,7 @@ void FTextView::scrollTo (int x, int y) if ( xoffset < 0 ) xoffset = 0; - if ( xoffset > xoffset_end ) + if ( xoffset > xoffset_end && xoffset_end >= 0 ) xoffset = xoffset_end; if ( update_scrollbar ) @@ -161,7 +161,7 @@ void FTextView::scrollTo (int x, int y) } } - if ( yoffset != y ) + if ( changeY && isVerticallyScrollable() ) { int yoffset_end = int(getRows() - getTextHeight()); yoffset = y; diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index 189d17e0..e7248d50 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -137,6 +137,10 @@ class FTextView : public FWidget std::size_t getTextHeight(); std::size_t getTextWidth(); + // Inquiry + bool isHorizontallyScrollable(); + bool isVerticallyScrollable(); + // Methods void init(); virtual void draw(); @@ -191,6 +195,14 @@ inline void FTextView::deleteRange (int from, int to) inline void FTextView::deleteLine (int pos) { deleteRange (pos, pos); } +//---------------------------------------------------------------------- +inline bool FTextView::isHorizontallyScrollable() +{ return bool( maxLineWidth > getTextWidth() ); } + +//---------------------------------------------------------------------- +inline bool FTextView::isVerticallyScrollable() +{ return bool( getRows() > getTextHeight() ); } + } // namespace finalcut #endif // FTEXTVIEW_H