Greg Ercolano wrote:
>       Or, make an invisible box using the techniques described above
>       to disable resizing of the tree in the one direction you want.

    Here's an example showing how to do that, since it may seem unclear.

    This program makes two separate windows; one where the tree resizes
    only on its width, the other only on its height.

    In both cases the buttons are 'locked' (don't move or resize)
    to show how the behavior can be restricted to just the tree widget.


#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Tree.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
//
// Demonstrate limiting a widget's resizing to just width or height. -erco 
11/29/10
//
//     Open two resizable windows: one where window resizing only affects the
//     the tree widget's width, the other only affects the tree widget's height.
//     In both cases, the extra buttons (A and B) are 'locked down' to show how
//     the resize behavior's influence can be limited to just the tree widget.
//
void ResizeTreeWidthOnly() {
  // Desired behavior:
  //     Force buttons to not change or move at all, while allowing tree
  //     to resize in width only.
  // Technique:
  //     Position a resizer widget below the tree so that only the tree's
  //     width can change. Since we don't want the buttons to move,
  //     but they are above the tree, we protect them from the resizer's
  //     influence by putting them in a group, and disabling the group's 
resizable().
  //
  Fl_Double_Window *win = new Fl_Double_Window(230, 300, "Resize Tree Width 
Only");
  win->begin();
  Fl_Group *grp = new Fl_Group(10,10,210,45);
  grp->box(FL_FLAT_BOX); grp->color(47);        // make group box slightly 
visible so we can see it (debugging)
  grp->begin();
      new Fl_Button(10, 10,100,25,"A");
      new Fl_Button(120,10,100,25,"B");
  grp->end();
  grp->resizable(0);                            // protect buttons from any 
resizing behavior
  Fl_Tree *tree = new Fl_Tree(10,50,210,240);
  tree->add("Flintstones/Fred");
  tree->add("Flintstones/Wilma");
  tree->add("Simpsons/Homer");
  tree->add("Simpsons/Marge");
  Fl_Box *win_resizer = new Fl_Box(10,295,210,2);
  win_resizer->box(FL_FLAT_BOX);                // make the resizer visible as 
a red box (debugging)
  win_resizer->color(FL_RED);
  win->end();
  win->resizable(win_resizer);                  // assign red resizer box as 
window's resizable
  win->show();
}

void ResizeTreeHeightOnly() {
  // Desired behavior:
  //     Force buttons to not change or move at all, while allowing tree
  //     to resize in height only.
  // Technique:
  //     Prevent buttons from resizing and limit tree to only resize
  //     on the vertical by placing a tiny resizer box at the far right of the 
tree,
  //     and making it the window's resizable.
  //
  //     This has the effect of:
  //         1) Preventing the buttons from resizing or moving at all;
  //            the resizer box acts as the 'spring' that absorbs resizing
  //            behavior away from widgets that are not opposite its edges.
  //
  //         2) Since the tree is opposite the resizer's left edge,
  //            the resizer limits the tree widget to only do vertical resizing.
  //
  Fl_Double_Window *win = new Fl_Double_Window(230, 300, "Resize Tree Height 
Only");
  win->begin();
  new Fl_Button(10, 10,100,25,"A");
  new Fl_Button(120,10,100,25,"B");
  Fl_Box *win_resizer = new Fl_Box(225,50,2,240);
  win_resizer->box(FL_FLAT_BOX);                // make the resizer visible as 
a red box (debugging)
  win_resizer->color(FL_RED);
  Fl_Tree *tree = new Fl_Tree(10,50,210,240);
  tree->add("Flintstones/Fred");
  tree->add("Flintstones/Wilma");
  tree->add("Simpsons/Homer");
  tree->add("Simpsons/Marge");
  win->end();
  win->resizable(win_resizer);                  // assign red resizer box as 
window's resizable
  win->show();
}

int main(int argc, char *argv[]) {
  Fl::scheme("gtk+");
  ResizeTreeWidthOnly();
  ResizeTreeHeightOnly();
  return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to