Getting text into the top-left "cell" in Fl_Table_Row

17 views
Skip to first unread message

pvr...@btinternet.com

unread,
Nov 30, 2020, 11:17:09 AM11/30/20
to fltk.general
Hi,

I am extending Fl_Table_Row to display records in a database. I would like to add the column header of the row headers. Is this possible? I tried to draw the text in draw_cell in the CONTEXT_STARTPAGE and CONTEXT_ENDPAGE, but neither did what I wanted. All I wanted to add was "Record No." or similar.

Regards Phil.

Greg Ercolano

unread,
Nov 30, 2020, 1:26:46 PM11/30/20
to fltkg...@googlegroups.com
On 2020-11-30 08:17, 'pvr...@btinternet.com' via fltk.general wrote:
Hi,

I am extending Fl_Table_Row to display records in a database. I would like to add the column header of the [rows]. Is this possible?

    Sure, be sure to turn on col_header(1) and then in your draw_cell(), add your code to the CONTEXT_COL_HEADER section
    to draw the text inside the cell area for that column# (the XYWH and COL values passed to you for those values respectively).


I tried to draw the text in draw_cell in the CONTEXT_STARTPAGE and CONTEXT_ENDPAGE, but neither did what I wanted. All I wanted to add was "Record No." or similar.

    The "CONTEXT_XXXPAGE" sections are just for drawing something over the entire table like a background, floating text, or some such.
    This is because the XYWH values at that time will be for the entire table, not any particular row/column or cell, which you'd need to know
    to draw each column's header.

    I suggest looking at the examples/table-simple.cxx example program, and look at how the A/B/C/D.. column headers are drawn, e.g.


  void draw_cell(TableContext context, int ROW=0, int COL=0, int X=0, int Y=0, int W=0, int H=0) {
    [..]
   
switch ( context ) {
      [..]
      case CONTEXT_COL_HEADER:                  // Draw column headers
        sprintf(s,"%c",'A'+COL);                // "A", "B", "C", etc.
        DrawHeader(s,X,Y,W,H);
        return;
        [..]



Philip Rose

unread,
Nov 30, 2020, 4:47:11 PM11/30/20
to fltkg...@googlegroups.com

Thanks Greg,

 

What is the column number for the row headers?

 

Phil

 

Sent from Mail for Windows 10

 

From: Greg Ercolano
Sent: 30 November 2020 18:26
To: fltkg...@googlegroups.com
Subject: Re: [fltk.general] Getting text into the top-left "cell" in Fl_Table_Row

 

On 2020-11-30 08:17, 'pvr...@btinternet.com' via fltk.general wrote:

Hi,

 

I am extending Fl_Table_Row to display records in a database. I would like to add the column header of the [rows]. Is this possible?


    Sure, be sure to turn on col_header(1) and then in your draw_cell(), add your code to the CONTEXT_COL_HEADER section
    to draw the text inside the cell area for that column# (the XYWH and COL values passed to you for those values respectively).


I tried to draw the text in draw_cell in the CONTEXT_STARTPAGE and CONTEXT_ENDPAGE, but neither did what I wanted. All I wanted to add was "Record No." or similar.

    The "CONTEXT_XXXPAGE" sections are just for drawing something over the entire table like a background, floating text, or some such.
    This is because the XYWH values at that time will be for the entire table, not any particular row/column or cell, which you'd need to know
    to draw each column's header.

    I suggest looking at the examples/table-simple.cxx example program, and look at how the A/B/C/D.. column headers are drawn, e.g.

  void draw_cell(TableContext context, int ROW=0, int COL=0, int X=0, int Y=0, int W=0, int H=0) {
    [..]
    switch ( context ) {
      [..]
      case CONTEXT_COL_HEADER:                  // Draw column headers
        sprintf(s,"%c",'A'+COL);                // "A", "B", "C", etc.
        DrawHeader(s,X,Y,W,H);
        return;
        [..]

 

--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/KDDLWooAfAU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/65d32c9f-72fc-6153-3ae9-5f44e80297a9%40seriss.com.

 

Greg Ercolano

unread,
Nov 30, 2020, 4:59:34 PM11/30/20
to fltkg...@googlegroups.com
On 2020-11-30 13:47, 'Philip Rose' via fltk.general wrote:

Thanks Greg,

What is the column number for the row headers?


    The row headers have their own context just like the column headers: CONTEXT_ROW_HEADER

    When you receive CONTEXT_ROW_HEADER, the ROW value will have the row number so you can draw
    the different headings for each row.

    If you have a 2x2 table, you'll get:

        > Two callbacks for the two column headings, each will have CONTEXT_COL_HEADER set, and COL will have the column#.
        > Two callbacks for the two row headings, each will have CONTEXT_ROW_HEADER set, and ROW will have the row#.
        > You'll also get four CONTEXT_CELL calls for each of the 4 cells, where ROW and COL will have the appropriate values for each cell

    Please look at the draw_cell() function in table-simple.cxx, it shows how to draw both row and column headers
    in addition to the cells; note the comments:



  void draw_cell(TableContext context, int ROW=0, int COL=0, int X=0, int Y=0, int W=0, int H=0) {

    static char s[40];
    switch ( context ) {
      case CONTEXT_STARTPAGE:                   // before page is drawn..
        fl_font(FL_HELVETICA, 16);              // set the font for our drawing operations
        return;


      case CONTEXT_COL_HEADER:                  // Draw column headers
        sprintf(s,"%c",'A'+COL);                // "A", "B", "C", etc.
        DrawHeader(s,X,Y,W,H);
        return;

      case CONTEXT_ROW_HEADER:                  // Draw row headers
        sprintf(s,"%03d:",ROW);                 // "001:", "002:", etc
        DrawHeader(s,X,Y,W,H);
        return;
      case CONTEXT_CELL:                        // Draw data in cells
        sprintf(s,"%d",data[ROW][COL]);
        DrawData(s,X,Y,W,H);
        return;
      default:
        return;



Philip Rose

unread,
Nov 30, 2020, 5:21:59 PM11/30/20
to fltkg...@googlegroups.com

I want to write text into the bit of the table that is above the row headers and to the left of the column headers to provide a header to the row headers.

 

In the example you gave the two columns have a header each, the two rows have a header each. That’s 8 cells occupied. I want to write something into the ninth cell in the top-left.

 

Phil

 

Sent from Mail for Windows 10

 

From: Greg Ercolano
Sent: 30 November 2020 21:59
To: fltkg...@googlegroups.com
Subject: Re: [fltk.general] Getting text into the top-left "cell" in Fl_Table_Row

 

On 2020-11-30 13:47, 'Philip Rose' via fltk.general wrote:

Thanks Greg,

What is the column number for the row headers?


    The row headers have their own context just like the column headers: CONTEXT_ROW_HEADER

    When you receive CONTEXT_ROW_HEADER, the ROW value will have the row number so you can draw
    the different headings for each row.

    If you have a 2x2 table, you'll get:

        > Two callbacks for the two column headings, each will have CONTEXT_COL_HEADER set, and COL will have the column#.
        > Two callbacks for the two row headings, each will have CONTEXT_ROW_HEADER set, and ROW will have the row#.
        > You'll also get four CONTEXT_CELL calls for each of the 4 cells, where ROW and COL will have the appropriate values for each cell

    Please look at the draw_cell() function in table-simple.cxx, it shows how to draw both row and column headers
    in addition to the cells; note the comments:


  void draw_cell(TableContext context, int ROW=0, int COL=0, int X=0, int Y=0, int W=0, int H=0) {
    static char s[40];
    switch ( context ) {
      case CONTEXT_STARTPAGE:                   // before page is drawn..
        fl_font(FL_HELVETICA, 16);              // set the font for our drawing operations
        return;
      case CONTEXT_COL_HEADER:                  // Draw column headers
        sprintf(s,"%c",'A'+COL);                // "A", "B", "C", etc.
        DrawHeader(s,X,Y,W,H);
        return;
      case CONTEXT_ROW_HEADER:                  // Draw row headers
        sprintf(s,"%03d:",ROW);                 // "001:", "002:", etc
        DrawHeader(s,X,Y,W,H);
        return;
      case CONTEXT_CELL:                        // Draw data in cells
        sprintf(s,"%d",data[ROW][COL]);
        DrawData(s,X,Y,W,H);
        return;
      default:
        return;

 

--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/KDDLWooAfAU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.

Philip Rose

unread,
Nov 30, 2020, 5:44:30 PM11/30/20
to fltkg...@googlegroups.com

In the shown example, it’s the place to the left of where it says “Date” and above the place where it has “2925”. I would like to write into there.

 

Phil.

 

Sent from Mail for Windows 10

 

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/5fc57085.1c69fb81.3f986.6ef8SMTPIN_ADDED_BROKEN%40gmr-mx.google.com.

 

example.png
5683198F44F84BAE892EC9863F570FD0.png

Greg Ercolano

unread,
Nov 30, 2020, 6:43:17 PM11/30/20
to fltkg...@googlegroups.com
On 2020-11-30 14:44, 'Philip Rose' via fltk.general wrote:

In the shown example, it’s the place to the left of where it says “Date” and above the place where it has “2925”. I would like to write into there.

    Oh, that little area is neither cell nor header.. that's a perfect use for CONTEXT_ENDPAGE.
    Here's how to write to that area, shown by drawing an "X":


      case CONTEXT_ENDPAGE: {                   // after page headers/cells are drawn..
        // Draw black 'x' in the dead area
        int X1=x(), Y1=y(), X2=x()+row_header_width(), Y2=y()+col_header_height();
        fl_color(FL_BLACK);
        fl_line(X1,Y1,X2,Y2);
        fl_line(X1,Y2,X2,Y1);
        return;
      }



    Modified version of table-simple.cxx attached here with that added.

table-simple2.cxx

Philip Rose

unread,
Dec 1, 2020, 10:29:05 AM12/1/20
to fltkg...@googlegroups.com

From: Greg Ercolano
Sent: 30 November 2020 23:43


To: fltkg...@googlegroups.com
Subject: Re: [fltk.general] Getting text into the top-left "cell" in Fl_Table_Row

 

On 2020-11-30 14:44, 'Philip Rose' via fltk.general wrote:

In the shown example, it’s the place to the left of where it says “Date” and above the place where it has “2925”. I would like to write into there.

    Oh, that little area is neither cell nor header.. that's a perfect use for CONTEXT_ENDPAGE.
    Here's how to write to that area, shown by drawing an "X":

      case CONTEXT_ENDPAGE: {                   // after page headers/cells are drawn..
        // Draw black 'x' in the dead area
        int X1=x(), Y1=y(), X2=x()+row_header_width(), Y2=y()+col_header_height();
        fl_color(FL_BLACK);
        fl_line(X1,Y1,X2,Y2);
        fl_line(X1,Y2,X2,Y1);
        return;
      }

Thanks Greg,

 

Looks like I had originally tried to display the text in the top-left of the window.

 

I had to tweak the code slightly to get the box to line up with the column headers:

 

       case CONTEXT_ENDPAGE:

       {

              // Code trying to write text into the top-left corner

              // Set the font for the header header

              fl_font(fl_font() | FL_ITALIC, fontsize_);

              // Set the col header row header crossing point

              fl_color(col_header_color());

              int X1 = x() + Fl::box_dx(box());

              int Y1 = y() + Fl::box_dy(box());

              int W1 = row_header_width();

              int H1 = col_header_height();

              fl_draw_box(FL_BORDER_BOX, X1, Y1, W1, H1, col_header_color());

              // Text color

              fl_color(FL_BLACK);

              fl_draw("QSO No.", X1, Y1, W1, H1, FL_ALIGN_CENTER);

 

              return;

       }

 

Regards Phil.

Philip Rose

unread,
Dec 1, 2020, 3:51:47 PM12/1/20
to fltkg...@googlegroups.com

I’ve since found out I could use Fl_Table_Row::wix and Fl_Table_Row::wiy, I had a vague remembrance they were there, but couldn’t find the article about them. I came across I had used tih in my code so searched that in the manual and found the others.

 

I know I’ve top-posted, but I cant be bothered the rigmarole to bottom post.

 

Phil.

 

Sent from Mail for Windows 10

 

--

You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/KDDLWooAfAU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.

1327F757E56D403F8108736D9CFB2036.png

Greg Ercolano

unread,
Dec 1, 2020, 4:05:40 PM12/1/20
to fltkg...@googlegroups.com
On 2020-12-01 12:51, 'Philip Rose' via fltk.general wrote:

I’ve since found out I could use Fl_Table_Row::wix and Fl_Table_Row::wiy, I had a vague remembrance they were there, but couldn’t find the article about them.


    Ya, those variables (and others) are described in this section of the docs for Fl_Table:
    https://www.fltk.org/doc-1.4/classFl__Table.html#details



    I was gonna mention them, but really using Fl::box_dx() et al as you did should work fine too.

I came across I had used tih in my code so searched that in the manual and found the others.


    Right.


 I know I’ve top-posted, but I cant be bothered the rigmarole to bottom post.


    Yes, I assume you're using the google group web interface, which doesn't seem to make that configurable,
    so until they do (probably never), we're stuck with their top post default.

    I prefer enabling the mail gateway to google groups, so I can use my mail client to handle everything
    in a way I'm used to, using a mail folder. (I hardly ever use the web interface to the group)
   

Ian MacArthur

unread,
Dec 1, 2020, 6:16:17 PM12/1/20
to fltkg...@googlegroups.com
Hmm - it looks from here as if Phil *might* be using the mail client that’s “built into” Win10 - is that right?

I tried it for a bit; didn’t like it.
It had a bunch of misbehaviours it probably learned from hanging around with Outlook, and didn’t seem to be amenable to much configuration to “fix” it...

Greg Ercolano

unread,
Dec 1, 2020, 6:31:53 PM12/1/20
to fltkg...@googlegroups.com
On 2020-12-01 15:16, Ian MacArthur wrote:
Hmm - it looks from here as if Phil *might* be using the mail client that’s “built into” Win10 - is that right?
 
    Oh, I didn't even notice his signature says that pretty clearly:

        Sent from Mail for Windows 10


    Sigh, sounds like yet another source of forced defaults.

    I can tell you that in google groups web interface when replying to an article,
    previous replies are compressed into a little "..." icon.

    And unless you click that "..." icon to open the quoted text, anything you type
    will be top posted unconditionally, and the entire previous message will be quoted
    in the final post, unseen by the poster.


Reply all
Reply to author
Forward
0 new messages