Table of Contents
16.2 TextLabel
The Text-Label component can display simple HTML text, also known as RichText. A text label will always be used if you only want to output the text to be displayed in plain format:
Figure 16.2.1: Display of extensive RichText in a TextLabel
16.2.1 Text Label Properties
In a text label, you can display text that you assign via the Text Label, Text or Text Label, Caption property. Further properties of a text label are described in the table:
| TextLabel | Data type | Default | Description |
|---|---|---|---|
| .Alignment | Integer | 0 | Sets the horizontal alignment of the text in the text label or returns its alignment→ class Align |
| .Autoresize | Boolean | False | Specifies whether the size of the text label automatically adapts to the text. |
| .Border | Integer | None | Sets the border of the text label or determines the border shape or specifies whether a border exists and which border shape is used → class Border |
| .Text | String | ~ | Sets or returns the text of the text label to be displayed |
| .Padding | Integer | 0 | Sets a distance between text and text label boundaries (edge) |
| .Transparent | Boolean | False | Sets the transparency of the text label or specifies whether the text label is transparent |
Table 16.2.1.1: Selected text label properties
16.2.2 Syntax of RichText in Gambas
RichText in Gambas uses a subset of HTML. The following HTML tags are allowed to mark text elements:
<h1>, <h2>, <h3>, <h4>, <h5>, <h6> → Headlines <b> → Bold font <i> → Italic <s> → Crossed out <u> → Underlined <sub> → Subscript <sup> → Superscript <small> → Small <p> → Paragraph <br> → Line break <a> → Link <font> → Font
Information about <font> tag is given in the following table. Please note that the <font> tag no longer exists under HTML5.
| Font attribute | Values | Notes |
|---|---|---|
| Face | Font Family | Various fonts can be specified in a comma-separated list |
| Color | Color values via color names or as hexadecimal number or in RGB format | color = Red, color = #C3DDFF → light blue, color = RGB (255,175,255,95) → orange |
| Size | Font size (default=3) | Absolute values from 1 to 7 or the two relative values -1 for smaller font or +1 for larger font |
Table 16.2.2.2.1: Information about <font> tag
With <a>….</a> insert a link into the RichText. It is underlined and displayed in blue format - as it is expected for a hyperlink - but has no effect! After right-clicking on the link, you can copy the link address in the context menu.
These tags are also tested to mark single or multi-line source code, insert a horizontal line or display an unsorted list of n entries:
<tt> → single-line source text <pre> → multiline source code <hr> → horizontal line <ul> → unsorted list <li> → list
Hints:
- Change the font properties of a text label using the <font> tag. If you only want to use one font with one style and size, you can do without it and set the font properties in the Properties window (IDE) or in the source code.
- Working with CSS is not supported, so that this text in a text label is not displayed as it would be possible in any browser.
- It has proved to be a good idea to adapt the size of the text label to the text to be displayed.
- You can use any HTML entity → http://unicode.e-workers.de/entities.php
- To quickly and efficiently mark a longer text with the above tags (RichText) a text editor like BlueFish is sufficient. Create an HTML file with this editor and save it in the project directory of the Gambas project that should use RichText. In the IDE, you can open and edit the contents of the HTML file with the text editor BlueFish.
Like a simple label, you react with the TextLabel.Adjust() method if the text for a text label has changed at runtime and the text label size should automatically adapt to the changed text:
Public Sub btnAdjust_Click() TextLabel.Wrap = False ' Bei längeren Textpassagen TRUE TextLabel.AutoResize = False TextLabel.Padding = 8 TextLabel.Text = "<font size=4 face=Ubuntu color=#C3DDFF>IP-Adresse → IPv4</font>" TextLabel.Text &= "<hr>Informationen auf <a href=http://de.wikipedia.org/wiki/IPv4>" TextLabel.Text &= "www.wikipedia.de</a>!" TextLabel.Adjust() End ' btnAdjust_Click() Public Sub btnAutoResize_Click() TextLabel.AutoResize = True TextLabel.Padding = 8 TextLabel.Text = "<font size=+1 face=Arial color=Red>Neue IP-Adresse → IPv6</font>" TextLabel.Text &= "<hr>Informationen auf <a href=http://de.wikipedia.org/wiki/IPv6>" TextLabel.Text &= "www.wikipedia.de</a>!" End ' btnAutoResize_Click()
Alternatively, set the TextLabel. AutoResize property to True to achieve the same effect.
16.2.3 Project {c_hl} 16.2.3 Project {c_hl}
Figure 16.2.3.1: RichText display for each HotSpot in a text label
As you can see, the source code for the project is very straightforward:
' Gambas class file Private mText As String[] Public Sub Form_Open() FMain.Center FMain.Resizable = False mText = New String[] mText = Split(File.Load("Text/architecture.txt"), "|") lblProject.Tag = mText[0] lblCompiler.Tag = mText[1] lblArchiver.Tag = mText[2] lblCompiledFiles.Tag = mText[3] lblExecutableFile.Tag = mText[4] lblMMAP.Tag = mText[5] lblClassLoader.Tag = mText[6] lblExecutionUnit.Tag = mText[7] lblSubRoutines.Tag = mText[8] lblComponentInterface.Tag = mText[9] lblComponentLoader.Tag = mText[10] lblInterpreter.Tag = mText[11] lblComponents.Tag = mText[12] lblNativeClasses.Tag = mText[13] End ' Form_Open() Public Sub HotSpots_MouseDown() TextLabel1.Text = Last.Tag End
The procedure HotSpots_MouseDown() replaces, in conjunction with the special object Last - which returns a reference to the object that last triggered an event - here at least 14 individual procedures!


