Page 1 of 1

Linking Rectangle height to Slider value

Posted: Thu Jan 16, 2020 9:00 am
by glenn9
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

Re: Linking Rectangle height to Slider value

Posted: Thu Jan 16, 2020 9:46 am
by AndyP
Hi glenn9, welcome to the forum.

Just add

Code: Select all

set the bottom  of graphic "Column" to 200
exchange 200 for the position of your rectangle.
You can easily find this with the message box and entering

Code: Select all

put the bottom  of graphic "Column"
Also wrap all your code with a lock screen and unlock screen... try removing these to see the difference it makes.

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
Let us know how you get on.

Re: Linking Rectangle height to Slider value

Posted: Thu Jan 16, 2020 11:56 am
by glenn9
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

Re: Linking Rectangle height to Slider value

Posted: Thu Jan 16, 2020 12:34 pm
by glenn9
checked the dictionary - I think I now understand why the lock screen works and I guess the

Code: Select all

set the bottom  of graphic "Col" to 200
anchors the bottom of the column to a defined position therefore just allowing the top of the column to move?

Thanks,

Glenn

Re: Linking Rectangle height to Slider value

Posted: Thu Jan 16, 2020 1:07 pm
by Klaus
Hi gelnn9,

welcome to the forum!

Code: Select all

set the bottom  of graphic "Col" to 200
anchors the bottom of the column to a defined position therefore just allowing the top of the column to move?
Yes.

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
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! :D

Best

Klaus

Re: Linking Rectangle height to Slider value

Posted: Thu Jan 16, 2020 3:02 pm
by dunbarx
Hi.

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
Also, please wrap your code within the code tags (</>). It makes it much easier to deal with.

Craig

Re: Linking Rectangle height to Slider value

Posted: Fri Jan 17, 2020 10:45 am
by glenn9
Thank you for all your replies, they have been most helpful.