[EMAIL PROTECTED] wrote:
> Author: hqm
> Date: 2006-06-13 11:26:28 -0400 (Tue, 13 Jun 2006)
> New Revision: 949
>
> Modified:
> openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
> Log:
> add getTextHeight to DHTML
>
> Modified:
> openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
> ===================================================================
> --- openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
> 2006-06-13 15:11:34 UTC (rev 948)
> +++ openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
> 2006-06-13 15:26:28 UTC (rev 949)
> @@ -102,7 +102,21 @@
> //Debug.info('getTextWidth', this.text, this._textsizecache[this.text]);
> return this._textsizecache[this.text].width;
> }
> +
> +LzTextSprite.prototype.getTextHeight = function () {
> +
> + if (! this._textsizecache) this._textsizecache = {};
>
> + if (! this._textsizecache[this.text]) {
> + this._textsizecache[this.text] = this.getTextSize(this.text);
> + }
> +
> + //Debug.info('getTextWidth', this.text, this._textsizecache[this.text]);
> + return this._textsizecache[this.text].height;
> +
> +}
> +
> +
> LzTextSprite.prototype.getTextSize = function (string) {
> var dim = new Object();
> if (document.all && document.body.insertAdjacentHTML) {
> @@ -196,6 +210,3 @@
> // TODO: not implemented
> }
>
> -LzTextSprite.prototype.getTextHeight = function () {
> -// TODO: not implemented
> -}
You'll likely need to set the style properties for multiline and
width/height to get the right values. For example, I've been returning
the natural height of the internal div when the height needs to be
updates - see line 78 of LzTextSprite.js:
if (this.sizeToHeight) {
this.owner.height = this.getHeight();
if (this.owner.onheight)
this.owner.onheight.sendEvent(this.owner.height);
}
You may be able to proxy getTextHeight to getHeight instead.
I added _textsizecache to track string widths only - it was a
last-minute change to improve performance.
I'll make a change to flush _textsizecache when setText is called with a
new value to address Tucker's concern.
--
Regards,
Max Carlson
OpenLaszlo.org
_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev