diff options
Diffstat (limited to 'examples/table-as-container.cxx')
| -rw-r--r-- | examples/table-as-container.cxx | 114 |
1 files changed, 54 insertions, 60 deletions
diff --git a/examples/table-as-container.cxx b/examples/table-as-container.cxx index 7f833cfc0..515ad884f 100644 --- a/examples/table-as-container.cxx +++ b/examples/table-as-container.cxx @@ -1,16 +1,14 @@ // -// "$Id$" +// Show how FLTK widgets can be parented by Fl_Table. -erco 03/30/2003 // -// Show how FLTK widgets can be parented by Fl_Table. -erco 03/30/2003 +// Originally the 'widgettable.cxx' example program that came with +// erco's Fl_Table widget. Added to FLTK in 2010. // -// Originally the 'widgettable.cxx' example program that came with -// erco's Fl_Table widget. Added to FLTK in 2010. -// -// This demonstrates how to use Fl_Table as a 'container' for FLTK -// widgets; one widget per cell. This isn't optimal for large tables, -// where it's better to make one instance of a widget, and move it to -// where it's needed. For an example of this, see the example program -// "table-spreadsheet.cxx". +// This demonstrates how to use Fl_Table as a 'container' for FLTK +// widgets; one widget per cell. This isn't optimal for large tables, +// where it's better to make one instance of a widget, and move it to +// where it's needed. For an example of this, see the example program +// "table-spreadsheet.cxx". // // Copyright 2010 Greg Ercolano. // Copyright 1998-2010 by Bill Spitzak and others. @@ -19,11 +17,11 @@ // the file "COPYING" which should have been included with this file. If this // file is missing or damaged, see the license at: // -// http://www.fltk.org/COPYING.php +// https://www.fltk.org/COPYING.php // -// Please report all bugs and problems to: +// Please see the following page on how to report bugs and issues: // -// http://www.fltk.org/str.php +// https://www.fltk.org/bugs.php // #include <stdio.h> @@ -41,8 +39,8 @@ void button_cb(Fl_Widget *w, void*); // class WidgetTable : public Fl_Table { protected: - void draw_cell(TableContext context, // table cell drawing - int R=0, int C=0, int X=0, int Y=0, int W=0, int H=0); + void draw_cell(TableContext context, // table cell drawing + int R=0, int C=0, int X=0, int Y=0, int W=0, int H=0); public: WidgetTable(int x, int y, int w, int h, const char *l=0) : Fl_Table(x,y,w,h,l) { @@ -57,32 +55,32 @@ public: ~WidgetTable() { } void SetSize(int newrows, int newcols) { - clear(); // clear any previous widgets, if any + clear(); // clear any previous widgets, if any rows(newrows); cols(newcols); - begin(); // start adding widgets to group + begin(); // start adding widgets to group { for ( int r = 0; r<newrows; r++ ) { - for ( int c = 0; c<newcols; c++ ) { - int X,Y,W,H; - find_cell(CONTEXT_TABLE, r, c, X, Y, W, H); - - char s[40]; - if ( c & 1 ) { - // Create the input widgets - sprintf(s, "%d.%d", r, c); - Fl_Input *in = new Fl_Input(X,Y,W,H); - in->value(s); - } else { - // Create the light buttons - sprintf(s, "%d/%d ", r, c); - Fl_Light_Button *butt = new Fl_Light_Button(X,Y,W,H,strdup(s)); - butt->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE); - butt->callback(button_cb, (void*)0); - butt->value( ((r+c*2) & 4 ) ? 1 : 0); - } - } + for ( int c = 0; c<newcols; c++ ) { + int X,Y,W,H; + find_cell(CONTEXT_TABLE, r, c, X, Y, W, H); + + char s[40]; + if ( c & 1 ) { + // Create the input widgets + sprintf(s, "%d.%d", r, c); + Fl_Input *in = new Fl_Input(X,Y,W,H); + in->value(s); + } else { + // Create the light buttons + sprintf(s, "%d/%d ", r, c); + Fl_Light_Button *butt = new Fl_Light_Button(X,Y,W,H,strdup(s)); + butt->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE); + butt->callback(button_cb, (void*)0); + butt->value( ((r+c*2) & 4 ) ? 1 : 0); + } + } } } end(); @@ -90,35 +88,35 @@ public: }; // Handle drawing all cells in table -void WidgetTable::draw_cell(TableContext context, - int R, int C, int X, int Y, int W, int H) { +void WidgetTable::draw_cell(TableContext context, + int R, int C, int X, int Y, int W, int H) { switch ( context ) { case CONTEXT_STARTPAGE: - fl_font(FL_HELVETICA, 12); // font used by all headers + fl_font(FL_HELVETICA, 12); // font used by all headers break; case CONTEXT_RC_RESIZE: { int X, Y, W, H; int index = 0; for ( int r = 0; r<rows(); r++ ) { - for ( int c = 0; c<cols(); c++ ) { - if ( index >= children() ) break; - find_cell(CONTEXT_TABLE, r, c, X, Y, W, H); - child(index++)->resize(X,Y,W,H); - } + for ( int c = 0; c<cols(); c++ ) { + if ( index >= children() ) break; + find_cell(CONTEXT_TABLE, r, c, X, Y, W, H); + child(index++)->resize(X,Y,W,H); + } } - init_sizes(); // tell group children resized + init_sizes(); // tell group children resized return; } case CONTEXT_ROW_HEADER: fl_push_clip(X, Y, W, H); { - static char s[40]; - sprintf(s, "Row %d", R); - fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, row_header_color()); - fl_color(FL_BLACK); - fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER); + static char s[40]; + sprintf(s, "Row %d", R); + fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, row_header_color()); + fl_color(FL_BLACK); + fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER); } fl_pop_clip(); return; @@ -126,17 +124,17 @@ void WidgetTable::draw_cell(TableContext context, case CONTEXT_COL_HEADER: fl_push_clip(X, Y, W, H); { - static char s[40]; - sprintf(s, "Column %d", C); - fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, col_header_color()); - fl_color(FL_BLACK); - fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER); + static char s[40]; + sprintf(s, "Column %d", C); + fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, col_header_color()); + fl_color(FL_BLACK); + fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER); } fl_pop_clip(); return; case CONTEXT_CELL: - return; // fltk handles drawing the widgets + return; // fltk handles drawing the widgets default: return; @@ -156,7 +154,3 @@ int main() { win.show(); return(Fl::run()); } - -// -// End of "$Id$". -// |
