fltk resizable fixed height

16 views
Skip to first unread message

danielc...@gmail.com

unread,
Aug 22, 2025, 5:59:38 AMAug 22
to fltk.general
Hi,
How to resize a subwindow only the width, keeping is height fixed?
win->resizable(??)
Thanks

Ian MacArthur

unread,
Aug 22, 2025, 6:28:57 AMAug 22
to fltk.general
Programmatically, you mean?
Can you not just do something like:

int old_h - win->h();
win->size (new_w, old_h);

I think that'd work...


As an aside, there's a typo in the Fl_Window docs., when I went to look this up to check, I saw:

<quote from docs>

You can also call the Fl_Widget methods size(x,y) and position(w,h), which are inline wrappers for this virtual function.

<endquote>

Which threw me as the params to size() and position() are swapped about, i.e. it _should_ be...

You can also call the Fl_Widget methods size(w,h) and position(x,y), which are inline wrappers for this virtual function.

FWIW, I think that's been back-to-front for a very long time, too. We never noticed!

 

Ian MacArthur

unread,
Aug 22, 2025, 6:29:56 AMAug 22
to fltk.general
On Friday, 22 August 2025 at 11:28:57 UTC+1 Ian MacArthur wrote:

int old_h - win->h();

bother...

int old_h  =  win->h();


danielc...@gmail.com

unread,
Aug 22, 2025, 6:36:09 AMAug 22
to fltk.general
I mean on resize main window.
subwindow->resizable(mainwindow);
resizes width and height.
I want that width resize but keep height fixed.
Thanks

pvr...@btinternet.com

unread,
Aug 22, 2025, 7:51:29 AMAug 22
to fltkg...@googlegroups.com
Daniel,
If I recall correctly, the suggestion is 

win->resizable(nullptr);
win->size(new_width, win->h());

Regards Phil.

Ian MacArthur

unread,
Aug 22, 2025, 9:06:48 AMAug 22
to fltk.general
On Friday, 22 August 2025 at 11:36:09 UTC+1 daniel wrote:
I mean on resize main window.
subwindow->resizable(mainwindow);
resizes width and height.
I want that width resize but keep height fixed.
Thanks

This line looks odd to me:

subwindow->resizable(mainwindow);

That seems to be saying you have set the mainwindow to be the resizable of the subwindow?
That seems back to front, surely? The resizable widget is typically some child of the enclosing group/window, so I don't understand how the mainwindow can be a child of the subwindow.

Anyway, that aside, if you need more complex control of resizing behaviour and layout, it might be worth looking at some of the newer layout widgets like Fl_Flex to see if they can achieve the effect you want here.

Gonzalo Garramuño

unread,
Aug 22, 2025, 12:10:52 PMAug 22
to fltkg...@googlegroups.com


El 22/8/25 a las 8:51, 'pvr...@btinternet.com' via fltk.general escribió:
Daniel,

Hi,
How to resize a subwindow only the width, keeping is height fixed?
win->resizable(??)
Thanks

I could be wrong, but I think the OP means how to resize a subwindow manually keeping its height, not programmatically.

If so, he should read the FLTK manual section on "How Does Resizing Work":

https://www.fltk.org/doc-1.5/resize.html

-- 
ggar...@gmail.com

Albrecht Schlosser

unread,
Aug 22, 2025, 2:35:20 PMAug 22
to fltkg...@googlegroups.com
The OP's question was:

How to resize a subwindow only the width, keeping is height fixed?
win->resizable(??)

On 8/22/25 18:10 Gonzalo Garramuño wrote:

I could be wrong, but I think the OP means how to resize a subwindow manually keeping its height, not programmatically.

I agree, if "manually" means by resizing the main window with the mouse (by the user).



If so, he should read the FLTK manual section on "How Does Resizing Work":

https://www.fltk.org/doc-1.5/resize.html

I agree again, but it might be tricky to choose the right way...

The main point is here (AFAICT) that the "subwindow" is in FLTK's view just another widget inside the main window. This subwindow doesn't need to have a resizable() by itself, the only issue is to make the subwindow react on main window resizing as desired.

The "classic" resizing mechanism can be tricky. It's pretty easy if the subwindow occupies the full width of the main window and if it is at the top or bottom of the window. Let's assume the subwindow is at the top of the main window. Then it's as easy as having any other widget (maybe an invisible Fl_Box or an Fl_Group) below the subwindow. That widget becomes the resizable() of the main window. It doesn't even have to occlude the full width of the main window. Since the resizable() widget is below the subwindow it consumes all increases of the main window's height. However, all widgets in the main window are resized horizontally, and thus the subwindow resizes horizontally (width) but not vertically (width).

Working example code (tested):

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(600, 300);
Fl_Window *subwin = new Fl_Window(0, 0, 600, 200);
subwin->box(FL_FLAT_BOX);
subwin->color(FL_YELLOW);
Fl_Box *sbox = new Fl_Box(40, 40, subwin->w() - 80, subwin->h() - 80, "Box in subwin");
sbox->box(FL_FLAT_BOX);
sbox->color(FL_GREEN);
subwin->end();
subwin->resizable(subwin);
Fl_Box *box = new Fl_Box(0, 200, 600, 100, "window->resizable(this)");
box->box(FL_UP_BOX);
box->labelfont(FL_BOLD + FL_ITALIC);
box->labelsize(30);
window->end();
window->resizable(box);
window->size_range(400, 250); // not necessary, but good style to set this
window->show(argc, argv);
return Fl::run();
}

    If there are other widgets below and
    above the subwindow, then it becomes more complicated, and (as
    others wrote) using Fl_Flex and/or Fl_Grid would likely be a better choice.
    It's really worth studying these container widgets, and there are
    six (6!) example programs in test/grid*.cxx and test/flex*.cxx,
    resp..

Albrecht Schlosser

unread,
Aug 22, 2025, 2:41:23 PMAug 22
to fltkg...@googlegroups.com
On 8/22/25 12:28 Ian MacArthur wrote:
As an aside, there's a typo in the Fl_Window docs., when I went to look this up to check, I saw:

<quote from docs>

You can also call the Fl_Widget methods size(x,y) and position(w,h), which are inline wrappers for this virtual function.

<endquote>

Which threw me as the params to size() and position() are swapped about, i.e. it _should_ be...

Thanks, fixed in commit 53f103f2cad038ac7262b5ceecd3a0b837851b6d.

Gonzalo Garramuño

unread,
Aug 22, 2025, 3:30:08 PMAug 22
to fltkg...@googlegroups.com


El 22/8/25 a las 15:35, 'Albrecht Schlosser' via fltk.general escribió:
If there are other widgets below and above the subwindow, then it becomes more complicated, and (as others wrote) using Fl_Flex and/or Fl_Grid would likely be a better choice. It's really worth studying these container widgets, and there are six (6!) example programs in test/grid*.cxx and test/flex*.cxx, resp..
I admit I am an old timer, so I forget about your new widget additions to FLTK.  Fl_Flex is probably what he wants, as Ian said.
-- 
ggar...@gmail.com
Reply all
Reply to author
Forward
0 new messages