Fl_Tree

39 views
Skip to first unread message

holm.h...@gmail.com

unread,
Sep 7, 2017, 4:31:58 PM9/7/17
to fltk.general

Hello,

The callbacks for Fl_Tree works for left mouse button, according to http://www.fltk.org/doc-1.3/classFl__Tree.html

Would it be possible to have a callback also for the right mouse button ?

I want to achieve :
 The user should click left button to mark start of a selection, and right button to mark end of selection

Any ideas ?

Best regards
Håvard

Greg Ercolano

unread,
Sep 7, 2017, 5:11:34 PM9/7/17
to fltkg...@googlegroups.com
You can derive your own class, overloading the handle() method
and look for these events to change the selections using Fl_Tree's
selection methods.

holm.h...@gmail.com

unread,
Oct 7, 2017, 6:24:41 AM10/7/17
to fltk.general

Hi,
Deriving my own class and overloading the handle method is ok, but I run into problems, when to change the selections.
How to find which item was clicked ?
Do I have to check coordinates of mouse / coordinates of each item in the tree ?

Best regards
Håvaard

Greg Ercolano

unread,
Oct 7, 2017, 11:47:53 AM10/7/17
to fltkg...@googlegroups.com
On 10/07/17 03:24, holm.h...@gmail.com wrote:
>
> Hi,
> Deriving my own class and overloading the handle method is ok, but I run into problems, when to change the selections.
> How to find which item was clicked ?

Quoting the docs:

Fl_Tree_Item * Fl_Tree::callback_item()
http://www.fltk.org/doc-1.3/classFl__Tree.html#ad576e00b3f3c5e2c6dae62fdf513ece2
"""
Gets the item that caused the callback.
The callback() can use this value to see which item changed.
"""

Also, although deprecated:

Fl_Tree_Item * item_clicked ()
http://www.fltk.org/doc-1.3/classFl__Tree.html#a719f3595b8e7a855ed0890cb7e6fdc67
"""
Return the item that was last clicked.
Valid only from within the callback().
Returns
The item clicked, or 0 if none. 0 may also be used to indicate several items were clicked/changed.
*Deprecated: in 1.3.3 ABI – use callback_item() instead.*
"""

And finally, if you want /all/ the selected items (e.g. with multi-mode, the user
can select several items), from the Fl_Tree docs introduction:

"""
You can walk selected items with first_selected_item() and next_selected_item().
"""
http://www.fltk.org/doc-1.3/classFl__Tree.html#a10f283a50a1e627ba2bf972c8b107a87
http://www.fltk.org/doc-1.3/classFl__Tree.html#a63bdc369548cc4287ee633c92ada9af9

> Do I have to check coordinates of mouse / coordinates of each item in the tree ?

No.. please review the docs, as there's many details there, both for Fl_Tree
and Fl_Tree_Item, and the preferences for the tree in Fl_Tree_Prefs:

http://www.fltk.org/doc-1.3/classFl__Tree.html
http://www.fltk.org/doc-1.3/classFl__Tree__Item.html
http://www.fltk.org/doc-1.3/classFl__Tree__Prefs.html

Also, there's /several/ demos, probably more than most widgets, with code examples:

examples/tree-as-container.cxx
examples/tree-custom-draw-items.cxx
examples/tree-custom-sort.cxx
examples/tree-of-tables.cxx
examples/tree-simple.cxx



holm.h...@gmail.com

unread,
Oct 9, 2017, 11:57:59 AM10/9/17
to fltk.general
Thank you - again :-)

Worked out fine.

Best regards
Håvard

Reply all
Reply to author
Forward
0 new messages