Using Dyalog APL I'm trying to create a grid with cell tooltips. These tooltips are created with the method AddComment. For some reason the tooltip does not resize itself to fit the content so if the text doesn't fit it will be cut off. Therefor a size calculation is required before the tooltip is created. The method GetTextSize can be used to retrieve the size of a text in pixels for the used font. However, this method seems to report the wrong size despite setting the Coord property to 'Pixel'.
Here is an example which illustrates the problem:
∇ ShowGrid;col;comment;height;row;width
'F'⎕WC'Form'
'F.G'⎕WC'Grid'(2 2⍴0)(0 0)(100 100)
comment←↑'line one' 'line two' 'line three'
row col←1 2
'F.G' ⎕WS'Coord' 'Pixel'
height width←4 F.G.GetTextSize comment
F.G.AddComment row col comment height width
∇
I also add four pixels to the reported size of the text since the border and padding of the tooltip seems to be one pixel each. The window created with this function is shown in the image below. Only the text "line one" is visible in the tooltip. I also tried setting Coord to 'RealPixel' and 'ScaledPixel' respectively but it made no difference. My question is basically: What is the proper way to calculate the tooltip size so that any given text will be displayed in its entirety? I'm using Dyalog APL 16.0 Classic.
CodePudding user response:
The comment is drawn with a font that is different to the one used by F.G.GetTextSize
. Unfortunately there is currently no simple way to retrieve the size of the font that is actually used.
We will look into ways to fix this.
CodePudding user response:
A workaround suggested by Adám is to determine and hard code the font used for comments and then use GetTextSize with this font as a parameter. With some guess work and testing I found it to be "Segoe UI" of size 15 pixels. Here is a (rather fragile) solution:
∇ ShowGrid;border;col;comment;boxSize;commentSize;padding;row
'F'⎕WC'Form'
'F.G'⎕WC'Grid'(2 2⍴0)(0 0)(100 100)
comment←↑'line one' 'line two' 'line three'
row col←1 2
'F.G'⎕WS'Coord' 'Pixel'
'F.G.FNT'⎕WC'Font' 'Segoe UI' 15
commentSize←F.G.GetTextSize comment'#.F.G.FNT'
(border padding)←1
boxSize←commentSize 2×border padding
F.G.AddComment row col comment,boxSize
∇