Linking Rectangle height to 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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
glenn9
Posts: 10
Joined: Wed Jan 15, 2020 10:45 pm

Linking Rectangle height to Slider value

Post by glenn9 » Thu Jan 16, 2020 9:00 am

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

AndyP
Posts: 458
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Linking Rectangle height to Slider value

Post by AndyP » Thu Jan 16, 2020 9:46 am

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.
Andy Piddock

http://2108.co.uk/tinyide/ - Mini LC IDE alternative

http://2108.co.uk/script-editor-themer/ - Script Editor colour theming

http://livecodeshare.runrev.com/stack/897/LiveCode-Multi-Search - Search across 8 LC resources

glenn9
Posts: 10
Joined: Wed Jan 15, 2020 10:45 pm

Re: Linking Rectangle height to Slider value

Post by glenn9 » Thu Jan 16, 2020 11:56 am

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

glenn9
Posts: 10
Joined: Wed Jan 15, 2020 10:45 pm

Re: Linking Rectangle height to Slider value

Post by glenn9 » Thu Jan 16, 2020 12:34 pm

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

Klaus
Posts: 11497
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Linking Rectangle height to Slider value

Post by Klaus » Thu Jan 16, 2020 1:07 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6468
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Linking Rectangle height to Slider value

Post by dunbarx » Thu Jan 16, 2020 3:02 pm

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

glenn9
Posts: 10
Joined: Wed Jan 15, 2020 10:45 pm

Re: Linking Rectangle height to Slider value

Post by glenn9 » Fri Jan 17, 2020 10:45 am

Thank you for all your replies, they have been most helpful.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”