Discussion:
Fl_Tabs: How to find the tab that is clicked upon
testalucida
2013-03-25 12:16:27 UTC
Permalink
Hi,
imagine a Fl_Tabs instance with only one "card".
Clicking on its tab will not result in a callback action.
Catching the FL_PUSH event provides the position of the mouse-click but I don't know the click occuring within the tab or somewhere right of it.
Is there a way how to get the tab giving the click-position?

That's what I mean:
_____
/ x\ o

I'm interested in click "x" but not in click "o".

I found a variable named Fl_Tabs::tab_pos containing an array of tab-offsets but it is not accessible.

Thanks for your help
MacArthur, Ian (Selex ES, UK)
2013-03-25 13:02:19 UTC
Permalink
Post by testalucida
imagine a Fl_Tabs instance with only one "card".
Clicking on its tab will not result in a callback action.
Catching the FL_PUSH event provides the position of the mouse-click but
I don't know the click occuring within the tab or somewhere right of
it.
Is there a way how to get the tab giving the click-position?
_____
/ x\ o
I'm interested in click "x" but not in click "o".
I found a variable named Fl_Tabs::tab_pos containing an array of tab-
offsets but it is not accessible.
Might be possible to derive your own Fl_Tab widget and use that to add an access method for the tab_pos array. Or indeed, the derived tab widget might be made to respond by calling its callback in response to clicks even when there is only one tab active...


I would say that a tab with only one entry is maybe an unusual case to actually *need* to detect the click: Can you explain what you are trying to achieve here? Maybe if you can describe the objective, someone will have an idea how to get there.

