FLTK logo

Re: Resizing behaviour of nested widgets

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

Re: Resizing behaviour of nested widgets Greg Ercolano Aug 22, 2011  
 
On 08/22/11 18:31, Greg Ercolano wrote:
> On 08/22/11 14:49, Jeff Paranich wrote:
>> Hi All,
>>
>> I've read "Article 415: How Does Resizing Work?" and have been battling with trying to get one of my windows to behave how I'd like.  I have done a mock sketch of my interface... it can be viewed here:
>>
>> http://i56.tinypic.com/2i94b4z.png
>>
>> The behavior I'm seeking may not be possible in FLTK, but I was hoping that in the picture where Fl_Hold_Browser is located, that the right-face of the widget (highlighted in yellow) would be clickable and could be resized horizontally, and in doing so Fl_Box, Fl_Table_Row, and Fl_Text_Display would be compressed.  And with this functionality, Fl_Window should still be resizable however when resized Fl_Hold_Browser would remain horizontally fixed but can stretch vertically, and all other widgets resize both horizontally and vertically.
>>
>> Hope this makes sense.  Is this or something very similar achievable?
> 
> 	Sounds like you should use Fl_Tile to manage the resizable aspect
> 	in this case.
> 
> 	I'd suggest putting all that stuff to the right of the yellow bar
> 	in a group, and make an Fl_Tile that contains the hold browser (left of yellow bar)
> 	and the aforementioned group (to the right of the yellow bar), and have
> 	the edges common so that when you glide over the border between the two,
> 	Fl_Tile will let you interactively resize them.


    Here's the above implemented as code.

    To get Fl_Tile to act as a "resizer", it's important that the tile's
    two children (the "hold" browser and the "group") have their common edges
    /touching/ each other. This causes Fl_Tile to make this boundary mouse
    sensitive to interactive resizing.

    I was lazy and left out the two widgets at the lower-right, cause
    their behavior will just be an extension of the others.

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Tile.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Table_Row.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Hold_Browser.H>

int main() {
    Fl_Window *win = new Fl_Window(400,500);

    Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
    menu->add("File/Foo");
    menu->add("Edit/Bar");

    Fl_Tile *tile = new Fl_Tile(10,menu->y()+menu->h()+10,
                                400-20, 500-(menu->y()+menu->h()+10)-10);
    tile->box(FL_FLAT_BOX);
    tile->color(9);
    tile->begin();

        Fl_Hold_Browser *hold = new Fl_Hold_Browser(10,40,150-10,500-40-10);
        hold->add("One");
        hold->add("Two");
        hold->add("Three");

        Fl_Group *group = new Fl_Group(150,40,400-150-10, 500-40-10);
        group->box(FL_FLAT_BOX);
        group->color(FL_BLUE+8);
        group->begin();

            Fl_Box *box = new Fl_Box(group->x()+10,40,400-(group->x()+10)-10,25,"Fl_Box");
            box->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER);
            box->box(FL_FLAT_BOX);
            box->color(FL_GREEN+8);

            Fl_Table_Row *table = new Fl_Table_Row(box->x(), box->y()+box->h()+10,
                                                   box->w(), group->h()-(box->h()+10));
        group->end();
        group->resizable(table);
    tile->end();

    win->resizable(tile);
    win->show();
    return(Fl::run());
}
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

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