FListView now has a sort indicator (▼/▲) to display the sort order

This commit is contained in:
Markus Gans 2018-11-10 00:53:57 +01:00
parent 3109189b1c
commit d39e85d4c5
7 changed files with 78 additions and 16 deletions

View File

@ -1,4 +1,4 @@
PROJECT_NAME = "The Final Cut" PROJECT_NAME = "The Final Cut"
EXCLUDE = debian, icon, logo, m4, scripts, examples EXCLUDE = debian, doc, icon, logo, m4, scripts, examples
EXCLUDE_PATTERNS = */test/* EXCLUDE_PATTERNS = */test/*

View File

@ -1,3 +1,6 @@
2018-11-10 Markus Gans <guru.mail@muenster.de>
* FListView now has a sort indicator to display the sort order
2018-11-07 Markus Gans <guru.mail@muenster.de> 2018-11-07 Markus Gans <guru.mail@muenster.de>
* Use new type FColor for color values * Use new type FColor for color values
@ -129,7 +132,7 @@
2018-07-01 Markus Gans <guru.mail@muenster.de> 2018-07-01 Markus Gans <guru.mail@muenster.de>
* All in FOptiMove required termcap values can now be passed * All in FOptiMove required termcap values can now be passed
with a single struct with a single struct
2018-06-25 Markus Gans <guru.mail@muenster.de> 2018-06-25 Markus Gans <guru.mail@muenster.de>
* All termcap values required in FOptiAttr can now be passed * All termcap values required in FOptiAttr can now be passed
@ -282,7 +285,7 @@
2018-01-02 Markus Gans <guru.mail@muenster.de> 2018-01-02 Markus Gans <guru.mail@muenster.de>
* Refactoring of secondary device attributes parsing * Refactoring of secondary device attributes parsing
* Small menu improvements * Small menu improvements
2017-12-31 Markus Gans <guru.mail@muenster.de> 2017-12-31 Markus Gans <guru.mail@muenster.de>
* Refactoring of the FListBox mouse event handler * Refactoring of the FListBox mouse event handler
@ -504,7 +507,7 @@
2017-07-18 Markus Gans <guru.mail@muenster.de> 2017-07-18 Markus Gans <guru.mail@muenster.de>
* New Widget class FListView (filled with FListViewItem) * New Widget class FListView (filled with FListViewItem)
to allow a multi-column data view 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 <guru.mail@muenster.de> 2017-07-11 Markus Gans <guru.mail@muenster.de>
* New class FTermBuffer to buffer terminal outputs * New class FTermBuffer to buffer terminal outputs

View File

@ -94,9 +94,12 @@ Listview::Listview (finalcut::FWidget* parent)
// Sort in ascending order by the 1st column // Sort in ascending order by the 1st column
listView.setColumnSort (1, finalcut::fc::ascending); 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() // 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 FListView with a list of items
populate(); populate();

View File

@ -1615,7 +1615,8 @@ void FDialog::resizeMouseUpMove (mouseStates& ms, bool mouse_up)
else else
h = int(getMaxHeight()) - getTermY() + y2_offset + 1; 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 ) if ( mouse_up )

View File

@ -610,6 +610,7 @@ FListView::FListView (FWidget* parent)
, scroll_distance(1) , scroll_distance(1)
, scroll_timer(false) , scroll_timer(false)
, tree_view(false) , tree_view(false)
, hide_sort_indicator(false)
, clicked_expander_pos(-1, -1) , clicked_expander_pos(-1, -1)
, xoffset(0) , xoffset(0)
, nf_offset(0) , nf_offset(0)
@ -1766,37 +1767,79 @@ inline FString FListView::getLinePrefix ( const FListViewItem* item
return line; 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) void FListView::drawColumnText (headerItems::const_iterator& iter)
{ {
// Print lable text // Print lable text
static const std::size_t leading_space = 1; static const std::size_t leading_space = 1;
static const std::size_t trailing_space = 1;
const FString& text = iter->name; const FString& text = iter->name;
std::size_t width = std::size_t(iter->width);
FString txt = " " + text; FString txt = " " + text;
std::size_t width = std::size_t(iter->width);
std::size_t txt_length = txt.getLength(); std::size_t txt_length = txt.getLength();
std::size_t length = 0;
std::size_t column_width = leading_space + width; 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() ) if ( isEnabled() )
setColor (wc.label_emphasis_fg, wc.label_bg); setColor (wc.label_emphasis_fg, wc.label_bg);
else else
setColor (wc.label_inactive_fg, wc.label_inactive_bg); 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 ) if ( txt_length <= column_width )
{ {
length = txt_length;
headerline << txt; headerline << txt;
if ( txt_length < column_width ) if ( length < column_width )
headerline << ' '; // trailing space
if ( txt_length + trailing_space < column_width )
{ {
setColor(); length++;
const FString line ( column_width - trailing_space - txt_length headerline << ' '; // trailing space
, wchar_t(fc::BoxDrawingsHorizontal) );
headerline << line; // horizontal line
} }
if ( isSortIndicator )
drawSortIndicator (length, column_width );
if ( length < column_width )
drawHeaderLine (column_width - length);
} }
else else
drawColumnEllipsis (iter, text); // Print ellipsis drawColumnEllipsis (iter, text); // Print ellipsis

View File

@ -283,6 +283,7 @@ class FListView : public FWidget
void setUserAscendingCompare (Compare); void setUserAscendingCompare (Compare);
template <typename Compare> template <typename Compare>
void setUserDescendingCompare (Compare); void setUserDescendingCompare (Compare);
void hideSortIndicator (bool);
bool setTreeView (bool); bool setTreeView (bool);
bool setTreeView(); bool setTreeView();
bool unsetTreeView(); bool unsetTreeView();
@ -356,7 +357,9 @@ class FListView : public FWidget
void drawListLine (const FListViewItem*, bool, bool); void drawListLine (const FListViewItem*, bool, bool);
void setLineAttributes (bool, bool); void setLineAttributes (bool, bool);
FString getLinePrefix (const FListViewItem*, std::size_t); FString getLinePrefix (const FListViewItem*, std::size_t);
void drawSortIndicator (std::size_t&, std::size_t);
void drawColumnText (headerItems::const_iterator&); void drawColumnText (headerItems::const_iterator&);
void drawHeaderLine (std::size_t);
void drawColumnEllipsis ( headerItems::const_iterator& void drawColumnEllipsis ( headerItems::const_iterator&
, const FString& ); , const FString& );
void updateDrawing (bool, bool); void updateDrawing (bool, bool);
@ -410,6 +413,7 @@ class FListView : public FWidget
int scroll_distance; int scroll_distance;
bool scroll_timer; bool scroll_timer;
bool tree_view; bool tree_view;
bool hide_sort_indicator;
FPoint clicked_expander_pos; FPoint clicked_expander_pos;
int xoffset; int xoffset;
int nf_offset; int nf_offset;
@ -477,6 +481,10 @@ template <typename Compare>
inline void FListView::setUserDescendingCompare (Compare cmp) inline void FListView::setUserDescendingCompare (Compare cmp)
{ user_defined_descending = cmp; } { user_defined_descending = cmp; }
//----------------------------------------------------------------------
inline void FListView::hideSortIndicator (bool hide)
{ hide_sort_indicator = hide; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FListView::setTreeView (bool on) inline bool FListView::setTreeView (bool on)
{ return (tree_view = on); } { return (tree_view = on); }

View File

@ -35,6 +35,10 @@
#error "Only <final/final.h> can be included directly." #error "Only <final/final.h> can be included directly."
#endif #endif
#if __cplusplus < 199711L
#error "Your C++ compiler does not support the C++98 standard!"
#endif
#include <sys/time.h> // need for gettimeofday #include <sys/time.h> // need for gettimeofday
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>