FLTK logo

Re: [fltk.general] fltk resizable fixed height

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.general  ]
 
[ Previous Message ] [ New Message | Reply ] [ Next Message ]

Re: fltk resizable fixed height "'Albrecht Schlosser' via fltk.general" Aug 22, 2025  
 
Title: Re: [fltk.general] fltk resizable fixed height
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..

--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkgeneral/8f07b52a-17d0-4571-9fdc-e0ee2bd14beb%40aljus.de.
[ Direct Link to Message ]
 
     
[ Previous Message ] [ New Message | Reply ] [ Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.