Replacing a Scrollbar control by a Segmented Control Widget

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
simon.schvartzman
Posts: 665
Joined: Tue Jul 29, 2014 12:52 am

Replacing a Scrollbar control by a Segmented Control Widget

Post by simon.schvartzman » Sat Jan 21, 2017 9:12 pm

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 6969 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...
Simon
________________________________________
To ";" or not to ";" that is the question

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by jmburnod » Sun Jan 22, 2017 12:42 am

Hi Simon,
Here is a stack which does the job.
One group with 2 btns. Script is in group script
Best regards
Jean-Marc
Attachments
OneGroupUpDown.livecode.zip
(1.26 KiB) Downloaded 241 times
https://alternatic.ch

simon.schvartzman
Posts: 665
Joined: Tue Jul 29, 2014 12:52 am

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by simon.schvartzman » Sun Jan 22, 2017 11:47 am

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
Simon
________________________________________
To ";" or not to ";" that is the question

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by jmburnod » Sun Jan 22, 2017 12:34 pm

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.
https://alternatic.ch

simon.schvartzman
Posts: 665
Joined: Tue Jul 29, 2014 12:52 am

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by simon.schvartzman » Mon Jan 23, 2017 12:31 pm

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.
Simon
________________________________________
To ";" or not to ";" that is the question

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by jmburnod » Mon Jan 23, 2017 5:50 pm

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 ?
https://alternatic.ch

simon.schvartzman
Posts: 665
Joined: Tue Jul 29, 2014 12:52 am

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by simon.schvartzman » Mon Jan 23, 2017 6:06 pm

@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
Simon
________________________________________
To ";" or not to ";" that is the question

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by jacque » Tue Jan 24, 2017 6:09 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

simon.schvartzman
Posts: 665
Joined: Tue Jul 29, 2014 12:52 am

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by simon.schvartzman » Tue Jan 24, 2017 6:23 pm

@jacque many thanks for the clarification.

Regards
Simon
________________________________________
To ";" or not to ";" that is the question

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Replacing a Scrollbar control by a Segmented Control Wid

Post by jmburnod » Tue Jan 24, 2017 7:21 pm

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
https://alternatic.ch

Post Reply