How to find the column and row of a basic tableField
hakan at exformedia.se
hakan at exformedia.se
Fri Apr 3 02:42:05 EDT 2020
With risk of going slightly off-topic, but also showing yet another code example. I had exactly this problem some time ago and came up with the following solution:
getProp clickedRowCol
# calc Row => TODO: Handle row with variable row heights
put the clickV - the top of me - the borderWidth of me - the effective topMargin of me + 5 into tY
put tY div the effective textHeight of me + 1 into tLine
#Calc column : TODO : Handle other text aligns
put the tabstops of me into tTabs
put the number of items in tTabs into tNumCols
put item -1 of tTabs into tLastTab
put tLastTab - item -2 of tTabs into tTabWidth
put the left of me + the borderWidth of me +the effective leftMargin of me - 2 into tLeft
if (the ClickH - tleft) > tLastTab then
# Click right of last column
return tLine, (the ClickH - tLastTab - tLeft) div tTabWidth + tNumCols + 1
else
put the ClickH - tLeft into tClickPos
put "," & tClickPos after tTabs
sort items of tTabs numeric ascending
return tLine, itemOffset(tClickPos, tTabs)
end if
end clickedRowCol
You can try it by adding the following mouseUp code:
on mouseUp
answer "You clicked at " & the clickH, the clickV && "= (Row,Col)" && the clickedRowCol of me
end mouseUp
It works for tables with or without date but doesn’t handle tables with variable row heights as that was not the case at the moment. To get it pixel-perfect I needed to compensate the row calculation with 5 pixels and the column with -2 as you can see in my code. Does anyone know why? Is it the same reason that if you set the margins of a field to 0 you often get the first line clipped?
Keep Safe!
:-Håkan
More information about the use-livecode
mailing list