Make only the main window resizable ?

36 views
Skip to first unread message

Lucas Sanner

unread,
Jul 30, 2025, 12:49:32 AMJul 30
to fltk.general
Hi all,
I want my application's main window resizable but I also want all visible widgets retain fixed size and position.
This is what I've come up with so far:

void Change_CB(Fl_Widget *w, void *) {
    Fl_Menu_Bar *menu = (Fl_Menu_Bar*)w;
    Fl_Menu_Item *p;
    // Change submenu name
    p = (Fl_Menu_Item*)menu->find_item("Edit/Submenu");
    if ( p ) p->label("New Submenu Name");
    // Change item name
    p = (Fl_Menu_Item*)menu->find_item("Edit/New Submenu Name/Aaa");
    if ( p ) p->label("New Aaa Name");
}

void Quit_CB(Fl_Widget *, void *) {
    exit(0);
}

int main() {
    Fl_Window *win = new Fl_Double_Window(400,400);
    Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
    Fl_Menu_Bar *toolbar = new Fl_Menu_Bar(0,25,400,25);
    menu->add("File/Quit",   FL_CTRL+'q', Quit_CB);
    menu->add("Edit/Change", FL_CTRL+'c', Change_CB);
    menu->add("Edit/Submenu/Aaa");
    menu->add("Edit/Submenu/Bbb");

    Fl_Group *g = new Fl_Group(0,50,400,375);   // container for other widgets
    g->resizable(nullptr); // prevent children from being resized
    Fl_Button *button = new Fl_Button(25, 60, 150, 50, "Start");
    // put other widgets here
    g->end();

    // Add an invisible box to absorb resizing
    // It must be placed over the remaining space
    Fl_Box *filler = new Fl_Box(0, 50, 400, 350); // matches group size
    filler->hide(); // make it invisible
    win->resizable(filler); // set this box as the resizable area

    win->end();
    win->show();
    return(Fl::run());
}

It works (ie: the button is not resized while resizing the window).
However it's just a workaround and it looks a bit DIY to me.
Did I miss something ?
Is there a specific and cleaner way to achieve this ?

Thanks for your help.

Ian MacArthur

unread,
Jul 30, 2025, 3:36:53 AMJul 30
to fltk.general
On Wednesday, 30 July 2025 at 05:49:32 UTC+1 lucas wrote:
Hi all,
I want my application's main window resizable but I also want all visible widgets retain fixed size and position.

FWIW, I've generally done that using a series of nested groups to control the resize behaviour, sometimes with "dummy boxes" like you did to "capture" the "unwanted" resizing in some areas.
However, that can get messy quite quickly... And isn't always obvious when you look at it 3 months later either!

I don't have a clear idea of what you actually want to achieve, but I suspect that either FL_FLEX or FL_GRID might be useful here, since they are intended to help manage resize behaviour and layout.

Lucas Sanner

unread,
Jul 30, 2025, 5:27:40 AMJul 30
to fltk.general
Thanks for your help.
What I want to achieve is pretty simple: Allowing only the main window to get resized, all the other widgets in the app have to remain static in size and position, (not a big deal!).
But for whatever reason it takes a lot of workarounds to get the application working this way.
I'll have a look at FL_FLEX and FL_GRID, they may allow to do this in a cleaner way.

Albrecht Schlosser

unread,
Jul 30, 2025, 8:42:31 AMJul 30
to fltkg...@googlegroups.com
On 7/30/25 11:27 Lucas Sanner wrote:
What I want to achieve is pretty simple: Allowing only the main window to get resized, all the other widgets in the app have to remain static in size and position, (not a big deal!).
But for whatever reason it takes a lot of workarounds to get the application working this way.
I'll have a look at FL_FLEX and FL_GRID, they may allow to do this in a cleaner way.

At a first glance what you want to achieve looks like the opposite of the typical usage of Fl_Flex and Fl_Grid which automatically resize their children guided by some rules you can apply. However, both layout widgets allow to set some or all of their children to a fixed size (see documentation). Depending on your other widgets Fl_Flex and/or Fl_Grid might be useful for some parts of your layout nevertheless (I recommend to study and try them).

That said, in your case you don't need "a lot of workarounds". The only things you need to do are to set the resizable() of your Fl_Group g to nullptr (which you already did) and win->resizable(g) .

See my simplified and working example below:

```
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Button.H>
void Quit_CB(Fl_Widget *, void *) {
Fl::hide_all_windows();
}
int main() {
Fl_Window *win = new Fl_Double_Window(400,400);
Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
Fl_Menu_Bar *toolbar = new Fl_Menu_Bar(0,25,400,25);
menu->add("File/Quit", FL_CTRL+'q', Quit_CB);
menu->add("Edit/Change");
Fl_Group *g = new Fl_Group(0,50,400,375); // container for other widgets
new Fl_Button(25, 60, 150, 50, "Start");
new Fl_Button(50, 200, 150, 50, "Stop");
// put other widgets here
g->end();
win->end();
g->resizable(nullptr); // prevent resizing of children of the main group
win->resizable(g); // set the main group as the resizable of the window
win->size_range(300, 300); // recommended (optional): set minimal window size
win->show();
return(Fl::run());
}

```

At least this is what I think you wanted to achieve. Note that the toolbar will still be resized horizontally.
Note also that I recommend Fl::hide_all_windows(); instead of exit(0).

Using Fl_Flex or Fl_Grid wouldn't be easier (not less code) in this case, and the above given code seems reasonable and self-explanatory (if you read the comments).

Lucas Sanner

unread,
Jul 30, 2025, 11:31:01 AMJul 30
to fltk.general
Thanks for the code, it helped.
In the end, the dummy invisible box is unnecessary.
g->resizable(nullptr) and win->resizable(g) is all I need.
Reply all
Reply to author
Forward
0 new messages