Linking Rectangle height to Slider value
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Linking Rectangle height to Slider value
Hi, I'm a livecode beginner (2 weeks) and I want to link a Slider to the height of a Rectangle and therefore wrote this code:
on scrollbardrag newValue
local tHt
put newValue into field"F1"
set location of graphic"Column" to 189, 100
set height of graphic"Column" to newValue
end scrollbardrag
Although it does alter the height of the Rectangle it alters the height from both the top and bottom of the column(Rectangle).
What I wanted it to do though is for it to keep the base of the column at the same position and only alter the top of the column.
Grateful for any hints!
many thanks
on scrollbardrag newValue
local tHt
put newValue into field"F1"
set location of graphic"Column" to 189, 100
set height of graphic"Column" to newValue
end scrollbardrag
Although it does alter the height of the Rectangle it alters the height from both the top and bottom of the column(Rectangle).
What I wanted it to do though is for it to keep the base of the column at the same position and only alter the top of the column.
Grateful for any hints!
many thanks
Re: Linking Rectangle height to Slider value
Hi glenn9, welcome to the forum.
Just add exchange 200 for the position of your rectangle.
You can easily find this with the message box and entering
Also wrap all your code with a lock screen and unlock screen... try removing these to see the difference it makes.
Let us know how you get on.
Just add
Code: Select all
set the bottom of graphic "Column" to 200
You can easily find this with the message box and entering
Code: Select all
put the bottom of graphic "Column"
Code: Select all
on scrollbardrag newValue
lock screen
local tHt
put newValue into field"F1"
set location of graphic"Column" to 189, 100
set height of graphic"Column" to newValue
set the bottom of graphic"Column" to 200
unlock screen
end scrollbardrag
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
Re: Linking Rectangle height to Slider value
Brill, many thanks indeed Andy, that has solved it. It now works very well and as expected.
The lock/unlock screen makes it scroll much smoother!
(I just need to spend some time now understanding why it's worked, including the unlock/lock command!)
Thank you again,
Glenn
The lock/unlock screen makes it scroll much smoother!
(I just need to spend some time now understanding why it's worked, including the unlock/lock command!)
Thank you again,
Glenn
Re: Linking Rectangle height to Slider value
checked the dictionary - I think I now understand why the lock screen works and I guess the anchors the bottom of the column to a defined position therefore just allowing the top of the column to move?
Thanks,
Glenn
Code: Select all
set the bottom of graphic "Col" to 200
Thanks,
Glenn
Re: Linking Rectangle height to Slider value
Hi gelnn9,
welcome to the forum!
Some comments to the script why I commented these lines out:
1. you are not using the local variable tHT in this handler, so no need to declare it here at all
2. Setting the height/width of an object will also affects it LOCATION, so if neccessary,
set the loc AFTER changing height and/or width of an object.
An only setting the heigth will no affect the X position, so you do not need to set the LOC again,
setting the BOTTOM is enough here, because after setting the height the loc of your graphic is
possibly NOT 189,100 anymore!
Best
Klaus
welcome to the forum!
Yes.anchors the bottom of the column to a defined position therefore just allowing the top of the column to move?Code: Select all
set the bottom of graphic "Col" to 200
Code: Select all
on scrollbardrag newValue
lock screen
## 1.
## local tHt
put newValue into field"F1"
## 2.
## set location of graphic"Column" to 189, 100
set height of graphic"Column" to newValue
set the bottom of graphic"Column" to 200
unlock screen
end scrollbardrag
1. you are not using the local variable tHT in this handler, so no need to declare it here at all
2. Setting the height/width of an object will also affects it LOCATION, so if neccessary,
set the loc AFTER changing height and/or width of an object.
An only setting the heigth will no affect the X position, so you do not need to set the LOC again,
setting the BOTTOM is enough here, because after setting the height the loc of your graphic is
possibly NOT 189,100 anymore!
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Linking Rectangle height to Slider value
Hi.
All good stuff. But do you need more than:
Also, please wrap your code within the code tags (</>). It makes it much easier to deal with.
Craig
All good stuff. But do you need more than:
Code: Select all
on scrollbardrag newValue
set the height of grc "column" to newValue
set the bottom of grc "column" to 200
end scrollbardrag
Craig
Re: Linking Rectangle height to Slider value
Thank you for all your replies, they have been most helpful.