Re: Why doesn't FLTK provide access to a widget Tree?
Bill Spitzak
Jun 11, 2021
FLTK certainly uses a list of children and parent pointers just like any other tree representation. As stated above this system puts the "roots" at the level of the outermose Fl_Window objects.
It also knows about all the currently-shown windows in an internal list, I don't remember if that list is available, and there was some work done on making whether a window that was hidden or removed being in this list system-dependent. A window you create and then do nothing with will not be part of any internal tree, it will be it's own independent tree.
> I think your intuition about how fltk works may be
missing the mark, that’s not really how it is done at all.
Not really ... exactly ... but very similar, isn't it? At least for
single windows.
Understood,
coming from a Web Dev environment, and given the various parent()
and child() functions available to our FL::Group widgets, I
assumed that behind the scenes some sort of tree structure was
managing these relationships. If this is not how it works, then
what kind of system FLTK use to keep track of parent/child
relationships?
There's not one complete tree structure, but for each Fl_Group
(derived) widget there is an array of children, and a Fl_Group
widget may have a parent() with an Fl_Window as the top-most parent.
However, ...
The F and L refer to Fast and Light. So
stuff like you are asking for is an overhead most users
might not want. It should be easy enough for you to
implement that if you want.
Just wondering, why doesn't FLTK
provide access to a global widget tree? Behind the
scenes, does FLTK not use a tree like structure to
represent the relationship between widgets, in a
fashion similar to HTML?
A simple widget tree for an FLTK app might look
like:
That tree is not for a complete FLTK app, but for a single
Fl_Window, yes.
________________________________
Window
/ \
Group Group
/\ \
Button Button Button
________________________________
Wouldn't it be great to have access to the FL_Tree
functions like root(), insert_above(), set_root(),
prev(), next(), etc for all of our widgets?
As Ian wrote, there's no "master" tree, widgets are independent and
can be moved around and there can be lots of independent (or
dependent) windows coming and going (like menu windows) etc..
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.