Re: [fltk.general] RFC: Tracking the focus widget - would this be useful ?

2013-01-06 Thread Greg Ercolano
On 01/04/13 05:22, Albrecht Schlosser wrote:
 I'd like to know if there are more FLTK users who have the need
 to track the widget that currently has the focus.

I wouldn't be against it.. sounds reasonable.

 I could imagine something like a callback that could be called
 whenever the current focus widget (Fl::focus()) changes. This
 could be something like:
 
Fl::register_focus[_tracking] (my_widget,callback,arg)

Seems like:

Fl::add_focus_callback(cb, data);
Fl::remove_focus_callback(cb,data);

..would make sense.

void callback (Fl_Widget *w, long or void * arg, Fl_Widget *focus)
 The last argument is just to avoid calling Fl::focus() each time
 the callback is called, but could also be removed. 

I'd prefer the user's callback code do the Fl::focus() call
(if it needs it) rather than a third arg so as to be consistent
with Fl_Callback and it's always easier to remember shorter arg lists.

Plus whatever few cycles are saved by preventing the user from calling
Fl::focus() are probably undone by the stack manipulations of handling
a third arg in the callback..
___
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk


Re: [fltk.general] RFC: Tracking the focus widget - would this be useful ?

2013-01-06 Thread Albrecht Schlosser
On 06.01.2013 09:01, Greg Ercolano wrote:
 On 01/04/13 05:22, Albrecht Schlosser wrote:
 I'd like to know if there are more FLTK users who have the need
 to track the widget that currently has the focus.

   I wouldn't be against it.. sounds reasonable.

 I could imagine something like a callback that could be called
 whenever the current focus widget (Fl::focus()) changes. This
 could be something like:

 Fl::register_focus[_tracking] (my_widget,callback,arg)

   Seems like:

   Fl::add_focus_callback(cb, data);
   Fl::remove_focus_callback(cb,data);

   ..would make sense.

 void callback (Fl_Widget *w, long or void * arg, Fl_Widget *focus)
 The last argument is just to avoid calling Fl::focus() each time
 the callback is called, but could also be removed.

   I'd prefer the user's callback code do the Fl::focus() call
   (if it needs it) rather than a third arg so as to be consistent
   with Fl_Callback and it's always easier to remember shorter arg lists.

Agreed, 100%. All good points.

   Plus whatever few cycles are saved by preventing the user from calling
   Fl::focus() are probably undone by the stack manipulations of handling
   a third arg in the callback..

Yep, you're right, thanks. Calling Fl::focus() is a simple pointer
assignment, usually handled inline:

 From FL/Fl.H:
static Fl_Widget* focus() {return focus_;}

Note also that I currently believe that the first argument I had in my
register... method should be dropped, because it's useless or redundant.
If someone would want to save the widget that is interested in the focus
change somewhere, s/he could use the data arg for this or save it
elsewhere.

Albrecht

___
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk


Re: [fltk.general] RFC: Tracking the focus widget - would this be useful ?

2013-01-05 Thread Denton Thomas
 All,

 I'd like to know if there are more FLTK users who have the need
 to track the widget that currently has the focus. If this was a
 common problem, we could probably add something to FLTK to make
 this easier. It's not easy with current FLTK methods, as can be
 seen in the current discussion with the title scroll to focus
 in Fl_Scroll in fltk.general.


I, for one, agree. Having a focus callback would be handy. Currently, I 
template/subclass every widget that I need to have this sort of ability.

If others are interested, and the weight of the additional code is trivial, I 
think it's worth it.

Denton
___
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk


[fltk.general] RFC: Tracking the focus widget - would this be useful ?

2013-01-04 Thread Albrecht Schlosser
All,

I'd like to know if there are more FLTK users who have the need
to track the widget that currently has the focus. If this was a
common problem, we could probably add something to FLTK to make
this easier. It's not easy with current FLTK methods, as can be
seen in the current discussion with the title scroll to focus
in Fl_Scroll in fltk.general.

http://www.fltk.org/newsgroups.php?gfltk.general+Q%22scroll+to+focus+in+Fl_Scroll%22


I could imagine something like a callback that could be called
whenever the current focus widget (Fl::focus()) changes. This
could be something like:

   Fl::register_focus[_tracking] (my_widget,callback,arg)

to register interest in focus changes. In this case, each focus
change would call the callback function like this:

   void callback (Fl_Widget *w, long or void * arg, Fl_Widget *focus)

The last argument is just to avoid calling Fl::focus() each time
the callback is called, but could also be removed. The first
argument would be the widget (my_widget) the callback was
registered for (this could also be NULL, if my_widget was NULL
in the call to register_focus[...].

... or something like that ...

Any ideas, comments, wishes ?

Albrecht

___
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk