Add an Fl_Menu_Bar to an Fl_Table?

23 views
Skip to first unread message

Daniel Polski

unread,
Mar 9, 2018, 3:42:26 AM3/9/18
to fltk.general
Hello,

I've added a Fl_Menu_Bar to an Fl_Table, but am having some problems getting the resizing working as I want.

Maybe my "solution" to wrap things inside an internal group in the table isn't the way to solve it, but I've created an example showing how it currently works.

My goal is to have the table columns Y position "stick" to the tables menu bar, but as you see in the example the magenta fields height grows & shrinks when you drag the tiled red & green groups.

(I intend to have even more controls to the right of the menu, which is why the menu doesn't cover the whole width)

Here's my example describing the current behaviour:


#include <Fl/Fl_Double_Window.H>
#include <FL/Fl.H>
#include <FL/Fl_Table.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Tile.H>
#include <FL/fl_draw.H>

class Testtable : public Fl_Table {



   
void DrawHeader(const char *s, int X, int Y, int W, int H) {

        fl_push_clip
(X, Y, W, H);

        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
();

   
}



   
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:

            fl_font
(FL_HELVETICA, 16);

           
return;

       
case CONTEXT_COL_HEADER:

            sprintf
(s, "%c", 'A' + COL);

           
DrawHeader(s, X, Y, W, H);

           
return;

       
case CONTEXT_ROW_HEADER:

            sprintf
(s, "%03d:", ROW);

           
DrawHeader(s, X, Y, W, H);

           
return;

       
case CONTEXT_CELL: {

            fl_draw_box
(FL_THIN_UP_BOX, X, Y, W, H, FL_WHITE);

            fl_color
(FL_BLACK);

            fl_draw
("test", X, Y, W, H, FL_ALIGN_CENTER);

           
return;

       
}

       
default:

           
return;

       
}

   
}



   
Fl_Group* grpWrapper;



public:

   
Testtable(int X, int Y, int W, int H, const char* L = 0) :
Fl_Table(X, Y+20, W, H-20, L) {

        rows
(20);

        cols
(5);

        col_header
(1);

        col_resize
(1);

       
end();



        grpWrapper
= new Fl_Group(X, Y, W, H);

        grpWrapper
->box(FL_FLAT_BOX);

        grpWrapper
->color(FL_MAGENTA);

        grpWrapper
->add(this);



       
Fl_Group* menuResizeLock = new Fl_Group(X, Y, W / 2, 20);

       
Fl_Menu_Bar* menubar = new Fl_Menu_Bar(X, Y, W/2, 20);

        menubar
->add("test menu 1/choice 1");

        menubar
->add("test menu 1/choice 2");

        menubar
->add("test menu 2/choice 1");

        menubar
->add("test menu 2/choice 2");

        menuResizeLock
->end();

        menuResizeLock
->resizable(NULL);



        grpWrapper
->end();



   
}



   
int y() { return grpWrapper->y(); }

   
int h() { return grpWrapper->h(); }

};



int main()

{

   
Fl_Double_Window* win = new Fl_Double_Window(640, 480);

   
Fl_Tile* tile = new Fl_Tile(0, 0, win->w(), win->h());



   
Fl_Group* grpTop = new Fl_Group(tile->x(), tile->y(), tile->w(),
win
->h() / 3);

    grpTop
->box(FL_FLAT_BOX);

    grpTop
->color(FL_RED);

    grpTop
->end();



   
Testtable* tbl = new Testtable(grpTop->x(), grpTop->y() +
grpTop
->h(), grpTop->w(), grpTop->h());



   
Fl_Group* grpBottom = new Fl_Group(tbl->x(), tbl->y() + tbl->h(),
tbl
->w(), tbl->h());

    grpBottom
->box(FL_FLAT_BOX);

    grpBottom
->color(FL_GREEN);

    grpBottom
->end();



    win
->resizable(win);



    tile
->end();

    win
->end();

    win
->show();

   
return Fl::run();

}




Btw.. What's your personal preferred way of accessing the forums these days? I had to use a web browser (which I don't like) to post this message since it bounced when emailing fltkg...@googlegroups.com (which I think I used earlier).


Albrecht Schlosser

unread,
Mar 9, 2018, 9:29:42 AM3/9/18
to fltkg...@googlegroups.com
On 09.03.2018 09:42 Daniel Polski wrote:
>
> Btw.. What's your personal preferred way of accessing the forums these
> days? I had to use a web browser (which I don't like) to post this
> message since it bounced when emailing fltkg...@googlegroups.com
> (which I think I used earlier).

I'm using an email client (thunderbird) and this works well for me.

You should be able to send mails to fltkg...@googlegroups.com, Your
email address (the same you used here) is registered with status
"posting allowed". Your delivery status is set to "No email" though so
you won't get emails from the list.

PS: Can't say anything to the original subject, but I hope someone else
will chime in...

Greg Ercolano

unread,
Mar 9, 2018, 11:42:40 AM3/9/18
to fltkg...@googlegroups.com
On 03/09/18 00:42, Daniel Polski wrote:
> My goal is to have the table columns Y position "stick" to the
> tables menu bar, but as you see in the example the magenta fields
> height grows & shrinks when you drag the tiled red & green groups.

You were close; just add this one line to make it work:

:
menuResizeLock->resizable(NULL);
grpWrapper->resizable(this); // <-- ADD THIS
grpWrapper->end();
:

You need to tell the grpWrapper group which item you want
to stretch during resize -- in this case, the table widget.

> Btw.. What's your personal preferred way of accessing the forums these days?

I use the mailing list. Posts come into my email, and I have a mail filter
that organizes them into a folder. I just reply to messages. When I want to
post a new message, I just compose a message To:fltkg...@googlegroups.com.

Any mail client should work. I use thunderbird, but any mail client should work.
Reply all
Reply to author
Forward
0 new messages