For example, you could make your own tab-like widget out of a stack of groups, each with an associated button - the button callback would show its group and hide all the others, of course, (that's really all the Fl_Tab does anyway) but the button callback would still fire even if only one "tab" was active... Might be easy to implement (indeed ISTR the unittests example in the tests folder does basically that already.)




Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Greg Ercolano
2013-03-25 14:43:51 UTC
Permalink
Post by testalucida
_____
/ x\ o
I'm interested in click "x" but not in click "o".
What Ian said, and I'd offer that setting when(FL_WHEN_NOT_CHANGED)
/should/ work for your case, but does not.

This is probably a bug in Fl_Tabs; I opened STR#2939 <http://fltk.org/str.php?L2939>
and suggested a patch there which makes that work, e.g.

Index: Fl_Tabs.cxx
===================================================================
--- Fl_Tabs.cxx (revision 9847)
+++ Fl_Tabs.cxx (working copy)
@@ -173,11 +173,14 @@
Fl::focus(this);
redraw_tabs();
}
- if (o && value(o)) {
- Fl_Widget_Tracker wp(o);
- set_changed();
- do_callback();
- if (wp.deleted()) return 1;
+ if (o) {
+ int change = value(o);
+ if (change || (when() & FL_WHEN_NOT_CHANGED)) {
+ Fl_Widget_Tracker wp(o);
+ if (change) set_changed();
+ do_callback();
+ if (wp.deleted()) return 1;
+ }
}
Fl_Tooltip::current(o);
} else {
MacArthur, Ian (Selex ES, UK)
2013-03-25 14:55:19 UTC
Permalink
Post by Greg Ercolano
Post by testalucida
_____
/ x\ o
I'm interested in click "x" but not in click "o".
What Ian said, and I'd offer that setting when(FL_WHEN_NOT_CHANGED)
/should/ work for your case, but does not.
Yes; I tried that too, to no avail...

However, I now think we may be missing a real easy trick here.

Fl_Tabs has an (apparently undocumented) public method which() that takes (int event_x, int event_y) and returns non-zero if it hits a valid tab...

Well, I think that's what it does, anyway...

So, harking back to testalucida's original query, he had the event positions from his handle() method, so this might be enough to get him sorted out?
Post by Greg Ercolano
This is probably a bug in Fl_Tabs; I opened STR#2939
<http://fltk.org/str.php?L2939>
and suggested a patch there which makes that work, e.g.
Looks about right - though I do wonder if it is a bug or not?
Do we want to be able to "reselect" an already selected tab? Dunno...

Though if FL_WHEN_NOT_CHANGED is set, maybe it should allow the tab to be reselected...?



Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
chris
2013-03-25 14:49:22 UTC
Permalink
You could perhaps use the method:

Fl_Widget * Fl_Tabs::which (int event_x, int event_y)

in your derived handle().

e.g.

int handle( int e)
{
if (e==FL_PUSH)
{
if ( which(Fl::event_x(), Fl::event_y() )
{
// pushed into the 'x'-region
}
else
{
// pushed into the 'o'-region
}
}
...
}
Post by testalucida
Hi,
imagine a Fl_Tabs instance with only one "card".
Clicking on its tab will not result in a callback action.
Catching the FL_PUSH event provides the position of the mouse-click but I don't know the click occuring within the tab or somewhere right of it.
Is there a way how to get the tab giving the click-position?
_____
/ x\ o
I'm interested in click "x" but not in click "o".
I found a variable named Fl_Tabs::tab_pos containing an array of tab-offsets but it is not accessible.
Thanks for your help
testalucida
2013-03-25 14:53:03 UTC
Permalink
Hi Ian,
excuse me bothering you... it's much easier than I thougt: I just overlooked the which( x, y ) method which exactly fits my needs.

Thanks for answering.
Post by testalucida
imagine a Fl_Tabs instance with only one "card".
Clicking on its tab will not result in a callback action.
Catching the FL_PUSH event provides the position of the mouse-click but
I don't know the click occuring within the tab or somewhere right of
it.
Is there a way how to get the tab giving the click-position?
=
_____
/ x\ o
=
I'm interested in click "x" but not in click "o".
=
I found a variable named Fl_Tabs::tab_pos containing an array of tab-
offsets but it is not accessible.
Might be possible to derive your own Fl_Tab widget and use that to add an a=
ccess method for the tab_pos array. Or indeed, the derived tab widget might=
be made to respond by calling its callback in response to clicks even when=
there is only one tab active...
I would say that a tab with only one entry is maybe an unusual case to actu=
ally *need* to detect the click: Can you explain what you are trying to ach=
ieve here? Maybe if you can describe the objective, someone will have an id=
ea how to get there.
For example, you could make your own tab-like widget out of a stack of grou=
ps, each with an associated button - the button callback would show its gro=
up and hide all the others, of course, (that's really all the Fl_Tab does a=
nyway) but the button callback would still fire even if only one "tab" was =
active... Might be easy to implement (indeed ISTR the unittests example in =
the tests folder does basically that already.)
Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS=
14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Greg Ercolano
2013-03-26 02:01:37 UTC
Permalink
Post by testalucida
I just overlooked the which( x, y ) method which exactly fits my needs.
Great -- yes, it's easy to miss, because it wasn't documented! ;)
Fixed in r9849:

-------------------------------------------------------------------------
Fl_Widget * Fl_Tabs::which(int event_x,
int event_y
)

Return the widget of the tab the user clicked on at event_x / event_y.
This is used for event handling (clicks) and by fluid to pick tabs.

Returns:
The child widget of the tab the user clicked on, or
0 if there are no children or if the event is outside of the tabs area.
-------------------------------------------------------------------------

Noticed push() wasn't documented either; put a \todo stand in
marker for now..

testalucida
2013-03-25 18:16:57 UTC
Permalink
thank you guys for caring about my problem

have a nice day

testalucida
Post by MacArthur, Ian (Selex ES, UK)
Post by Greg Ercolano
Post by testalucida
_____
/ x\ o
I'm interested in click "x" but not in click "o".
=
What Ian said, and I'd offer that setting when(FL_WHEN_NOT_CHANGED)
/should/ work for your case, but does not.
Yes; I tried that too, to no avail...
However, I now think we may be missing a real easy trick here.
Fl_Tabs has an (apparently undocumented) public method which() that takes (=
int event_x, int event_y) and returns non-zero if it hits a valid tab...
Well, I think that's what it does, anyway...
So, harking back to testalucida's original query, he had the event position=
s from his handle() method, so this might be enough to get him sorted out?
Post by Greg Ercolano
=
This is probably a bug in Fl_Tabs; I opened STR#2939
<http://fltk.org/str.php?L2939>
and suggested a patch there which makes that work, e.g.
Looks about right - though I do wonder if it is a bug or not?
Do we want to be able to "reselect" an already selected tab? Dunno...
Though if FL_WHEN_NOT_CHANGED is set, maybe it should allow the tab to be r=
eselected...?
Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS=
14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Loading...