Detecting clicks in Segmented Control widget

Mike Bonner bonnmike at gmail.com
Wed Jan 25 14:44:55 EST 2017


If you don't mind the message on re-click being another "hiliteChanged"
message, you can tweak it on your own.

If you're on windows, go to your x86 programs folder/runrev/ then the
version you're using. Guessing 8.1.1.  Then extensions
Copy the segmented control folder out to where you can work on it safely
(and I renamed it to com.livecode.widget.segmented2)
Then with a text editor, edit the lcb file inside.

Change the metadata for the title to segmented control2 (or whatever)
Change the version (start at 1.0.0?)

Then find the onClick handler and make it look like this:

public handler OnClick() returns nothing

variable tLabel as String
variable tSegment
variable tCount as Integer

variable tX as Integer
put clickPosToComponent(the click position) into tX

if tX is 0 then
return
end if

if mMultiSelect is false then
-- if cannot multiselect, then need to select the clicked-on segment and
deselect the currently selected segment
-- if the clicked-on segment is already selected, then do nothing
* if not (tX is in mSelectedSegments) then*
* setSelection([tX])*
* else*
* post "hiliteChanged" -- if the segment was already hilited, send a
hilitechanged anyway*
* end if*
else
-- if can multiselect, then select the clicked-on segment if it is
unselected or unselect if its selected
  if tX is in mSelectedSegments then
removeFromSelection(tX)
else
addToSelection(tX)
end if
end if
end handler

If you have it set for multi hilites, it should toggle segments on and off
as expected and you should see a hiliteChanged in those instances still.

I can get the version in 9 dp2 to pop out a mouseup but haven't been able
to do so in 8 versions so this is my best answer. (despite it not being the
best way i'm sure)

once the file is changed, save it.  Start up LC.

Go to tools and choose extension bulder.

Click the folder icon near the top, and browse to where the modified lcb
file is located and choose it.

At this point you can click test and it should pop up a stack with the
control already placed. Or click "install" and a second segmented control
should show up in your toolbar.

Drag it out and set up the hilite changed handler so that you know its
firing (like maybe have it output a random number so you can see it change)
  Then click the same segment and see if it works as expected.

Since I'm still clueless about lcb, you might have to do some hoop jumping
to track if it IS actually the same segment each time, but you can track
the hiliteditems and hilitednames of the control so it should be easy to
do.

If things don't work as expected, you can go to the extension manager and
uninstall your new control.

Also, I'd recommend against trying to edit the current one in place.
Various things went missing on me when I tried that (including the whole
folder for that extension!) and i've no clue where they went. (Learning is
FUN!)

On Wed, Jan 25, 2017 at 11:13 AM, hlowe via use-livecode <
use-livecode at lists.runrev.com> wrote:

> I am switching over from a home-grown segmented control to LC's Segmented
> Control widget. This widget receives a "hiliteChanged" message when the
> selected segment changes but (apparently) no message is received by the
> widget if the user clicks in the currently selected segment. I need to
> respond to the user clicking in the currently selected segment of the
> widget. Anyone know if it is possible to detect this event in the Segmented
> Control widget? The widget does not appear to receive MouseUp or MouseDown
> messages when clicked.
>
> Thanks,
>
> Henry
>
>
>
> --
> View this message in context: http://runtime-revolution.
> 278305.n4.nabble.com/Detecting-clicks-in-Segmented-
> Control-widget-tp4711930.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list