ScrollBar, text size and height

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

ScrollBar, text size and height

Post by TodayIsTheDay » Sat Oct 10, 2009 3:48 am

I have a script that uses the scrollbar to change the size of text in a field and put the size and height of the text into two other fields.

Code: Select all

on scrollbardrag tValue
   put the textheight of field "field1" into field "textheight"
   put the textsize of field "field1"-1 into field "textsize"
   if  tValue =1 then set theTextSize of  field "Field1" to 9  
   else if tValue =2  then set the TextSize of  field "Field1" to 10
   else if tValue =3  then set the TextSize of  field "Field1" to 11
   else if tValue =4  then set the TextSize of  field "Field1" to 12
   else if tValue =5  then set the TextSize of  field "Field1" to 13
   else if tValue =6  then set the TextSize of  field "Field1" to 14
   else if tValue =7  then set the TextSize of  field "Field1" to 15
   else if tValue =8  then set the TextSize of  field "Field1" to 16
   else if tValue =9  then set the TextSize of  field "Field1" to 17
   else if tValue =10  then set the TextSize of  field "Field1" to 18
   else if tValue =11  then set the TextSize of  field "Field1" to 19
   else if tValue =12  then set the TextSize of  field "Field1" to 20
   else if tValue =13  then set the TextSize of  field "Field1" to 21
   else if tValue =14  then set the TextSize of  field "Field1" to 22
   else if tValue =15  then set the TextSize of  field "Field1" to 23
   else if tValue =16  then set the TextSize of  field "Field1" to 24
   else if tValue =17  then set the TextSize of  field "Field1" to 25
   else if tValue =18  then set the TextSize of  field "Field1" to 26
   else if tValue =19  then set the TextSize of  field "Field1" to 27
   else if tValue =20  then set the TextSize of  field "Field1" to 28
   else if tValue =21  then set the TextSize of  field "Field1" to 29
   else if tValue =21  then set the TextSize of  field "Field1" to 30
   else if tValue =23  then set the TextSize of  field "Field1" to 31
   else if tValue =24  then set the TextSize of  field "Field1" to 32
   else if tValue =25  then set the TextSize of  field "Field1" to 33
   else if tValue =26  then set the TextSize of  field "Field1" to 34
   else if tValue =27  then set the TextSize of  field "Field1" to 35
   else if tValue =28  then set the TextSize of  field "Field1" to 36
   else if tValue =29  then set the TextSize of  field "Field1" to 37
   else if tValue =30  then set the TextSize of  field "Field1" to 38
   else if tValue =31  then set the TextSize of  field "Field1" to 39
   else if tValue =32  then set the TextSize of  field "Field1" to 40
   else if tValue =33  then set the TextSize of  field "Field1" to 41
   else if tValue =34  then set the TextSize of  field "Field1" to 42
   else if tValue =35  then set the TextSize of  field "Field1" to 43
   else if tValue =36  then set the TextSize of  field "Field1" to 44
   
   else end if
   
end scrollbardrag
I'm sure this is not the way to do this but it seems to sort of work...

Can someone please tell me how would be the correct way to do this?

And can someone please explain why this script acts the way it does?
For instance, if you start sliding the scrollbar, sometimes the numbers in the field telling you how big the text is does not change but you can clearly see the text getting bigger....

Sometimes when you slide the scrollbar all the way back to the left it does not go to the lowest number in my script (9)?

http://screencast.com/t/EHJK55WwnW

Thanks!

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Sat Oct 10, 2009 5:34 am

Wow - that's a lot of work to go through for that. If those are really the numbers you want, then try

Code: Select all

on scrollbardrag tValue
    put the textheight of field "field1" into field "textheight"
    put the textsize of field "field1"-1 into field "textsize"
    set the textsize of field "Field1" to tValue+8
end scrollbardrag

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Sat Oct 10, 2009 9:36 pm

Wow. Thanks!

Talk about making something super simple. I had no idea it could be done that way.

It still seemed to do the weirdness with reporting the text size and height.

I ended up doing this and it seemed to fix it. I'd like to understand why?

Code: Select all

on scrollbardrag tValue
    
    put the textheight of field "field1" into field "textheight"
    
    put the textsize of field "field1"-1 into field "textsize"
    
    set the textsize of field "Field1" to tValue+8

    put the textheight of field "field1" into field "textheight"
    
    put the textsize of field "field1"-1 into field "textsize"
   

end scrollbardrag 
Also I would have never known to do this. How did you know to do the value =8?

Thanks!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sat Oct 10, 2009 9:52 pm

TodayIsTheDay,
if you mean by weirdness that texHeight and TexSize are not what you expect from the setting of the TextSize by the scrollbar then maybe this is before you set the textSize to the scrollbarValue you query the values.
So they are the values from your last setting. Try

Code: Select all

on scrollbardrag tValue 
   set the textsize of field "Field1" to tValue+8 
   put the textheight of field "field1" into field "textheight" 
   put the textsize of field "field1"-1 into field "textsize" 
end scrollbardrag 
and it should work. If that is what you mean.
by the way what is the -1 for in "put the textsize of field "field1"-1 into field "textsize""?
regards
Bernd

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Sat Oct 10, 2009 10:04 pm

What I meant was when you moved the scrollbar all the way back to the left, one time it might report text height as 8 the next time as 11 the next time as 10 even though you have the scrollbar all the way to the left.

I didn't understand why....

Does that make sense? Sometimes I can be confusing when I try to explain things.

the -1 was a mistake. I don't know what I was doing there...

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Sat Oct 10, 2009 10:07 pm

The way you posted it worked perfectly. There was no need for me to have it at the beginning of the code and at the end. :roll:

I'm really new to coding and Rev. I'm just making all sorts of little test apps and trying code...

Thank you!

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Sat Oct 10, 2009 10:21 pm

Well, the way I knew it was 8 was because that's what you were doing in your code. Nothing magical about the number 8, but you had

Code: Select all

if  tValue =1 then set theTextSize of  field "Field1" to 9
and then on down to

Code: Select all

if tValue =36  then set the TextSize of  field "Field1" to 44 
so I just simplified it a bit. Fiddle with the value if you want and see what happens.

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Sat Oct 10, 2009 10:34 pm

I think I way overthink this stuff sometimes... It was right in front of me and I didn't see it...

Thank you again.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Sat Oct 10, 2009 11:27 pm

I think I way overthink this stuff sometimes... It was right in front of me and I didn't see it...
Been there <g>. But there's nothing like having group input when you get stuck on things.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Sun Oct 11, 2009 4:20 pm

You can also set the startValue and endValue properties of the scrollbar to 8 and 74 respectively, and then you don't have to add 8 to the thumbPosition of the scrollbar to determine the textHeight.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Post Reply