I wish ...
Richard Gaskin
ambassador at fourthworld.com
Sat Jun 13 13:13:57 EDT 2015
Paul Dupuis
> Wouldn't it be more convenient to be able to do something like
>
> set the relative top of btn X to 40
> -- and have LiveCode see the keyword "relative" and position it
> at 40 pix down from the top of it's owner?
Or even more succinct:
set the relTop of btn x to 40
Doable in a few minutes with four pairs of these, one for each side:
setProp relTop pVal
set top of the target to (pVal \
+ the top of the owner of the target \
+ the topMargin of the owner of the target \
+ the borderWidth of the owner of the target \
- the vscroll of the owner of the target )
end relTop
getProp relTop
return (the top of the target \
- the top of the owner of the target \
- the topMargin of the owner of the target \
- the borderWidth of the owner of the target \
+ the vscroll of the owner of the target)
end relTop
You could even go further to include relTopLeft, relTopRight, and relLoc
if needed.
One challenge with that approach is the often it's not the immediate
owner I'm aligning to, but sometimes a group two or even three levels
up, depending on how deeply things are nested. But for some tasks that
may be useful, and I'm far too lazy to write getProp and setProp
handlers with enough options to handle all nested depths I might need. :)
While I don't use relative getProp and setProp handlers myself, I do
take advantage of other fairly recent enhancements to the language to
simplify layout management, like behaviors and also leveraging a
critical change to the resizeControl message:
In recent versions of LC resizeControl is sent to a group not only when
interactively resized by the user, but also in response to any change to
the size of a group from any script.
This has been a godsend for simplifying many layouts, and making them
more portable as well.
For example, consider this layout with three groups each containing a
number of objects:
----------------------------------------------------------
| ---------------------------------------------------- |
| | ------------- ------------- -------------- | |
| | | object | | object | | object | | |
| | ------------- ------------- -------------- | |
| ---------------------------------------------------- |
| |
| ------------------- ----------------------------- |
| | --------------- | | ----------- ----------- | |
| | | Object | | | | Object | | Object | | |
| | --------------- | | ----------- ----------- | |
| | | Object | | | ---------- ----------- | |
| | --------------- | | | Object| | Object | | |
| | | Object | | | ---------- ----------- | |
| | --------------- | | ----------- ----------- | |
| | | object | | | | Object | | Object | | |
| | --------------- | | ----------- ----------- | |
| | | Object | | | ----------- ----------- | |
| | --------------- | | | Object | | Object | | |
| | | Object | | | ----------- ----------- | |
| | --------------- | | ----------- ----------- | |
| ------------------- | | Object | | Object | | |
| | ----------- ----------- | |
| ----------------------------- |
----------------------------------------------------------
Taking advantage of the way resizeControl now works, the stack or card
script only needs to set the rects of the three outer groups, and each
group can respond to the resizeControl message to handle its own
interior objects.
Within each group, its resizeControl handler arranges its objects
relative to "me", so it always works no matter where "me" has been resized.
With this arrangement I can reuse any of those groups in any other
layout, putting them directly on a card or even within another group as
needed, and as long as some parent object sets their rect they'll be
able to respond to the resizeControl message to take care of themselves.
Coupled with the new preOpenControl, openControl, and closeControl
messages, many other aspects of a group's logic can be further
encapsulated, whether for reuse or just maintenance sanity.
--
Richard Gaskin
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
____________________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list