com.extjs.gxt.ui.client.util
Class TextMetrics

java.lang.Object
  extended by com.extjs.gxt.ui.client.util.TextMetrics

public class TextMetrics
extends java.lang.Object

Provides precise pixel measurements for blocks of text so that you can determine exactly how high and wide, in pixels, a given block of text will be.


Method Summary
 void bind(El el)
          Binds this TextMetrics instance to an element from which to copy existing CSS styles that can affect the size of the rendered text.
 void bind(com.google.gwt.user.client.Element el)
          Binds this TextMetrics instance to an element from which to copy existing CSS styles that can affect the size of the rendered text.
static TextMetrics get()
          Returns the singleton instance.
 int getHeight(java.lang.String text)
          Returns the measured height of the specified text.
 Size getSize(java.lang.String text)
          Returns the size of the specified text based on the internal element's style and width properties.
 int getWidth(java.lang.String text)
          Returns the measured width of the specified text.
 void setFixedWidth(int width)
          Sets a fixed width on the internal measurement element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static TextMetrics get()
Returns the singleton instance.

Returns:
the text metrics instance

bind

public void bind(com.google.gwt.user.client.Element el)
Binds this TextMetrics instance to an element from which to copy existing CSS styles that can affect the size of the rendered text.

Parameters:
el - the element

bind

public void bind(El el)
Binds this TextMetrics instance to an element from which to copy existing CSS styles that can affect the size of the rendered text.

Parameters:
el - the element

getHeight

public int getHeight(java.lang.String text)
Returns the measured height of the specified text. For multiline text, be sure to call setFixedWidth(int) if necessary.

Parameters:
text - the text to be measured
Returns:
the height in pixels

getSize

public Size getSize(java.lang.String text)
Returns the size of the specified text based on the internal element's style and width properties.

Parameters:
text - the text to measure
Returns:
the size

getWidth

public int getWidth(java.lang.String text)
Returns the measured width of the specified text.

Parameters:
text - the text to measure
Returns:
the width in pixels

setFixedWidth

public void setFixedWidth(int width)
Sets a fixed width on the internal measurement element. If the text will be multiline, you have to set a fixed width in order to accurately measure the text height.

Parameters:
width - the width to set on the element