Using scrollbars with style "scale"

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Using scrollbars with style "scale"

Post by phaworth » Tue Oct 21, 2014 8:20 pm

Writing on the forum since the use list is down right now.

I have a scrollbar with the style set to "scale". Right now I'm using the scrollbardrag message to store the thumbpos and a mouseUp message to do what I need to do after the user finishes dragging. So far so good.

I want the user to be able to click somewhere on the scrollbar and have the thumbpos set to wherever he clicked The dictionary mentions scrollbardPageInc, scrollbarPageDec, scrollLineInc, and scrollbarLineDec. After experimenting, I found that the scrollbarLinexxx messages are not sent to a scale scrollbar. The scrollbarPagexxx messages are sent but the newposition parameter is always 1 different than the existing thumbpos and does not reflect where the user clicked.

As an example, lets say the scrollbar min and max are set to 1 and 50 and it's currently positioned at thumbpos 25. If the user clicks on it at a position that corresponds to thumbpos 10, the scrollbarPageDec message comes in with a parameter of 24 not 10.

I think this behavior is because the pageincrement property of my scrollbar is set to 1 (by LC not me). It feels like I am going to have to set the thumbpos to a calculated value based on the location of the mouse click, the width of the scrollbar, and startvalue and endvalue of the scrollbar. Before I go down that path, am I missing some obvious way of achieving this?

Pete

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

Re: Using scrollbars with style "scale"

Post by dunbarx » Tue Oct 21, 2014 10:35 pm

Hi.

You nailed the procedure. I did this just for fun. In a scrollbar script (I assume horizontal):

Code: Select all

on mouseUp
   put the endValue of scrollbar 1 into tEnd
    put the width of scrollbar 1 into tWidth
   put trunc(tEnd/tWidth) into tScale
   put item 1 of the clickLoc into tClickH
   
   put the left of scrollbar 1 into leftH
   put tclickH - leftH into scaleValue
   
   set the thumbPos of scrollbar 1 to scalevalue * tScale
end mouseUp
Such fun. But it needs to address the width of the thumb.

Craig

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

Re: Using scrollbars with style "scale"

Post by dunbarx » Tue Oct 21, 2014 10:38 pm

What is a "scale" style for scrollbars?

Craig

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Using scrollbars with style "scale"

Post by phaworth » Wed Oct 22, 2014 12:10 am

Thanks Craig, I figured it would have be a homegrown solution.

You probably figured it out but scrollbars with a scale style are displayed as slider controls. On the tools palette, you'll see one next to the progress bar icon.

Pete

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

Re: Using scrollbars with style "scale"

Post by dunbarx » Wed Oct 22, 2014 4:27 am

Pete.

Of course. Everyone knows that. Now even me.

Craig

Post Reply