Page 1 of 1

Replacing a Scrollbar control by a Segmented Control Widget

Posted: Sat Jan 21, 2017 9:12 pm
by simon.schvartzman
Hi, in the picture below I would like to replace the LittleArrows Scrollbar (Up & Down) by a Segmented Control with exactly the same functionality, Increasing and Decreasing a Label field called ValMeses.
segmented control.jpeg
segmented control.jpeg (22.05 KiB) Viewed 6970 times
Problems are:
- the Segmented Control doesn't react to several mouse clicks in the same segment
- it remains hilited even when I click the mouse outside the control

this is the code for the Scrollbar that works fine

Code: Select all

on scrollbarLineDec
   if field ValMeses < 12 then
      add 1 to field ValMeses
   end if
end scrollbarLineDec

on scrollbarLineinc
   if field ValMeses > 0 then
      subtract 1 field ValMeses
   end if
end scrollbarLineinc
and this is the code for the Segmented Control

Code: Select all

on hiliteChanged
   put the hilitedItemNames of me into tHilited
   if tHilited = "Plus" then
      if field ValMeses < 12 then
         add 1 to field ValMeses
      end if
   else
      if field ValMeses > 0 then
         subtract 1 field ValMeses
      end if
   end if   
 nd hiliteChanged
What am I doing wrong? Many thanks...

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Sun Jan 22, 2017 12:42 am
by jmburnod
Hi Simon,
Here is a stack which does the job.
One group with 2 btns. Script is in group script
Best regards
Jean-Marc

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Sun Jan 22, 2017 11:47 am
by simon.schvartzman
Jean-Marc, many thanks for your help.

With my limited LC knowledge it would have taken me a very long time to get there.

Best,

Simon

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Sun Jan 22, 2017 12:34 pm
by jmburnod
Welcome Simon,

That is one quick way to do it.
LiveCode is very flexible and allows several ways to do the same thing and I'm sure that we can make better
With these recurrent questions:
What is the best way in my context ?
What is the best way for future update ?
etc.

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Mon Jan 23, 2017 12:31 pm
by simon.schvartzman
As a matter of fact I still wonder how to do it using the Segmented Control Widget which seems to be the proper one and looks nicer.

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Mon Jan 23, 2017 5:50 pm
by jmburnod
Hi Max
I never used a widget but I tried to use it for your scrollbar case.
It seems the only message sent by an element of the widget is "mouseup".
Can some widget's expert confirm this ?

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Mon Jan 23, 2017 6:06 pm
by simon.schvartzman
@jmburnod I'm very far from being a "widget expert" but just for you to know in my experience with the widget I got the message from the "hiliteChanged" event.

Best, Simon

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Tue Jan 24, 2017 6:09 pm
by jacque
A segmented control is not suitable for what you want. It has a specific purpose, which is to choose among several options. We use a group of radio buttons the same way. Only one selection is possible at any time, and re-selecting the same option does nothing. Segmented controls are typically used as navigation bars in mobile apps, for example.

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Tue Jan 24, 2017 6:23 pm
by simon.schvartzman
@jacque many thanks for the clarification.

Regards

Re: Replacing a Scrollbar control by a Segmented Control Wid

Posted: Tue Jan 24, 2017 7:21 pm
by jmburnod
Hi Max,
Segmented Control Widget which seems to be the proper one and looks nicer.
As Jacqueline said (thanks one more), group is a way for your case.
Just make better look for btns of group and you can recreate the same look as widget.
Best
Jean-Marc