Thank you Juni, Redbol,
It looks like all should be easier than I though: the width and height of a group automatically reflect the contained items - which might just work for me.
At the level above the widgets, when the screen is resized (rotated or other), I now use the function below to help reposition my widgets dynamically across the top of the screen.
Great people and support in this forum - thank you for your time ! -ivec
function M.screenBox()
local scrL = display.safeScreenOriginX;
local scrT = display.safeScreenOriginY;
return {
L = scrL,
T = scrT,
R = scrL + display.safeActualContentWidth,
B = scrT + display.safeActualContentHeight,
}
end
-- Utility to reposition widgets at the top of a screen/box, e.g. when screen is resized:
-- layoutItems( nil, box, widget1, 5, widget2, nil, widget3, nil )
-- A "number" value indicates a fixed spacing between two items; the 'extra' space is shared across the "nil" entries
-- Note: it seems wiser to use e.g. -1 as a value, instead of nil, for "variable spacing"
function M.layoutItems(box,...)
local defSpc = 10
local refW = box.R-box.L
local totW = 0
local maxH = 1
local nilCnt = 0
local altSpc=nil
-- scan through the provided elements to compute total width
for i=1,#arg do local v = arg[i] --i,v in ipairs(arg) do
--for i,v in ipairs(arg) do -- the "iterator" version seems to stop at the first 'nil' element...
local t = type(v) -- string number table nil
if t=="table" then
totW = totW + (altSpc or defSpc) + v.width
altSpc=nil
maxH = math.max(maxH,v.height)
elseif t=="nil" then
nilCnt = nilCnt+1
elseif t=="number" then
altSpc=v
end
end
totW = totW + (altSpc or defSpc)
local scal = (totW>refW) and (refW/totW) or nil -- scaling if exceeded length
local nilSpc = (totW<refW) and (refW-totW)/nilCnt or 0 -- note: at least one "nil" is required
local xPos = box.L
local yPos = box.T + 0.5*maxH
altSpc=nil
-- position the widgets
for i=1,#arg do local v = arg[i] --i,v in ipairs(arg) do
local t = type(v) -- string number table nil
if t=="table" then
local w = v.width
xPos = xPos + (altSpc or defSpc) + w
altSpc=nil
v.x = xPos-0.5*w -- could test 'anchor' to position accordingly
v.y = yPos
elseif t=="nil" then
xPos = xPos+nilSpc
elseif t=="number" then
altSpc=v
end
end
box.T = box.T + maxH
end