A simple HTML text renderer.

See the Text section of the manual for more details and a list of the supported HTML tags.

Static methods


A default method HtmlText uses to format assigned text. See HtmlText.formatText for details.


A default method HtmlText uses to load fonts for <font> tags with face attribute. See HtmlText.loadFont for details.


A default method HtmlText uses to load images for <img> tag. See HtmlText.loadImage for details.


new(font:Font, ?parent:Object)


@:value(true)condenseWhite:Bool = true

When enabled, condenses extra spaces (carriage-return, line-feed, tabulation and space character) to one space. If not set, uncondensed whitespace is left as is, as well as line-breaks.

@:value(1)imageSpacing:Float = 1

The spacing after <img> tags in pixels.

@:value(Bottom)imageVerticalAlign:ImageVerticalAlign = Bottom

Vertical alignment of the images in <img> tag relative to the text.

@:value(Accurate)lineHeightMode:LineHeightMode = Accurate

Line height calculation mode controls how much space lines take up vertically. Changing mode to Constant restores the legacy behavior of HtmlText.



Called when text is assigned, allowing to process arbitrary text to a valid XHTML.


Method that should return an h2d.Font instance for <font> tags with face attribute. By default calls HtmlText.defaultLoadFont method.

HtmlText does not cache font instances and it's recommended to perform said caching from outside. Due to internal structure, method should be deterministic and always return same Font instance on consequent calls with same name input.



A value contained in face attribute.


Method should return loaded font instance or null. If null is returned - currently active font is used.


Method that should return an h2d.Tile instance for <img> tags. By default calls HtmlText.defaultLoadImage method.

HtmlText does not cache tile instances. Due to internal structure, method should be deterministic and always return same Tile on consequent calls with same url input.



A value contained in src attribute.


Called on a tag click

Inherited Variables

Defined by Text

dropShadow:{dy:Float, dx:Float, color:Int, alpha:Float}

Adds simple drop shadow to the Text with specified offset, color and alpha. Causes text to be rendered twice (first drop shadow and then the text itself).


The font used to render text.

@:value(0)letterSpacing:Float = 0

Extra letter spacing in pixels.

@:value(0)lineSpacing:Float = 0

Extra line spacing in pixels.


When set, limits maximum line width and causes word-wrap. Affects positioning of the text depending on textAlign value.

When Text is affected by size constraints (see Object.constraintSize), smallest of the two is used for word-wrap.


Current rendered text.


Text align rules dictate how the text lines are positioned. See Align for specific details on each alignment mode.


Text RGB color. Alpha value is ignored.

read onlytextHeight:Float

Calculated text height.

Not a completely precise text metric and increments in the Font.lineHeight steps. In HtmlText, can be increased by various values depending on the active line font and HtmlText.lineHeightMode value.

read onlytextWidth:Float

Calculated text width. Can exceed maxWidth in certain cases.

Defined by Drawable


The color multiplier for the drawable. Can be used to adjust individually each of the four channels R,G,B,A (default [1,1,1,1])


Setting colorAdd will add the amount of color of each channel R,G,B,A to the object pixels.


Setting a colorKey color value will discard all pixels that have this exact color in the tile.


Setting a colorMatrix will apply a color transformation. See also adjustColor.


By enabling smoothing, scaling the object up or down will use hardware bilinear filtering resulting in a less crisp aspect.

By default smooth is null in which case Scene.defaultSmooth value is used.


Enables texture uv wrap for this Drawable, causing tiles with uv exceeding the texture size to repeat instead of clamping on edges.

Note that tileWrap does not use the Tile region as a wrapping area but instead uses underlying h3d.mat.Texture size. This is due to implementation specifics, as it just sets the Texture.wrap to either Repeat or Clamp. Because of that, proper Tile tiling can be expected only when the tile covers an entire Texture area.

Defined by Object


A flag that indicates whether the object was allocated or not.

When adding children to allocated objects, onAdd is being called immediately, otherwise it's delayed until the whole tree is added to a currently active Scene.

@:value(1.)alpha:Float = 1.

The amount of transparency of the Object.

@:value(Alpha)blendMode:BlendMode = Alpha

