Rework tooltip size calculations to get rid of delayed update.
This commit is contained in:
parent
5b84e09572
commit
0980f6302a
1 changed files with 34 additions and 33 deletions
|
@ -13,7 +13,8 @@ var Tooltip = {
|
||||||
_height: 0,
|
_height: 0,
|
||||||
_tipId: nil,
|
_tipId: nil,
|
||||||
_slice: 17,
|
_slice: 17,
|
||||||
_measureText: nil
|
_measureText: nil,
|
||||||
|
_measureBB: nil
|
||||||
};
|
};
|
||||||
m.setInt("size[0]", size[0]);
|
m.setInt("size[0]", size[0]);
|
||||||
m.setInt("size[1]", size[1]);
|
m.setInt("size[1]", size[1]);
|
||||||
|
@ -84,7 +85,6 @@ var Tooltip = {
|
||||||
{
|
{
|
||||||
me._label = msg;
|
me._label = msg;
|
||||||
me._updateText();
|
me._updateText();
|
||||||
me._updateBounds();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setProperty: func(prop)
|
setProperty: func(prop)
|
||||||
|
@ -94,7 +94,7 @@ var Tooltip = {
|
||||||
|
|
||||||
me._property = prop;
|
me._property = prop;
|
||||||
if (me._property != nil)
|
if (me._property != nil)
|
||||||
me._listener = setlistener(me._property, func { me._propertyChanged(); });
|
me._listener = setlistener(me._property, func { me._updateText(); });
|
||||||
|
|
||||||
me._updateText();
|
me._updateText();
|
||||||
},
|
},
|
||||||
|
@ -102,15 +102,12 @@ var Tooltip = {
|
||||||
# specify a string used to compute the width of the tooltip
|
# specify a string used to compute the width of the tooltip
|
||||||
setWidthText: func(txt)
|
setWidthText: func(txt)
|
||||||
{
|
{
|
||||||
me._measureText = txt;
|
me._measureBB = me._text.setText(txt)
|
||||||
|
.update()
|
||||||
|
.getBoundingBox();
|
||||||
me._updateBounds();
|
me._updateBounds();
|
||||||
},
|
},
|
||||||
|
|
||||||
_propertyChanged: func
|
|
||||||
{
|
|
||||||
me._updateText();
|
|
||||||
},
|
|
||||||
|
|
||||||
_updateText: func
|
_updateText: func
|
||||||
{
|
{
|
||||||
var msg = me._label;
|
var msg = me._label;
|
||||||
|
@ -120,28 +117,32 @@ var Tooltip = {
|
||||||
}
|
}
|
||||||
|
|
||||||
me._text.setText(msg);
|
me._text.setText(msg);
|
||||||
|
me._updateBounds();
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateBounds: func
|
_updateBounds: func
|
||||||
{
|
{
|
||||||
var width = me.get("size[0]");
|
var max_width = me.get("size[0]") - 2 * me._slice;
|
||||||
me._text.setMaxWidth(width);
|
me._text.setMaxWidth(max_width);
|
||||||
|
|
||||||
if (me._measureText == nil)
|
# compute the bounds
|
||||||
me._updateText();
|
var text_bb = me._text.update().getBoundingBox();
|
||||||
else
|
var width = text_bb[2];
|
||||||
me._text.setText(me._measureText);
|
var height = text_bb[3];
|
||||||
|
|
||||||
me._text.update(); # compute the bounds
|
if( me._measureBB != nil )
|
||||||
var bounds = me._text.getBoundingBox();
|
{
|
||||||
me._updateText(); # restore real text after measurement
|
width = math.max(width, me._measureBB[2]);
|
||||||
|
height = math.max(height, me._measureBB[3]);
|
||||||
|
}
|
||||||
|
|
||||||
if ((bounds[2] == me._width) and (bounds[3] == me._height))
|
if( width > max_width )
|
||||||
return;
|
width = max_width;
|
||||||
|
|
||||||
me._width = bounds[2] + 2 * me._slice;
|
me._width = width + 2 * me._slice;
|
||||||
me._height = bounds[3] + 2 * me._slice;
|
me._height = height + 2 * me._slice;
|
||||||
me._frame.setSize(me._width, me._height);
|
me._frame.setSize(me._width, me._height)
|
||||||
|
.update();
|
||||||
},
|
},
|
||||||
|
|
||||||
_remapValue: func(val)
|
_remapValue: func(val)
|
||||||
|
|
Loading…
Add table
Reference in a new issue