From d39e85d4c5462de841871b88d17196a2483b570b Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 10 Nov 2018 00:53:57 +0100 Subject: [PATCH] =?UTF-8?q?FListView=20now=20has=20a=20sort=20indicator=20?= =?UTF-8?q?(=E2=96=BC/=E2=96=B2)=20to=20display=20the=20sort=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .codedocs | 2 +- ChangeLog | 9 +++-- examples/listview.cpp | 5 ++- src/fdialog.cpp | 3 +- src/flistview.cpp | 63 +++++++++++++++++++++++++++++------ src/include/final/flistview.h | 8 +++++ src/include/final/fobject.h | 4 +++ 7 files changed, 78 insertions(+), 16 deletions(-) diff --git a/.codedocs b/.codedocs index 5b2b06cb..94853e96 100644 --- a/.codedocs +++ b/.codedocs @@ -1,4 +1,4 @@ PROJECT_NAME = "The Final Cut" -EXCLUDE = debian, icon, logo, m4, scripts, examples +EXCLUDE = debian, doc, icon, logo, m4, scripts, examples EXCLUDE_PATTERNS = */test/* diff --git a/ChangeLog b/ChangeLog index 3e5a9deb..49e4ccff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-11-10 Markus Gans + * FListView now has a sort indicator to display the sort order + 2018-11-07 Markus Gans * Use new type FColor for color values @@ -129,7 +132,7 @@ 2018-07-01 Markus Gans * All in FOptiMove required termcap values can now be passed - with a single struct + with a single struct 2018-06-25 Markus Gans * All termcap values required in FOptiAttr can now be passed @@ -282,7 +285,7 @@ 2018-01-02 Markus Gans * Refactoring of secondary device attributes parsing - * Small menu improvements + * Small menu improvements 2017-12-31 Markus Gans * Refactoring of the FListBox mouse event handler @@ -504,7 +507,7 @@ 2017-07-18 Markus Gans * New Widget class FListView (filled with FListViewItem) to allow a multi-column data view - * Add the listview example to demonstrate FListView + * Add the listview example to demonstrate FListView 2017-07-11 Markus Gans * New class FTermBuffer to buffer terminal outputs diff --git a/examples/listview.cpp b/examples/listview.cpp index d353748a..062688e8 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -94,9 +94,12 @@ Listview::Listview (finalcut::FWidget* parent) // Sort in ascending order by the 1st column listView.setColumnSort (1, finalcut::fc::ascending); - // The sorting occurs later automatically at insert(). + // Sorting follows later automatically on insert(). // Otherwise you could start the sorting directly with sort() + // Allways show the sort indicator (▼/▲) + listView.hideSortIndicator(false); + // Populate FListView with a list of items populate(); diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 995f75e8..bd6c4a77 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -1615,7 +1615,8 @@ void FDialog::resizeMouseUpMove (mouseStates& ms, bool mouse_up) else h = int(getMaxHeight()) - getTermY() + y2_offset + 1; - setSize (std::size_t(w), std::size_t(h)); + setSize ( ( w >= 0) ? std::size_t(w) : 0 + , ( h >= 0) ? std::size_t(h) : 0 ); } if ( mouse_up ) diff --git a/src/flistview.cpp b/src/flistview.cpp index dfa08d8a..73c7f9e4 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -610,6 +610,7 @@ FListView::FListView (FWidget* parent) , scroll_distance(1) , scroll_timer(false) , tree_view(false) + , hide_sort_indicator(false) , clicked_expander_pos(-1, -1) , xoffset(0) , nf_offset(0) @@ -1766,37 +1767,79 @@ inline FString FListView::getLinePrefix ( const FListViewItem* item return line; } +//---------------------------------------------------------------------- +inline void FListView::drawSortIndicator ( std::size_t& length + , std::size_t column_width ) +{ + if ( length >= column_width ) + return; + + setColor(); + length++; + + if ( sort_order == fc::ascending ) + headerline << wchar_t(fc::BlackDownPointingTriangle); // ▼ + else if ( sort_order == fc::descending ) + headerline << wchar_t(fc::BlackUpPointingTriangle); // ▲ + + if ( length < column_width ) + { + length++; + headerline << ' '; + } +} + +//---------------------------------------------------------------------- +inline void FListView::drawHeaderLine (std::size_t length) +{ + setColor(); + const FString line (length, wchar_t(fc::BoxDrawingsHorizontal)); + headerline << line; // horizontal line +} + //---------------------------------------------------------------------- void FListView::drawColumnText (headerItems::const_iterator& iter) { // Print lable text static const std::size_t leading_space = 1; - static const std::size_t trailing_space = 1; const FString& text = iter->name; - std::size_t width = std::size_t(iter->width); FString txt = " " + text; + std::size_t width = std::size_t(iter->width); std::size_t txt_length = txt.getLength(); + std::size_t length = 0; std::size_t column_width = leading_space + width; + headerItems::const_iterator first = header.begin(); + int column = std::distance(first, iter) + 1; + bool isSortIndicator = bool ( sort_column == column + && ! hide_sort_indicator ); if ( isEnabled() ) setColor (wc.label_emphasis_fg, wc.label_bg); else setColor (wc.label_inactive_fg, wc.label_inactive_bg); + if ( isSortIndicator && txt_length >= column_width - 1 && txt_length > 1 ) + { + txt_length = column_width - 2; + txt = txt.left(txt_length); + } + if ( txt_length <= column_width ) { + length = txt_length; headerline << txt; - if ( txt_length < column_width ) - headerline << ' '; // trailing space - - if ( txt_length + trailing_space < column_width ) + if ( length < column_width ) { - setColor(); - const FString line ( column_width - trailing_space - txt_length - , wchar_t(fc::BoxDrawingsHorizontal) ); - headerline << line; // horizontal line + length++; + headerline << ' '; // trailing space } + + if ( isSortIndicator ) + drawSortIndicator (length, column_width ); + + if ( length < column_width ) + drawHeaderLine (column_width - length); } else drawColumnEllipsis (iter, text); // Print ellipsis diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index bcb209c5..be9cd05b 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -283,6 +283,7 @@ class FListView : public FWidget void setUserAscendingCompare (Compare); template void setUserDescendingCompare (Compare); + void hideSortIndicator (bool); bool setTreeView (bool); bool setTreeView(); bool unsetTreeView(); @@ -356,7 +357,9 @@ class FListView : public FWidget void drawListLine (const FListViewItem*, bool, bool); void setLineAttributes (bool, bool); FString getLinePrefix (const FListViewItem*, std::size_t); + void drawSortIndicator (std::size_t&, std::size_t); void drawColumnText (headerItems::const_iterator&); + void drawHeaderLine (std::size_t); void drawColumnEllipsis ( headerItems::const_iterator& , const FString& ); void updateDrawing (bool, bool); @@ -410,6 +413,7 @@ class FListView : public FWidget int scroll_distance; bool scroll_timer; bool tree_view; + bool hide_sort_indicator; FPoint clicked_expander_pos; int xoffset; int nf_offset; @@ -477,6 +481,10 @@ template inline void FListView::setUserDescendingCompare (Compare cmp) { user_defined_descending = cmp; } +//---------------------------------------------------------------------- +inline void FListView::hideSortIndicator (bool hide) +{ hide_sort_indicator = hide; } + //---------------------------------------------------------------------- inline bool FListView::setTreeView (bool on) { return (tree_view = on); } diff --git a/src/include/final/fobject.h b/src/include/final/fobject.h index 3ebb31af..2be00ec5 100644 --- a/src/include/final/fobject.h +++ b/src/include/final/fobject.h @@ -35,6 +35,10 @@ #error "Only can be included directly." #endif +#if __cplusplus < 199711L + #error "Your C++ compiler does not support the C++98 standard!" +#endif + #include // need for gettimeofday #include #include