I’m setting a tooltip on a label with label.tooltip = MyCustomObject(). MyCustomObject uses the canvas rendering context to format text correctly. When I set it as a tooltip, it is not added to the zCanvas instance and thus any internal calls to this.getCanvas() return null. Is there some other way to do this so that I can have access and format my text correctly. 

2 answers

Staff August 24, 2015

Could you describe the workflow ? It is not clear what is “format text correctly” and when it is going on. 
In general you can override “setParent(p)” method of tooltip component to be aware when it gets parent and calculate/format a text 

#1
  1. I have a text string I need to format into multiple lines. I also need to dynamically resize the tooltip depending on the amount of text. To accomplish this, I use c.measureText and insert newline characters where it is necessary. The flow is something like this1) create tooltip and set as the tooltip property on a label.2) when an update comes in with a message, I need to add it to the tooltip. If it isn't currently showing, I cannot get the 2d context and format3) when it is shown, it seems I need to format and resize it before it is rendered.I actually tried setParent(p), but it seemed to position it incorrectly after I resized it. It may be that I was doing something wrong though.
Staff August 24, 2015

To measure text metrics you don’t need get 2D context of zCanvas. Use “zebra.ui.Font” instead to measure text metrics. Think you should use font property of your label or text render component and call “stringWidth(s)” method to get string width in pixels.  

#2

Please login or Register to Submit Answer