advanced format for slider value

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Ashkan
Posts: 7
Joined: Thu Jun 04, 2015 12:45 pm

advanced format for slider value

Post by Ashkan » Wed Jun 17, 2015 12:32 pm

Hi everyone,

I have an slider its value is from 0 to 23 for hours.
I want its value to be shown as 00:00 to 23:00 when 'Show Value' is set. (Minutes are always :00 .)
The usual 'Value Format', as I have read from examples and livecode wiki, formats this number as a floating point number with specified decimal places/leading zeros.

Thanks a lot for your help.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: advanced format for slider value

Post by dunbarx » Wed Jun 17, 2015 2:50 pm

Hi.

This is not perfect. Maybe it can be made so. Before you start, go to the inspector and set the valueFormat to ".00". Then in the slider script:

Code: Select all

on scrollbarDrag
   set the thumbPos of me to round(the thumbPos of me,0)
end scrollbarDrag
Is this OK?

Craig Newman

Ashkan
Posts: 7
Joined: Thu Jun 04, 2015 12:45 pm

Re: advanced format for slider value

Post by Ashkan » Wed Jun 17, 2015 3:48 pm

Thanks Craig,
I got 12.00 instead of 12:00, as you pointed out "It is not perfect".
Another problem is that the slider loses its smooth movement and jumps between round number. :(

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: advanced format for slider value

Post by dunbarx » Wed Jun 17, 2015 4:03 pm

Then you have to make a workaround. In this case we call it a kluge.

Create a field of nice size and proportion that will overlie the numeric part of the slider. Have that field track the thumb (or rather, vice-versa). Use the mouseMove or mouseStillDown message in the field to load that field with the rounded value of the slider. Or do the math yourself and simply hide the position display. Now you never set the thumbPosition, so the smoothness will return. And you can format the field value in any way you like.

OK with this? You will have to scale the X coordinates to make sense of it all, something the thumbPos does for you.

Craig

Ashkan
Posts: 7
Joined: Thu Jun 04, 2015 12:45 pm

Re: advanced format for slider value

Post by Ashkan » Wed Jun 17, 2015 4:29 pm

Thanks Craig,

Yes, it works and it provides me with the functionality I need.
Thank you a lot for your kindness and spending your time.
My project is on mobile phone and I should check processing power of my mobile.
I have eight sliders working at same time.
I have already encountered the problem that everything is OK on PC but the processing power of mobile is not enough. It doesn't seem heavy calculation and I guess it works. I will check it.

Post Reply