MrKim Well-Known Member Licensed User Longtime User Feb 5, 2023 #1 Trying to measure a Tab returns -1 (at least in B4J) B4X: Dim cvs1 As B4XCanvas, P As Pane, Fnt As Font = xui.CreateDefaultFont(15) P.Initialize("") cvs1.Initialize(P) Log(cvs1.MeasureText(TAB, Fnt).Width) Your code MeasureText HERE and below returns 32.87109375. (And why didn't I find THIS code 3 days ago?) B4X: Dim lbl As Label lbl.Initialize("") lbl.Text = TAB lbl.Font = Fnt mBase.AddView(lbl, 0, 0, -1, -1) 'mBase is a B4XView panel. lbl.Snapshot lbl.RemoveNodeFromParent Log(lbl.Width) Interestingly, if I bracket the TAB, then subtract the width of 1 of the bracketing characters I get the same result as MeasureText : B4X: Log(cvs1.MeasureText($"!${TAB}!"$, Fnt).Width) Log(cvs1.MeasureText($"!"$, Fnt).Width) Log(cvs1.MeasureText($"!${TAB}!"$, Fnt).Width - cvs1.MeasureText($"!"$, Fnt).Width)
Trying to measure a Tab returns -1 (at least in B4J) B4X: Dim cvs1 As B4XCanvas, P As Pane, Fnt As Font = xui.CreateDefaultFont(15) P.Initialize("") cvs1.Initialize(P) Log(cvs1.MeasureText(TAB, Fnt).Width) Your code MeasureText HERE and below returns 32.87109375. (And why didn't I find THIS code 3 days ago?) B4X: Dim lbl As Label lbl.Initialize("") lbl.Text = TAB lbl.Font = Fnt mBase.AddView(lbl, 0, 0, -1, -1) 'mBase is a B4XView panel. lbl.Snapshot lbl.RemoveNodeFromParent Log(lbl.Width) Interestingly, if I bracket the TAB, then subtract the width of 1 of the bracketing characters I get the same result as MeasureText : B4X: Log(cvs1.MeasureText($"!${TAB}!"$, Fnt).Width) Log(cvs1.MeasureText($"!"$, Fnt).Width) Log(cvs1.MeasureText($"!${TAB}!"$, Fnt).Width - cvs1.MeasureText($"!"$, Fnt).Width)
Erel B4X founder Staff member Licensed User Longtime User Feb 5, 2023 #2 This is not a bug. 1. The measurement comes from the JavaFX API. 2. The measurement of invisible text is unspecified. This is not a measurement of the character width.
This is not a bug. 1. The measurement comes from the JavaFX API. 2. The measurement of invisible text is unspecified. This is not a measurement of the character width.