FLTK logo

Re: Fl_Tree events

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: Fl_Tree events Greg Ercolano May 17, 2012  
 
On 05/17/12 11:56, Eugenio Bargiacchi wrote:
> get_item_focus() would certainly help.

	Try implementing it and see if it does.
	I'll certainly add it anyway, as it seems to be an omission.

> If I may suggest, you could also add FL_TREE_REASON_FOCUS_SELECTED
> and FL_TREE_REASON_FOCUS_DESELECTED as fields in the Fl_Tree_Reason enum,
> if the focus changed but the selected item did not.

	Sure, can investigate that.

> And maybe a couple of methods to setup which key/click triggers
> a focus change or a select change =)

	I don't think I'd do this with methods, as the default
	behavior needs to be consistent with other FLTK widgets
	for focus nav, ie. up/dn/lt/rt are best for this.

	Rather than clutter up the API with methods to change
	these, and have to have arrays of key values, I'd rather
	leave it to the app programmer to derive a class,
	handle() the events to get the keys they want, and
	make sure the API provides methods to change focus and
	change selection (which I think is already there; you
	have Fl_Tree::set_item_focus() and Fl_Tree::select(item))

> What do you suggest as a workaround for me while waiting on the next awesome release? Is the Fl_Button method the only way?
> 

	I'd suggest derive your own class from Fl_Tree,
	and make a handle() method catch FL_PUSH and check for
	the right mouse, and if so, determine the item and then
	Fl_Tree::select() it, eg:

    int handle(int e) {
        switch (e) {
            case FL_PUSH:
                if ( Fl::event_button() == FL_RIGHT_MOUSE ) {
                    Fl_Tree_Item *item = (Fl_Tree_Item*)find_clicked();
                    if ( item ) {
                        printf("*Right* click on item '%s'\n", item->label());
                        select(item);           // for example, select the item
                    }
                }
                break;
        }
        return(Fl_Tree::handle(e));
    }

	Your tree callback can then check if Fl::event_button() is FL_RIGHT_MOUSE
	and act accordingly.

	Or, just put the handling code in the above handle method.


> Many thanks!
> 
> 
> 
>> On 05/17/12 09:44, Eugenio Bargiacchi wrote:
>>> The problem is even if I were to reimplement handle() and make it trigger
>>> a callback, there would be no obvious way for me to get the focused item,
>>> since the pointer that holds that is private
>>
>> 	It looks like the Fl_Tree API has a public set_item_focus(),
>> 	but does not have a get_item_focus().
>>
>> 	Would having that help you?
>>
>> 	If so, I suggest adding one to the Fl_Tree.H file,
>> 	and if it helps you, follow up and I'll add it to 1.3.x.
>>
>> 	Fl_Tree is fairly young, so it's in active development,
>> 	and we're finding lots of new things to add to it.
>>
>>
> 
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'.