The blending mode of the object.

If there is no Object.filter active, only applies to the current object (not inherited by children). Otherwise tells how the filter is blended with background.


The post process filter for this object.

When set, Object.alpha value affects both filter and object transparency (use Drawable.color.a to set transparency only for the object).


The name of the object. Can be used to retrieve an object within a tree by using Object.getObjectByName.

read onlynumChildren:Int

How many immediate children this object has.

read onlyparent:Object

The parent object in the scene tree.


The parent container of this object. See Object.contentChanged for more details.


A flag that indicates that the object transform was modified and absolute position recalculation is required.

Automatically cleared on Object.sync and can be manually synced with the Object.syncPos.

@:value(0)rotation:Float = 0

The rotation angle of this object, in radians.

@:value(1)scaleX:Float = 1

The amount of horizontal scaling of this object.

@:value(1)scaleY:Float = 1

The amount of vertical scaling of this object.

@:value(true)visible:Bool = true

Is the object and its children are displayed on screen.

@:value(0)x:Float = 0

The x position (in pixels) of the object relative to its parent.

@:value(0)y:Float = 0

The y position (in pixels) of the object relative to its parent.

Inherited Methods

Defined by Text


Calculates and returns width of the provided text with settings this Text instance.

private@:value({ prevChar : -1, afterData : 0., leftMargin : 0. })@:dox(show)splitRawText(text:String, leftMargin:Float = 0., afterData:Float = 0., ?font:Font, ?sizes:Array<Float>, prevChar:Int = -1):String

Advanced usage Perform a word-wrap of the text based on this Text settings.



String to word-wrap.


Starting x offset of the first line.


Minimum remaining space required at the end of the line.


Optional overriding font to use instead of currently set.


Optional line width array. Will be populated with sizes of split lines if present. Sizes will include both leftMargin in it's first line entry.


Optional character code for concatenation purposes (proper kernings).


Extra validation of the text variable when it's changed. Override to add custom validation.

Only validation of the text is allowed, and attempting to change the text value will lead to undefined behavior.

Defined by Drawable


Add a shader to the drawable shaders.

Keep in mind, that as stated before, drawable children do not inherit Drawable properties, which includes shaders.


Set the Drawable.colorMatrix value by specifying which effects to apply. Calling adjustColor() without arguments will reset the colorMatrix to null.

@:value({ toHxsl : true })getDebugShaderCode(toHxsl:Bool = true):String

Returns the built shader code, can be used for debugging shader assembly



Whether return an HXSL shader or the native shading language of the backend.


Returns the first shader of the given shader class among the drawable shaders.



The class of the shader to look up.


Returns an iterator of all drawable shaders


Remove a shader from the drawable shaders, returns true if found or false if it was not part of our shaders.

Defined by Object

private@:dox(show)addBounds(relativeTo:Object, out:Bounds, dx:Float, dy:Float, width:Float, height:Float):Void

Adds specified area in local coordinate space to the bounds. Expected to be used within Object.getBoundsRec.



An object relative to which the Object bounds coordinates should be. If not set, coordinates are in absolute coordinate space.


An output Bounds instance.


The top-left X offset of the added bounds rectangle.


The top-left Y offset of the added bounds rectangle.


The width of the added bounds rectangle.


The height of the added bounds rectangle.


Add a child object at the end of the children list.

addChildAt(s:Object, pos:Int):Void

Insert a child object at the specified position of the children list.


Internal usage Calculates the absolute object position transform. See `Object.syncPos` for a safe position sync method. This method does not ensure that object parents also have up-to-date transform nor does it clear the `Object.posChanged` flag.

private@:dox(show)clipBounds(ctx:RenderContext, bounds:Bounds):Void

Internal usage Clip a local bounds with our global viewport. Used during filter rendering in order to clip out areas that are off-screen and should not be rendered.

private@:dox(show)constraintSize(maxWidth:Float, maxHeight:Float):Void

Advanced usage This can be called by a parent container to constraint the size of its children. Negative value mean that constraint is to be disabled.

For example, Text constraints it's maximum width, causing word-wrap to occur within constrained area.

