WoW:UIOBJECT SimpleHTML: Difference between revisions
(Added Section 'Creation Using Pure LUA') |
mNo edit summary |
||
Line 2: | Line 2: | ||
'''SimpleHTML''' widgets allow display of simple HTML markup as well as standard escape sequences. The two may be combined; if HTML is not valid (not well-formed XHTML), it will be displayed literaly. | '''SimpleHTML''' widgets allow display of simple HTML markup as well as standard escape sequences. The two may be combined; if HTML is not valid (not well-formed XHTML), it will be displayed literaly. | ||
==Supported HTML== | ''Note: SimpleHTML ''appears'' to have all the methods of [[#FontInstance|FontInstance]], and they can indeed be used in the same way to set the default font, but they all have an optional first parameter for which element's font to set ("h1", "h2", "p", etc). The Font instance methods are not reflected in the SimpleHTML frame until you SetText on the frame. It also appears that you can only supply the block elements and not the inline elements (ie Hyperlinks cannot be colored a different color). Other than that, see FontInstance for documentation of these methods.'' | ||
== Supported HTML == | |||
The following HTML tags are supported: | The following HTML tags are supported: | ||
; h1, h2, h3, p | ; h1, h2, h3, p | ||
: <code> <(h1|h2|h3|p) [align="(left|center|right)"]>...</(h1|h2|h3|p)></code> | : <code><(h1|h2|h3|p) [align="(left|center|right)"]>...</(h1|h2|h3|p)></code> | ||
: Text containers; following optional attributes are supported: | : Text containers; following optional attributes are supported: | ||
:*align - (left, center, right) controls positioning of the text element, | :*align - (left, center, right) controls positioning of the text element, | ||
; img | ; img | ||
:<code><img src="IMAGE_SOURCE" [align="(left|center|right)"] [width="NUM"] [height="NUM"] /></code> | :<code><img src="IMAGE_SOURCE" [align="(left|center|right)"] [width="NUM"] [height="NUM"] /></code> | ||
: Image, only outside of text containers; following attributes are supported: | : Image, only outside of text containers; following attributes are supported: | ||
Line 15: | Line 17: | ||
:*height - (number) height of image in pixels. | :*height - (number) height of image in pixels. | ||
:*src - (string) image source, for example Interface\Icons\Ability_Ambush | :*src - (string) image source, for example Interface\Icons\Ability_Ambush | ||
; a | ; a | ||
: <code><a href="LINK">TEXT</a></code> | : <code><a href="LINK">TEXT</a></code> | ||
: anchor (link only), only displayed inside text containers; following attributes are required: | : anchor (link only), only displayed inside text containers; following attributes are required: | ||
:*href - (string) link to pass OnHyperLink* widget handlers | :*href - (string) link to pass OnHyperLink* widget handlers | ||
;br | ;br | ||
: <code> <br /></code> | : <code><br /></code> | ||
: line break, no attributes. | : line break, no attributes. | ||
===Well-formed HTML=== | === Well-formed HTML === | ||
SimpleHTML will only display text as HTML if it is well-formed; the following conditions and quirks apply: | SimpleHTML will only display text as HTML if it is well-formed; the following conditions and quirks apply: | ||
* Tag names are case insensitive, img and iMg achieve the same result. | * Tag names are case insensitive, img and iMg achieve the same result. | ||
Line 30: | Line 32: | ||
* Quotes, less/greater than signs, and amperstands must be entity-escaped (<code>&quot;</code> <code>&lt;</code> <code>&gt;</code> <code>&amp;</code>). No other entity-escapes are supported. | * Quotes, less/greater than signs, and amperstands must be entity-escaped (<code>&quot;</code> <code>&lt;</code> <code>&gt;</code> <code>&amp;</code>). No other entity-escapes are supported. | ||
* Unrecognized tags are ignored entirely, even if they contain known tags inside; unrecognized attributes are ignored. | * Unrecognized tags are ignored entirely, even if they contain known tags inside; unrecognized attributes are ignored. | ||
* Document content must be enclosed in <code><html><body> | * Document content must be enclosed in <code><html><body> </body></html></code> tags. | ||
==Standard escape sequences== | == Standard escape sequences == | ||
SimpleHTML also supports the usual [[UI Escape Sequences]], which can be used to change font color, or as an alternative syntax to specify hyperlinks. | SimpleHTML also supports the usual [[UI Escape Sequences]], which can be used to change font color, or as an alternative syntax to specify hyperlinks. | ||
==Setting element styles== | == Setting element styles == | ||
It is possible to set different fonts for the text-container elements | It is possible to set different fonts for the text-container elements (h1, h2, h3, and p), using [[API_FontInstance_SetFont|SetFont]]: | ||
SimpleHTML:SetFont('h1', GameFontHighlightLarge); | SimpleHTML:SetFont('h1', GameFontHighlightLarge); | ||
Line 44: | Line 46: | ||
</SimpleHTML> | </SimpleHTML> | ||
==Creation Using Pure LUA== | == Creation Using Pure LUA == | ||
Creating a SimpleHTML object using pure LUA is very simple. | Creating a SimpleHTML object using pure LUA is very simple. | ||
MySimpleHTMLObject = CreateFrame('SimpleHTML'); | MySimpleHTMLObject = CreateFrame('SimpleHTML'); | ||
Line 53: | Line 55: | ||
The literal number 11 specifies the size of the font. | The literal number 11 specifies the size of the font. | ||
==Example== | == Example == | ||
The following is an example of a combination of HTML markup and [[UI Escape Sequences]], as well as custom element styles; the code below was passed to SimpleHTML:SetText() to generate the image on the right. | The following is an example of a combination of HTML markup and [[UI Escape Sequences]], as well as custom element styles; the code below was passed to SimpleHTML:SetText() to generate the image on the right. | ||
[[Image:SimpleHTMLExample.png|thumb|right|The finished product]] | [[Image:SimpleHTMLExample.png|thumb|right|The finished product]] |
Revision as of 06:53, 14 February 2015
← Widget API < SimpleHTML
SimpleHTML widgets allow display of simple HTML markup as well as standard escape sequences. The two may be combined; if HTML is not valid (not well-formed XHTML), it will be displayed literaly.
Note: SimpleHTML appears to have all the methods of FontInstance, and they can indeed be used in the same way to set the default font, but they all have an optional first parameter for which element's font to set ("h1", "h2", "p", etc). The Font instance methods are not reflected in the SimpleHTML frame until you SetText on the frame. It also appears that you can only supply the block elements and not the inline elements (ie Hyperlinks cannot be colored a different color). Other than that, see FontInstance for documentation of these methods.
Supported HTML
The following HTML tags are supported:
- h1, h2, h3, p
<(h1|h2|h3|p) [align="(left|center|right)"]>...</(h1|h2|h3|p)>
- Text containers; following optional attributes are supported:
- align - (left, center, right) controls positioning of the text element,
- img
<img src="IMAGE_SOURCE" [align="(left|center|right)"] [width="NUM"] [height="NUM"] />
- Image, only outside of text containers; following attributes are supported:
- align - (left, center, right) controls positioning of the image.
- width - (number) width of image in pixels.
- height - (number) height of image in pixels.
- src - (string) image source, for example Interface\Icons\Ability_Ambush
- a
<a href="LINK">TEXT</a>
- anchor (link only), only displayed inside text containers; following attributes are required:
- href - (string) link to pass OnHyperLink* widget handlers
- br
<br />
- line break, no attributes.
Well-formed HTML
SimpleHTML will only display text as HTML if it is well-formed; the following conditions and quirks apply:
- Tag names are case insensitive, img and iMg achieve the same result.
- All tags must be closed; closing tags must match the case of the opening tag; some tags are self-closing (br, img).
- Attribute values must be quoted; both double and single quotes are supported.
- Quotes, less/greater than signs, and amperstands must be entity-escaped (
"
<
>
&
). No other entity-escapes are supported. - Unrecognized tags are ignored entirely, even if they contain known tags inside; unrecognized attributes are ignored.
- Document content must be enclosed in
<html><body> </body></html>
tags.
Standard escape sequences
SimpleHTML also supports the usual UI Escape Sequences, which can be used to change font color, or as an alternative syntax to specify hyperlinks.
Setting element styles
It is possible to set different fonts for the text-container elements (h1, h2, h3, and p), using SetFont:
SimpleHTML:SetFont('h1', GameFontHighlightLarge);
You can also define font properties for these elements in your XML files, eg:
<SimpleHTML ...> <FontStringHeader1 inherits="GameFontHighlightLarge"/> </SimpleHTML>
Creation Using Pure LUA
Creating a SimpleHTML object using pure LUA is very simple.
MySimpleHTMLObject = CreateFrame('SimpleHTML');
After, the creation of the object you can assign the HTML code to be displayed. But, there is one more required step!
MySimpleHTMLObject:SetText('<html><body><h1>Heading1</h1><p>A paragraph</p></body></html>');
For the SimpleHTML object to actual render the HTML code you gave it (or plain text) a font must be set.
MySimpleHTMLObject:SetFont('Fonts\\FRIZQT__.TTF', 11);
The literal number 11 specifies the size of the font.
Example
The following is an example of a combination of HTML markup and UI Escape Sequences, as well as custom element styles; the code below was passed to SimpleHTML:SetText() to generate the image on the right.
<html><body> <h1>SimpleHTML Demo: Ambush</h1> <img src="Interface\Icons\Ability_Ambush" width="32" height="32" align="right"/> <p align="center">|cffee4400'You think this hurts? Just wait.'|r</p> <br/><br/> <p>Among every ability a rogue has at his disposal,<br/> Ambush is without a doubt the hardest hitting Rogue ability.</p> </body></html>