Fl_Group and button callback issues

11 views
Skip to first unread message

Karl Harbinger

unread,
Sep 29, 2016, 11:44:36 AM9/29/16
to fltk.general
I want my window to be resizable without stretching the buttons.
When I uncomment the buttongroup part below, the buttons aren't stretched, but I can't press the buttons anymore.
What am I missing?


#include <FL/Fl.H>
#include <FL/fl_ask.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Return_Button.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Window.H>

#include <string>
#include <iostream>
#include <stdlib.h>

int check_button_count = 4;

static void cb_exit0_cb(Fl_Widget*)
{
 
exit(0);
}

static void cb_exit1_cb(Fl_Widget*)
{
 
exit(1);
}

int main(int argc, char **argv)
{
 
Fl_Window        *win;
 
Fl_Group         *g, *g_inside, *buttongroup;
 
Fl_Box           *invisible;
 
Fl_Return_Button *but_ok;
 
Fl_Button        *but_cancel;

 
int winh = 30*check_button_count + 56;

  win
= new Fl_Window(420, winh, "Select your options");
  win
->callback(cb_exit1_cb);
 
{
    g
= new Fl_Group(0, 0, 420, winh-16);
   
{
      g_inside
= new Fl_Group(0, 0, 420, winh-16);
     
{
       
for (int i = 0; i < check_button_count; ++i)
       
{
         
new Fl_Check_Button(10, 10 + 30*i, 400, 30, "test");
       
}
     
}
      g_inside
->end();
   
}
    g
->resizable(g_inside);
    g
->end();

   
//buttongroup = new Fl_Group(0, winh-16, 420, 36);
   
//{
      invisible
= new Fl_Box(199, winh-16, 1, 26);
      but_ok
= new Fl_Return_Button(220, winh-36, 90, 26, fl_ok);
      but_ok
->callback(cb_exit0_cb);
      but_cancel
= new Fl_Button(320, winh-36, 90, 26, fl_cancel);
      but_cancel
->callback(cb_exit1_cb);
   
//}
   
//buttongroup->resizable(invisible);
   
//buttongroup->end();
 
}
  win
->resizable(g);
  win
->end();
  win
->show();

 
return Fl::run();
}


Ian MacArthur

unread,
Sep 29, 2016, 12:36:07 PM9/29/16
to fltkg...@googlegroups.com
On Thu Sep 29 2016 16:44:36, Karl Harbinger wrote:
> I want my window to be resizable without stretching the buttons.
> When I uncomment the buttongroup part below, the buttons aren't stretched, but I can't press the buttons anymore.
> What am I missing?

Your buttons are positioned (mostly) outside their parent group, so don’t get any clicks...

You can try setting all of your groups to have grp->box(FL_BORDER_BOX); to see where things lie, then its pretty clear what’s up.

I’ll post a hacked up tweak in a few minutes...



Ian MacArthur

unread,
Sep 29, 2016, 12:45:26 PM9/29/16
to fltkg...@googlegroups.com
OK, here you go.

Changes:

- I’ve adjusted the group sizes to put your buttons “inside” their parent
- I’ve made the exit callbacks hide the parent win, rather than just bombing on exit()
- I’ve added a dummy widget to the check box group to eat the resizing there too
- I’ve explicitly set the box type of the groups and “invisible” widgets, to make it more explicit what’s going on

Seems to work...

Build with fltk-config --compile...


#include <FL/Fl.H>
#include <FL/fl_ask.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Return_Button.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Window.H>

#include <string>
#include <iostream>
#include <stdlib.h>

static int check_button_count = 4;
static Fl_Window *win;

static void cb_exit0_cb(Fl_Widget*)
{
win->hide();
}

static void cb_exit1_cb(Fl_Widget*)
{
win->hide();
}

int main(int argc, char **argv)
{
Fl_Group *g, *g_inside, *buttongroup;
Fl_Box *invisible;
Fl_Return_Button *but_ok;
Fl_Button *but_cancel;

int winh = (30 * check_button_count) + 56;
int mod_h = winh - 40;

win = new Fl_Window(420, winh, "Select your options");
win->callback(cb_exit1_cb);
{
g = new Fl_Group(0, 0, 420, mod_h);
{
g_inside = new Fl_Group(0, 0, 420, mod_h);
{
for (int i = 0; i < check_button_count; ++i)
{
new Fl_Check_Button(10, 10 + 30*i, 400, 30, "test");
}
}
Fl_Box *dummy2 = new Fl_Box (418, mod_h - 2, 1, 1);
dummy2->box(FL_NO_BOX);
g_inside->resizable(dummy2);
g_inside->end();
g_inside->box(FL_BORDER_BOX);
}
g->resizable(g_inside);
g->end();
g->box(FL_BORDER_BOX);

buttongroup = new Fl_Group(0, mod_h, 420, 36);
{
invisible = new Fl_Box(199, mod_h, 1, 1);
invisible->box(FL_NO_BOX);
but_ok = new Fl_Return_Button(220, mod_h + 4, 90, 26, fl_ok);
but_ok->callback(cb_exit0_cb);
but_cancel = new Fl_Button(320, mod_h + 4, 90, 26, fl_cancel);
but_cancel->callback(cb_exit1_cb);
}
buttongroup->resizable(invisible);
buttongroup->end();
buttongroup->box(FL_BORDER_BOX);
}
win->resizable(g);
win->end();
win->show();

return Fl::run();
}

/* end of file */





Karl Harbinger

unread,
Sep 30, 2016, 2:46:49 AM9/30/16
to fltk.general
Thanks, you really helped me there.
Reply all
Reply to author
Forward
0 new messages