If developers will be able to add this, I will promise to release my improved ‘magnet’ module to the public as free marketplace plugin. It is currently based on https://github.com/radixzz/magnet/blob/master/lib/magnet.lua but has loads of functions added, an overview of those can be seen at the bottom of this post.
It can align any object to another object so you can easily read how all of your objects in the screen is set up. For example the pseudo code below.
local informationContainer = createInformationContainer(50, 50) magnet:center(informationContainer, 0, 0) -- Aligns in the center of the screen local healthIcon = createHealthIcon(12, 12) magnet:topLeft(healthIcon, 2, 2, informationContainer) local manaIcon = createManaIcon(12, 12) magnet:topRight(manaIcon, 2, 2, informationContainer) local nameText = createNameText() magnet:atCenterRight(nameText, 0, 0, informationContainer)
This would result in something like this.
As of now, it depends on some hacked display.new* methods to work almost all of the time, even with very complex situations. So I can’t really release it, but adding more precise contentBounds would remove the need for this hack, and would also be a nice performance boost since I won’t have to resolve the object position by looping through all of the parents recursively.
function magnet:top(obj, marginY, parent) function magnet:right(obj, marginX, parent) function magnet:bottom(obj, marginY, parent) function magnet:left(obj, marginX, parent) function magnet:horizontalCenter(obj, marginX, parent) function magnet:verticalCenter(obj, marginY, parent) function magnet:topLeft(obj, marginX, marginY, parent) function magnet:topRight(obj, marginX, marginY, parent) function magnet:bottomLeft(obj, marginX, marginY, parent) function magnet:bottomRight(obj, marginX, marginY, parent) function magnet:center(obj, marginX, marginY, parent) function magnet:topCenter(obj, marginX, marginY, parent) function magnet:centerRight(obj, marginX, marginY, parent) function magnet:bottomCenter(obj, marginX, marginY, parent) function magnet:centerLeft(obj, marginX, marginY, parent) function magnet:atTop(obj, marginY, parent) function magnet:atBottom(obj, marginY, parent) function magnet:atRight(obj, marginX, parent) function magnet:atLeft(obj, marginX, parent) function magnet:atTopLeft(obj, marginX, marginY, parent) function magnet:atTopCenter(obj, marginX, marginY, parent) function magnet:atTopRight(obj, marginX, marginY, parent) function magnet:atBottomLeft(obj, marginX, marginY, parent) function magnet:atBottomCenter(obj, marginX, marginY, parent) function magnet:atBottomRight(obj, marginX, marginY, parent) function magnet:atLeftTop(obj, marginX, marginY, parent) function magnet:atLeftCenter(obj, marginX, marginY, parent) function magnet:atLeftBottom(obj, marginX, marginY, parent) function magnet:atRightTop(obj, marginX, marginY, parent) function magnet:atRightCenter(obj, marginX, marginY, parent) function magnet:atRightBottom(obj, marginX, marginY, parent) function magnet:topCenterBetween(obj, marginX, marginY, parent, yPosition) function magnet:bottomCenterBetween(obj, marginX, marginY, parent, yPosition) function magnet:centerLeftBetween(obj, marginX, marginY, parent, xPosition) function magnet:centerRightBetween(obj, marginX, marginY, parent, xPosition) function magnet:atTopLeftBetween(obj, marginX, marginY, parent, yPosition) function magnet:atTopCenterBetween(obj, marginX, marginY, parent, yPosition) function magnet:atTopRightBetween(obj, marginX, marginY, parent, yPosition) function magnet:atBottomLeftBetween(obj, marginX, marginY, parent, yPosition) function magnet:atBottomCenterBetween(obj, marginX, marginY, parent, yPosition) function magnet:atBottomRightBetween(obj, marginX, marginY, parent, yPosition) function magnet:atLeftTopBetween(obj, marginX, marginY, parent, xPosition) function magnet:atLeftCenterBetween(obj, marginX, marginY, parent, xPosition) function magnet:atLeftBottomBetween(obj, marginX, marginY, parent, xPosition) function magnet:atRightTopBetween(obj, marginX, marginY, parent, xPosition) function magnet:atRightCenterBetween(obj, marginX, marginY, parent, xPosition) function magnet:atRightBottomBetween(obj, marginX, marginY, parent, xPosition) function magnet:getLocationFor(...) function magnet:getXLocationFor(...) function magnet:getYLocationFor(...) setmetatable(magnet, {\_\_call = function(...) magnet[select(2, ...)](magnet, select(3, ...)) end })