From fdca0bcde18fd94c209fd1bfe8f82f45b290fe2e Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Sun, 17 Mar 2013 06:06:52 +0000 Subject: [PATCH] Small fix to column max width calculation: take into account width of header. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9837 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- examples/table-sort.cxx | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/examples/table-sort.cxx b/examples/table-sort.cxx index aef19a538..3a8fcb41a 100644 --- a/examples/table-sort.cxx +++ b/examples/table-sort.cxx @@ -39,7 +39,7 @@ #ifdef WIN32 // WINDOWS # define DIRCMD "dir" -# define DIRHEADER { "Date", "Time", "Size", "Filename", "", "", "", "", "" } +static const char *G_header[] = { "Date", "Time", "Size", "Filename", "", "", "", "", "", 0 }; # ifdef _MSC_VER # define popen _popen # endif @@ -47,9 +47,15 @@ // UNIX # include # define DIRCMD "ls -l" -# define DIRHEADER { "Perms", "#L", "Own", "Group", "Size", "Date", "", "", "Filename" } +static const char *G_header[] = { "Perms", "#L", "Own", "Group", "Size", "Date", "", "", "Filename", 0 }; #endif /*WIN32*/ +// Font face/sizes for header and rows +#define HEADER_FONTFACE FL_HELVETICA_BOLD +#define HEADER_FONTSIZE 16 +#define ROW_FONTFACE FL_HELVETICA +#define ROW_FONTSIZE 16 + // A single row of columns class Row { public: @@ -147,12 +153,11 @@ void MyTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, switch ( context ) { case CONTEXT_COL_HEADER: fl_push_clip(X,Y,W,H); { - static const char *head[] = DIRHEADER; fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, FL_BACKGROUND_COLOR); if ( C < 9 ) { - fl_font(FL_HELVETICA_BOLD, 16); + fl_font(HEADER_FONTFACE, HEADER_FONTSIZE); fl_color(FL_BLACK); - fl_draw(head[C], X+2,Y,W,H, FL_ALIGN_LEFT, 0, 0); // +2=pad left + fl_draw(G_header[C], X+2,Y,W,H, FL_ALIGN_LEFT, 0, 0); // +2=pad left // Draw sort arrow if ( C == _sort_lastcol ) { draw_sort_arrow(X,Y,W,H); @@ -166,7 +171,7 @@ void MyTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, // Bg color Fl_Color bgcolor = row_selected(R) ? selection_color() : FL_WHITE; fl_color(bgcolor); fl_rectf(X,Y,W,H); - fl_font(FL_HELVETICA, 16); + fl_font(ROW_FONTFACE, ROW_FONTSIZE); fl_color(FL_BLACK); fl_draw(s, X+2,Y,W,H, FL_ALIGN_LEFT); // +2=pad left // Border fl_color(FL_LIGHT2); fl_rect(X,Y,W,H); @@ -181,13 +186,17 @@ void MyTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, // Automatically set column widths to widest data in each column void MyTable::autowidth(int pad) { - fl_font(FL_COURIER, 16); - // Initialize all column widths to lowest value - for ( int c=0; c col_width(c)) col_width(c, w + pad); } }