FLTK logo

Re: [fltk/fltk] possible incoherence in Fl_Tree_Item drawing (Issue #298)

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.issues  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: [fltk/fltk] possible incoherence in Fl_Tree_Item drawing (Issue #298) erco77 Nov 28, 2021  
 

There's a few ways to parse events for items:

  • The tree's callback
  • The tree's handle() method

The callback approach is perhaps easier, saves a little work by avoiding having to derive a class from Fl_Tree and do any event handle() stuff.

So to do that, I expect you'd configure a callback for the tree, and set it up so the callback is invoked whenever there's a click, e.g.

Fl_Tree *tree = new Fl_Tree(..);
tree->callback(MyTree_CB);                           // tree callback (userdata optional)
tree->when(FL_WHEN_CHANGED|FL_WHEN_RELEASE);         // when to invoke callback
tree->item_reselect_mode(FL_TREE_SELECTABLE_ALWAYS); // callback even when reselected

Then in the callback you can get the item clicked with tree->callback_item(), and the reason for the callback with tree->callback_reason() (e.g. 'selected', 'reselected', 'deselected', etc), and then using the item returned by callback_item(), invoke your own custom Fl_Tree_Item's method, e.g. MyTreeItem::my_handle(), so the item can handle click events on it.

From there you should be able to use e.g. Fl::event_x() to determine where on the item the click occurred and if it happened over one of your drawn indicators (e.g. the eyeball icon), and toggle the icon's xpm to affect its state and how it draws, and use Fl::event() to determine if it was a push or release, etc.

I can try to whip up an example and follow up maybe tomorrow, but pretty sure something along those lines should work.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

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'.