Structured Text: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Feature | Informative | " to "{{Feature|informative|")
 
(56 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== Description ==
{{TOC|side}}
Structured Text is a [[Data Types|Data Type]] that has been introduced with {{arma1}}. It is a '''rich text''', which is able to include images and formatting. It can be created using XML-like syntax, as seen [[#Markup|below]]. However, using XML-like syntax alone is not going to turn a normal string into structured text, it should be converted to TEXT first.


Rich text, which is able to include images and formatting. It can be created using XML like syntax, as seen in [[parseText]]. Introduced with Armed Assault, does not refer to Cold War Crisis or Resistance.
{{Feature|important|
This type is not meant to be used with remote execution. Executing <sqf inline>[parseText "test"] remoteExec ["hint"];</sqf> will result in the following rpt message:<br>
{{hl|Performance warning: SimpleSerialization::Write 'params' is using type of ',TEXT' which is not optimized by simple serialization, falling back to generic serialization, use generic type or ask for optimizations for these types}}<br>
Parse the text on the receiving client instead.
}}
 
 
== Commands ==
 
* See [[:Category:Command Group: Structured Text|Command Group: Structured Text]] for all related commands.


'''Related commands:''' [[parseText]], [[composeText]], [[ctrlSetStructuredText]], [[hintC_structuredText]]


== Markups ==
== Markups ==
=== Syntax ===
All attribute values should be encapsulated in double {{hl|"..."}} or single {{hl|'...'}} quotes. Both of the following are correct:
<syntaxhighlight lang="html">
<t size="2.0">Large text</t>
<t size='2.0'>Large text</t>
</syntaxhighlight>
{{Feature|warning|The following will log an ''.rpt'' error {{hl|Unknown attribute .0}} and only number 2 would be taken into account:
<syntaxhighlight lang="html">
<t size=2.0>Large text</t>
</syntaxhighlight>
}}


=== Text ===
=== Text ===
Texts could be created with the following markup:
Texts could be created with the following markup:
* <tt><nowiki><t>Hello World!</t></nowiki></tt>
<syntaxhighlight lang="html">
Or could also be inserted via the [[composeText]] and [[text]] commands
<t>Hello World!</t>
</syntaxhighlight>
Or could also be inserted via the [[composeText]] / [[formatText]] and [[text]] commands.


==== Non-break Space ====
==== Special characters ====
A non-break space, commonly known as '''&amp;nbsp;''' shows as '''?''' in structured text control. Use alternative which is:'''&amp;#160;'''
To insert special characters, such as {{hl|<}}, {{hl|>}}, etc. you can use the {{Link|https://dev.w3.org/html5/html-author/charref|HTML representation}} of that character, e.g.:
<nowiki><t>FIVE&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;SPACES</t></nowiki>
{| class="wikitable"
|-
! Character !! HTML
|-
| < || {{hl|&amp;lt;}}
|-
| > || {{hl|&amp;gt;}}
|-
| non-breaking space || {{hl|&amp;#160;}}
|-
| ... || ...
|}
{{Feature|important|Using a special character directly will result in it being displayed as "?" or, in the case of writing "<TEXT>", will result in an error in the [[RPT]]: {{hl|Wrong text element 'TEXT'}}
}}


=== Line break ===
=== Line break ===
Line breaks could be created with either of the following markups:
Line breaks could be created with either of the following markups:
* <tt><nowiki><br/></nowiki></tt>
<syntaxhighlight lang="html">
* <tt><nowiki><br></br></nowiki></tt>
<br/>
Or could also be inserted via the [[composeText]] and [[lineBreak]] commands
<br />
<br></br>
</syntaxhighlight>
Or could also be inserted via the [[composeText]] / [[formatText]] and [[lineBreak]] commands.


=== Image ===
=== Image ===
Images could be created with either of the following markups:
Images could be created with either of the following markups:
* <tt><nowiki><img image="\a3\Data_f\Flags\flag_Altis_co.paa"/></nowiki></tt>
<syntaxhighlight lang="html">
* <tt><nowiki><img image="\a3\Data_f\Flags\flag_Altis_co.paa"></img></nowiki></tt>
<img image='\a3\Data_f\Flags\flag_Altis_co.paa'/>
Or could also be inserted via the [[composeText]] and [[image]] commands.
<img image='\a3\Data_f\Flags\flag_Altis_co.paa' />
<img image='\a3\Data_f\Flags\flag_Altis_co.paa'></img>
</syntaxhighlight>
Or could also be inserted via the [[composeText]] / [[formatText]] and [[image]] commands.
 
{{ArgTitle|3|Hyperlink|{{GVI|arma3}}}}
 
Clickable links, similar to HTML hyperlinks, could be created with the following markup:
<syntaxhighlight lang="html">
<a href='http://arma3.com'>Arma 3</a>
</syntaxhighlight>
By default the links are not underlined or have a different color to stand out. These attributes should be added separately.<br>
Note: ''&'' should be escaped by ''&amp;amp;''.
<syntaxhighlight lang="html">
<a href='https://arma3.com/?foo&bar'>Example URL A</a> <!-- will not work -->
<a href='https://arma3.com/?foo&amp;bar'>Example URL B</a> <!-- will work -->
</syntaxhighlight>


=== Hyperlink ===
Hyperlinks could be created the following markup: ''(Since ["Arma 3","Arma3",125,126163,"Development"])''
* <tt><nowiki><a href="http://google.com">Google</a></nowiki></tt>
Other examples:
<nowiki><a color="#0000FF" href="http://arma3.com">Arma 3</a></nowiki>
<nowiki><a underline="true" color="#0000FF" href="http://killzonekid.com">KK's&amp;#160;blog</a></nowiki>
Create clickable image:
<code>_ctrl = [[findDisplay]] 46 [[createDisplay]] "RscDisplayEmpty" [[ctrlCreate]] ["RscStructuredText", -1];
_ctrl [[ctrlSetPosition]] [0,0,1,1];
_ctrl [[ctrlCommit]] 0;
_ctrl [[ctrlSetStructuredText]] [[parseText]] "<nowiki><a color='#00FF00' size='5' href='http://arma3.com'><img image='\A3\weapons_f\ammoBoxes\data\ui\map_AmmoBox_F_CA.paa' /></a></nowiki>";</code>
[[Category: Data Types]]


== Attributes ==
== Attributes ==
The following inline text attributes are supported:
* <tt>size</tt>
* <tt>align</tt>
* <tt>valign</tt>
* <tt>color</tt>
* <tt>font</tt>
* <tt>image</tt>
* <tt>shadow</tt>
* <tt>shadowOffset</tt>
* <tt>shadowColor</tt>
* <tt>underline</tt>
* <tt>href</tt>
* <tt>colorLink</tt>


=== Color ===
The following inline attributes are supported:
In format [http://en.wikipedia.org/wiki/RGB RGB] or [http://en.wikipedia.org/wiki/ARGB ARGB]
{{Columns|4|
<t color='#ff0000'>Red text</t>
* {{hl|size}}
<t color='#99ffffff'>Transparent white text</t>
* {{hl|color}}
<t colorLink='#0000ff'><a href='http://www.arma3.com/'>Blue link</a></t>
* {{hl|font}}
* {{hl|align}}
* {{hl|valign}}
* {{hl|underline}}
* {{hl|shadow}}
* {{hl|shadowColor}}
* {{hl|shadowOffset}}
* {{hl|colorLink}}
* {{hl|href}}
* {{hl|image}}
}}


=== Size ===
=== Size ===
The multiplier for the value of control config property <tt>size</tt>. Default is 1, meaning that the height of letters will be equal to the value set in config. Setting this to 2 will make letters 2 times the size, etc. If the control is defined as follows:


<syntaxhighlight lang=cpp>class MyStructuredText: RscStructuredText  
The structured text {{hl|size}} attribute is a multiplier for the value of control config property {{hl|size}}. Default is 1, meaning that the height of letters will be equal to the value set in config. Setting this to 2 will make letters 2 times the size, 0.5 will make them half the size, etc. If the control is defined as follows:
 
<syntaxhighlight lang="cpp">
class MyStructuredText : RscStructuredText  
{
{
...
...
Line 71: Line 118:
size = 0.04;
size = 0.04;
...
...
};</syntaxhighlight>
};
</syntaxhighlight>


Then the structured text:
Then the structured text:
<code>_control [[ctrlSetStructuredText]] [[parseText]] "<t size='2'>Hello!</t>";</code>
<sqf>_control ctrlSetStructuredText parseText "<t size='2'>Hello!</t>";</sqf>
Will result in a total text size of 0.04*2 = 0.08. Unfortunately, there is no script command to set or get the value of config <tt>size</tt> property dynamically.
Will result in a total text size of 0.04 * 2 = 0.08. Unfortunately, there is no script command to set or get the value of config {{hl|size}} property dynamically.
 
=== Color ===
 
The {{hl|color}} attribute is similar to HTML hex color and could either have format {{Link|https://en.wikipedia.org/wiki/RGB|<nowiki>#RRGGBB</nowiki>}} or {{Link|https://en.wikipedia.org/wiki/ARGB|<nowiki>#AARRGGBB</nowiki>}}.
<syntaxhighlight lang="html">
<t color='#ff0000'>Red text</t>
<t color='#99ffffff'>Semi-transparent white text</t>
</syntaxhighlight>


=== Font ===
=== Font ===
Font are defined in ''CfgFontFamilies''
<t font='Zeppelin33'>Bold Text</t>


=== Align ===
The value for the {{hl|font}} attribute could be found in {{hl|CfgFontFamilies}} config. Some of the {{arma3}} fonts:
Parameter can be 'left', 'center', 'right'
{{Columns|4|
<t align='center'>Centered Text</t>
* {{hl|EtelkaMonospacePro}}
* {{hl|EtelkaMonospaceProBold}}
* {{hl|EtelkaNarrowMediumPro}}
* {{hl|LCD14}}
* {{hl|LucidaConsoleB}}
* {{hl|PuristaBold}}
* {{hl|PuristaLight}}
* {{hl|PuristaMedium}}
* {{hl|PuristaSemibold}}
* {{hl|RobotoCondensed}}
* {{hl|RobotoCondensedBold}}
* {{hl|RobotoCondensedLight}}
* {{hl|TahomaB}}
}}
<syntaxhighlight lang="html">
<t font='PuristaBold'>Bold Text</t>
<t font='LCD14'>Wicked looking text</t>
</syntaxhighlight>
 
=== Horizontal Alignment ===
 
The {{hl|align}} attribute controls horizontal text alignment and could be one of the following:
* {{hl|left}}
* {{hl|center}}
* {{hl|right}}
<syntaxhighlight lang="html">
<t align='right'>Text displayed to the right</t>
</syntaxhighlight>
 
=== Vertical Alignment ===
 
The {{hl|valign}} attribute controls vertical text alignment and could be one of the following:
* {{hl|top}}
* {{hl|middle}}
* {{hl|bottom}}
<syntaxhighlight lang="html">
<t valign='bottom'>Text displayed at the bottom</t>
</syntaxhighlight>


=== Underline ===
=== Underline ===
<t underline='true'>Underlined Text</t>
 
NOTE: Using regular spaces might split the underline between words. To have a continuous underline, you must use non-breaking spaces, via [https://en.wikipedia.org/wiki/Non-breaking_space#Keyboard_entry_methods Alt+255] or the following code:
The {{hl|underline}} attribute underlines each individual word in text. The normal spaces are not underlined.
<code>[[format]] ["<t underline='true'>%1</t>", "Underlined Text" [[splitString]] " " [[joinString]] [[toString]] [160]]</code>
<syntaxhighlight lang="html">
<t underline='1'>Underlined Text</t>
</syntaxhighlight>
{{Feature|informative|
If you would like to have a continuous underline between words, use non-breaking spaces. This could be achieved in several ways:
* Insertion from keyboard: {{Link|https://en.wikipedia.org/wiki/Non-breaking_space#Keyboard_entry_methods|Alt+255}}
* Scripted method:  
<sqf>hint parseText format ["<t underline='1'>%1</t>", "Underlined Text" splitString " " joinString toString [160]]</sqf>
* Using HTML code:
<sqf>hint parseText "<t underline='1'>Underlined&amp;#160;Text</t>";</sqf>
}}


=== Shadow ===
=== Shadow ===
Parameter can be '0' (no shadow), '1' (classic shadow, can be colored), '2' outline (always black)
<t shadow='1'>Text with shadow</t>
<t shadow='1' shadowColor='#ff0000'>Text with red Shadow</t>
<t shadow='2'>Text with outline</t>


=== Space ===
The {{hl|shadow}} attribute controls the appearance of shadow/outline around text and could be one of the following:
A non-break space, commonly known as '''&amp;nbsp;''' shows as '''?''' in structured text control. Use alternative which is:'''&amp;#160;'''
* {{hl|0}} - normal text
<t size='2.0'>FIVE&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;SPACES</t>
* {{hl|1}} - classic shadow (text ghosting below and to the right)
* {{hl|2}} - outline (slight, always black, outline around characters)
<syntaxhighlight lang="html">
<t shadow='0'>Text with no shadow</t>
<t shadow='1'>Text with default black shadow</t>
<t shadow='2'>Text with default black outline</t>
</syntaxhighlight>
 
=== Shadow Color ===
 
The {{hl|shadowColor}} attribute controls the color of the shadow (not the outline, which is always black for some reason)
<syntaxhighlight lang="html">
<t shadow='1' shadowColor='#ff0000'>Text with red shadow</t>
</syntaxhighlight>
 
=== Shadow Offset ===


=== Syntax ===
The {{hl|shadowOffset}} attribute controls how far is the shadow offset from the text source (has no effect on the outline)
All operator types values should be encapsulated with <nowiki>''</nowiki>, for example, the following will log an .rpt error "Unknown attribute .0" and only 2 would be taken into account:
<syntaxhighlight lang="html">
<t size=2.0>Large text</t>
<t shadow='1' shadowColor='#ff0000' shadowOffset='0.5'>Text with red shadow, which is offset by half character size</t>
While the following is correct:
</syntaxhighlight>
<t size='2.0'>Large text</t>
 
=== Link Color ===
 
Will change the color of the text if the text is a link, otherwise the text color is unaffected.
<syntaxhighlight lang="html">
<t colorLink='#0000ff'><a href='http://www.arma3.com/'>Blue text</a></t>
<a colorLink='#0000ff' href='http://www.arma3.com/'>Blue text too</a>
<t colorLink='#0000ff'>Normal text color</t>
</syntaxhighlight>
 
=== Hyperlink Reference ===
 
The {{hl|href}} attribute is essential part of the {{hl|<nowiki><a></nowiki>}} tag and should contain URL of the destination (See [[#Hyperlink | Hyperlink]]).
 
=== Image Reference ===
 
The {{hl|image}} attribute is essential part of the {{hl|<nowiki><img></nowiki>}} tag and should contain filepath to the image (See [[Structured_Text#Image | Image]]).
 
 
== SQF Code Examples ==
 
{{hl|align}} {{hl|valign}} demo:
<sqf>hint parseText "<t size='3'><t size='1' valign='top' align='right'>Top Right</t> <t size='1' valign='middle' align='center'>Middle Center</t> <t size='1' valign='bottom' align='left'>Bottom Left</t></t>";</sqf>
{{Feature|informative|Sometimes an extra space is required when outputting to [[hint]]. In the above example spaces between {{hl|<nowiki><t></nowiki>}}s inside another {{hl|<nowiki><t></nowiki>}} wrapper ensure that the hint will be 3 lines tall}}
 
Create clickable image:
<sqf>
_ctrl = findDisplay 46 createDisplay "RscDisplayEmpty" ctrlCreate ["RscStructuredText", -1];
_ctrl ctrlSetPosition [0,0,1,1];
_ctrl ctrlCommit 0;
_ctrl ctrlSetStructuredText parseText "<a color='#00FF00' size='5' href='http://arma3.com'><img image='\A3\weapons_f\ammoBoxes\data\ui\map_AmmoBox_F_CA.paa' /></a>";
</sqf>
 
The use of [[composeText]]:
<sqf>
_separator = parseText "<br />------------------------<br />";
_image = "\a3\Data_f\Flags\flag_Altis_co.paa";
_txt1 = text "left";
_txt1 setAttributes ["align", "left"];
_txt2 = text "right";
_txt2 setAttributes ["align", "right"];
_structuredText = composeText [image _image, lineBreak, lineBreak, text "Heading Text", _separator, _txt1, _txt2];
hint _structuredText;
</sqf>


== Code Examples: ==


<code>_separator1 = [[parseText]] <nowiki>"<br />------------------------<br /></nowiki>";
[[Category:Data Types]]
_image = "\ca\ui\textures\aus_flag.paa";
_txt = [[composeText]] <nowiki>[</nowiki>[[image]] _image, "Heading Text", _separator1, "Content"];
[[hint]] _txt;</code>

Latest revision as of 21:42, 16 May 2024

Structured Text is a Data Type that has been introduced with Armed Assault. It is a rich text, which is able to include images and formatting. It can be created using XML-like syntax, as seen below. However, using XML-like syntax alone is not going to turn a normal string into structured text, it should be converted to TEXT first.

This type is not meant to be used with remote execution. Executing [parseText "test"] remoteExec ["hint"]; will result in the following rpt message:

Performance warning: SimpleSerialization::Write 'params' is using type of ',TEXT' which is not optimized by simple serialization, falling back to generic serialization, use generic type or ask for optimizations for these types

Parse the text on the receiving client instead.


Commands


Markups

Syntax

All attribute values should be encapsulated in double "..." or single '...' quotes. Both of the following are correct:

<t size="2.0">Large text</t>
<t size='2.0'>Large text</t>
The following will log an .rpt error Unknown attribute .0 and only number 2 would be taken into account:
<t size=2.0>Large text</t>

Text

Texts could be created with the following markup:

<t>Hello World!</t>

Or could also be inserted via the composeText / formatText and text commands.

Special characters

To insert special characters, such as <, >, etc. you can use the HTML representation of that character, e.g.:

Character HTML
< &lt;
> &gt;
non-breaking space &#160;
... ...
Using a special character directly will result in it being displayed as "?" or, in the case of writing "<TEXT>", will result in an error in the RPT: Wrong text element 'TEXT'

Line break

Line breaks could be created with either of the following markups:

<br/>
<br />
<br></br>

Or could also be inserted via the composeText / formatText and lineBreak commands.

Image

Images could be created with either of the following markups:

<img image='\a3\Data_f\Flags\flag_Altis_co.paa'/>
<img image='\a3\Data_f\Flags\flag_Altis_co.paa' />
<img image='\a3\Data_f\Flags\flag_Altis_co.paa'></img>

Or could also be inserted via the composeText / formatText and image commands.

Hyperlink

Clickable links, similar to HTML hyperlinks, could be created with the following markup:

<a href='http://arma3.com'>Arma 3</a>

By default the links are not underlined or have a different color to stand out. These attributes should be added separately.
Note: & should be escaped by &amp;.

<a href='https://arma3.com/?foo&bar'>Example URL A</a> <!-- will not work -->
<a href='https://arma3.com/?foo&amp;bar'>Example URL B</a> <!-- will work -->


Attributes

The following inline attributes are supported:

  • size
  • color
  • font
  • align
  • valign
  • underline
  • shadow
  • shadowColor
  • shadowOffset
  • colorLink
  • href
  • image

Size

The structured text size attribute is a multiplier for the value of control config property size. Default is 1, meaning that the height of letters will be equal to the value set in config. Setting this to 2 will make letters 2 times the size, 0.5 will make them half the size, etc. If the control is defined as follows:

class MyStructuredText : RscStructuredText 
{
	...
	text = "Hello!";
	size = 0.04;
	...
};

Then the structured text:

_control ctrlSetStructuredText parseText "<t size='2'>Hello!</t>";

Will result in a total text size of 0.04 * 2 = 0.08. Unfortunately, there is no script command to set or get the value of config size property dynamically.

Color

The color attribute is similar to HTML hex color and could either have format #RRGGBB or #AARRGGBB.

<t color='#ff0000'>Red text</t>
<t color='#99ffffff'>Semi-transparent white text</t>

Font

The value for the font attribute could be found in CfgFontFamilies config. Some of the Arma 3 fonts:

  • EtelkaMonospacePro
  • EtelkaMonospaceProBold
  • EtelkaNarrowMediumPro
  • LCD14
  • LucidaConsoleB
  • PuristaBold
  • PuristaLight
  • PuristaMedium
  • PuristaSemibold
  • RobotoCondensed
  • RobotoCondensedBold
  • RobotoCondensedLight
  • TahomaB
<t font='PuristaBold'>Bold Text</t>
<t font='LCD14'>Wicked looking text</t>

Horizontal Alignment

The align attribute controls horizontal text alignment and could be one of the following:

  • left
  • center
  • right
<t align='right'>Text displayed to the right</t>

Vertical Alignment

The valign attribute controls vertical text alignment and could be one of the following:

  • top
  • middle
  • bottom
<t valign='bottom'>Text displayed at the bottom</t>

Underline

The underline attribute underlines each individual word in text. The normal spaces are not underlined.

<t underline='1'>Underlined Text</t>
If you would like to have a continuous underline between words, use non-breaking spaces. This could be achieved in several ways:
  • Insertion from keyboard: Alt+255
  • Scripted method:

hint parseText format ["<t underline='1'>%1</t>", "Underlined Text" splitString " " joinString toString [160]]

  • Using HTML code:
hint parseText "<t underline='1'>Underlined&amp;#160;Text</t>";

Shadow

The shadow attribute controls the appearance of shadow/outline around text and could be one of the following:

  • 0 - normal text
  • 1 - classic shadow (text ghosting below and to the right)
  • 2 - outline (slight, always black, outline around characters)
<t shadow='0'>Text with no shadow</t>
<t shadow='1'>Text with default black shadow</t>
<t shadow='2'>Text with default black outline</t>

Shadow Color

The shadowColor attribute controls the color of the shadow (not the outline, which is always black for some reason)

<t shadow='1' shadowColor='#ff0000'>Text with red shadow</t>

Shadow Offset

The shadowOffset attribute controls how far is the shadow offset from the text source (has no effect on the outline)

<t shadow='1' shadowColor='#ff0000' shadowOffset='0.5'>Text with red shadow, which is offset by half character size</t>

Link Color

Will change the color of the text if the text is a link, otherwise the text color is unaffected.

<t colorLink='#0000ff'><a href='http://www.arma3.com/'>Blue text</a></t>
<a colorLink='#0000ff' href='http://www.arma3.com/'>Blue text too</a>
<t colorLink='#0000ff'>Normal text color</t>

Hyperlink Reference

The href attribute is essential part of the <a> tag and should contain URL of the destination (See Hyperlink).

Image Reference

The image attribute is essential part of the <img> tag and should contain filepath to the image (See Image).


SQF Code Examples

align valign demo:

hint parseText "<t size='3'><t size='1' valign='top' align='right'>Top Right</t> <t size='1' valign='middle' align='center'>Middle Center</t> <t size='1' valign='bottom' align='left'>Bottom Left</t></t>";

Sometimes an extra space is required when outputting to hint. In the above example spaces between <t>s inside another <t> wrapper ensure that the hint will be 3 lines tall

Create clickable image:

_ctrl = findDisplay 46 createDisplay "RscDisplayEmpty" ctrlCreate ["RscStructuredText", -1]; _ctrl ctrlSetPosition [0,0,1,1]; _ctrl ctrlCommit 0; _ctrl ctrlSetStructuredText parseText "<a color='#00FF00' size='5' href='http://arma3.com'><img image='\A3\weapons_f\ammoBoxes\data\ui\map_AmmoBox_F_CA.paa' /></a>";

The use of composeText:

_separator = parseText "<br />------------------------<br />"; _image = "\a3\Data_f\Flags\flag_Altis_co.paa"; _txt1 = text "left"; _txt1 setAttributes ["align", "left"]; _txt2 = text "right"; _txt2 setAttributes ["align", "right"]; _structuredText = composeText [image _image, lineBreak, lineBreak, text "Heading Text", _separator, _txt1, _txt2]; hint _structuredText;