See also:


Tells if the object is contained into this object children, recursively.


Advanced usage Called by the children of a container object if they have `parentContainer` defined in them. Primary use-case is when the child size got changed, requiring content to reevaluate positioning such as `Flow` layouts, but also can be used for other purposes.


Override this method in order to add custom graphics rendering to your Object. draw is invoked before rendering of the object children.


Draw the object and all its children into the given Texture.

drawToTextures(texs:Array<Texture>, outputs:Array<Output>):Void

Draw the object and all its children into the given Textures.

private@:dox(show)emitTile(ctx:RenderContext, tile:Tile):Void

Draws single Tile instance with this Object transform.

find<T>(f:Object ‑> Null<T>):Null<T>

Find a single object in the tree by calling f on each and returning the first not-null value returned, or null if not found.

findAll<T>(f:Object ‑> Null<T>, ?arr:Array<T>):Array<T>

Find several objects in the tree by calling f on each and returning all the not-null values returned.



An optional array instance to fill results with. Allocates a new array if not set.


Returns the updated absolute position matrix. See Object.getMatrix for current matrix values.

getBounds(?relativeTo:Object, ?out:Bounds):Bounds

Return the bounds of the object for its whole content, recursively.



An optional object relative to coordinates of which bounds are returned. Returns bounds in the absolute coordinates if not set.


An optional bounds instance to fill. Allocates new Bounds instance and returns it if not set.

private@:dox(show)getBoundsRec(relativeTo:Object, out:Bounds, forSize:Bool):Void

Override this method in order to expand the reported bounds of an object. Object.addBounds can be used to add bounds with respect to relativeTo. Do not remove the super call.



An object relative to which the Object bounds coordinates should be.


An output Bounds instance.


Whether it's being called for Object.getSize or Object.getBounds.


Return the nth element among the immediate children list of this object, or null if there is no Object at this position.


Return the index of the object o within the immediate children list of this object, or -1 if it is not part of the children list.


Populates Matrix with current absolute object transform values. See Object.getAbsPos for up-to-date values.


Search for an object recursively by name, return null if not found.


Return the total number of children in the whole tree, recursively.


Returns an h2d.Scene down the hierarchy tree or null if object is not added to Scene.


Similar to getBounds(parent), but instead of the full content, it will return the size based on the alignment of the object. For instance for a text, Object.getBounds will return the full glyphs size whereas getSize will ignore the pixels under the baseline.



An optional bounds instance to fill. Allocates new Bounds instance and returns it if not set.


Convert an absolute screen position into a local position relative to the object origin, applying all the inherited transforms.



A position to convert and return. Modifies the Point instance as is.


Return an iterator over this object immediate children


Convert a local position (or [0,0] if pt is null) relative to the object origin into an absolute screen position, applying all the inherited transforms.



An optional position to convert and return. Allocates new Point at 0,0 position if not set. Modifies the Point instance as is.

move(dx:Float, dy:Float):Void

Move the object by the specified amount along its current direction (Object.rotation angle).


Sent when object is being added to an allocated scene.

Do not remove the super call when overriding.


Should be called when Object content was changed in order to notify parent container. See Object.contentChanged.


Sent when object was already allocated and moved within scene object tree hierarchy.

Do not remove the super call when overriding.



Whether Object was moved withing same parent (through Layers.ysort for example) or relocated to a new one.


Sent when object is removed from the allocated scene.

Do not remove the super call when overriding.


Same as parent.removeChild(this), but does nothing if parent is null.


Remove the given object from the immediate children list of the object if it's part of it.


Remove all children from the immediate children list.


Rotate the object by the given angle (in radians)


Scale uniformly the object by the given factor.


Sets the parent container for this Object and it's children. See Object.contentChanged for more details.

inlinesetPosition(x:Float, y:Float):Void

Set the position of the object relative to its parent.


Set the uniform scale for the object.


Performs a sync of data for rendering (such as absolute position recalculation). While this method can be used as a substitute to an update loop, it's primary purpose it to prepare the Object to be rendered.

Do not remove the super call when overriding.


Ensures that object has an up-to-date position transform.