LabelLib — Label Control Library
Complete functionality for creating and managing text label controls in Plan9Basic. Labels display static or dynamic text with full font styling, alignment, word wrap, rotation, and mouse event support. 89 functions.
| Category | Count | Description |
|---|---|---|
| Error Handling | 4 | label_error, label_errormsg$, label_strerror$, label_clearerror |
| Creation & Destruction | 5 | label# (4 overloads), label_free |
| Text Content | 2 | label_text$ (get), label_text# (set) |
| Font Properties | 14 | fontfamily, fontsize, fontcolor, bold, italic, underline, strikeout (get/set) |
| Text Alignment | 4 | textalign, vertalign (get/set) |
| Word Wrap & Auto Size | 4 | wordwrap, autosize (get/set) |
| Position & Size | 14 | x, y, width, height (get/set), bounds#, move#, size# |
| Alignment & Margins | 12 | align (get/set), margin#, margins#, marginleft/top/right/bottom (get/set) |
| Visibility & Behavior | 8 | visible, enabled, opacity, hittest (get/set) |
| Tag & Rotation | 4 | tag, rotation (get/set) |
| Parent & Z-Order | 4 | parent# (get/set), bringtofront#, sendtoback# |
| Events | 18 | 8 event types × set/get + clearcallbacks# |
Cross-Platform Support
| Platform | Status | Notes |
|---|---|---|
| Windows | ✅ Full Support | Win32/Win64 |
| Linux | ✅ Full Support | GTK-based |
| Android | ✅ Full Support | Mobile-optimized |
Error Handling
| Function | Signature | Description |
|---|---|---|
label_error() | label_error@ | Last error code (0 = no error) |
label_errormsg$() | label_errormsg$@ | Last error message as string |
label_strerror$(code) | label_strerror$@n | Description for a given error code |
label_clearerror() | label_clearerror@ | Clear the error state |
let lbl# = label#(frm#, "Hello") if label_error() <> 0 then println "Error: " + label_errormsg$() endif
Numeric Values Reference
Plan9Basic does not have built-in constants. You can define your own named values for readability:
' Text alignment let ALIGN_CENTER = 0 let ALIGN_LEADING = 1 let ALIGN_TRAILING = 2 ' Control alignment let CTRL_NONE = 0 let CTRL_TOP = 1 let CTRL_CLIENT = 9
Text Horizontal Alignment label_textalign#
| Value | Description |
|---|---|
| 0 | Center |
| 1 | Leading (Left for LTR languages) |
| 2 | Trailing (Right for LTR languages) |
Text Vertical Alignment label_vertalign#
| Value | Description |
|---|---|
| 0 | Center |
| 1 | Leading (Top) |
| 2 | Trailing (Bottom) |
Control Alignment label_align#
| Value | Description |
|---|---|
| 0 | None (absolute positioning) |
| 1 | Top |
| 2 | Left |
| 3 | Right |
| 4 | Bottom |
| 9 | Client (fill parent) |
| 11 | Center |
Creation & Destruction
| Function | Signature | Description |
|---|---|---|
label#(parent#) | label#@# | Create an empty label |
label#(parent#, text$) | label#@#$ | Create with text |
label#(parent#, text$, x, y) | label#@#$nn | Create with text and position |
label#(parent#, text$, x, y, w, h) | label#@#$nnnn | Create with text, position, and size |
label_free(lbl#) | label_free@# | Destroy label and release resources |
' Empty label let lbl# = label#(frm#) ' With text let lbl# = label#(frm#, "Hello, World!") ' With text and position let lbl# = label#(frm#, "Status:", 20, 50) ' Full creation let lbl# = label#(frm#, "Description", 20, 80, 300, 60) ' Cleanup label_free(lbl#)
ⓘ Note: Text is always the second parameter when provided. The
parent# must be a valid form or container control (panel, layout).Text Content
| Function | Signature | Description |
|---|---|---|
label_text$(lbl#) | label_text$@# | Get the label text |
label_text#(lbl#, text$) | label_text#@#$ | Set the label text |
label_text#(lbl#, "Processing...") println "Label says: " + label_text$(lbl#)
Font Properties
| Function | Signature | Description |
|---|---|---|
label_fontfamily$(lbl#) | label_fontfamily$@# | Get font family name |
label_fontfamily#(lbl#, family$) | label_fontfamily#@#$ | Set font family |
label_fontsize(lbl#) | label_fontsize@# | Get font size |
label_fontsize#(lbl#, size) | label_fontsize#@#n | Set font size |
label_fontcolor$(lbl#) | label_fontcolor$@# | Get font color |
label_fontcolor#(lbl#, color$) | label_fontcolor#@#$ | Set font color |
label_bold(lbl#) | label_bold@# | Get bold state (0/1) |
label_bold#(lbl#, n) | label_bold#@#n | Set bold (0/1) |
label_italic(lbl#) | label_italic@# | Get italic state (0/1) |
label_italic#(lbl#, n) | label_italic#@#n | Set italic (0/1) |
label_underline(lbl#) | label_underline@# | Get underline state (0/1) |
label_underline#(lbl#, n) | label_underline#@#n | Set underline (0/1) |
label_strikeout(lbl#) | label_strikeout@# | Get strikeout state (0/1) |
label_strikeout#(lbl#, n) | label_strikeout#@#n | Set strikeout (0/1) |
label_fontfamily#(lbl#, "Arial") label_fontsize#(lbl#, 18) label_fontcolor#(lbl#, "#0066CC") label_bold#(lbl#, 1) label_italic#(lbl#, 1) println "Font: " + label_fontfamily$(lbl#) + " " + str$(label_fontsize(lbl#)) + "pt"
Text Alignment
| Function | Signature | Description |
|---|---|---|
label_textalign(lbl#) | label_textalign@# | Get horizontal alignment (0=center, 1=left, 2=right) |
label_textalign#(lbl#, n) | label_textalign#@#n | Set horizontal alignment |
label_vertalign(lbl#) | label_vertalign@# | Get vertical alignment (0=center, 1=top, 2=bottom) |
label_vertalign#(lbl#, n) | label_vertalign#@#n | Set vertical alignment |
' Center text both horizontally and vertically label_textalign#(lbl#, 0) ' Horizontal center label_vertalign#(lbl#, 0) ' Vertical center ' Top-left alignment label_textalign#(lbl#, 1) ' Leading (left) label_vertalign#(lbl#, 1) ' Leading (top)
Word Wrap & Auto Size
| Function | Signature | Description |
|---|---|---|
label_wordwrap(lbl#) | label_wordwrap@# | Get word wrap state (0/1) |
label_wordwrap#(lbl#, n) | label_wordwrap#@#n | Enable/disable word wrap |
label_autosize(lbl#) | label_autosize@# | Get auto-size state (0/1) |
label_autosize#(lbl#, n) | label_autosize#@#n | Enable/disable auto-sizing |
' Auto-size: label adjusts to fit text label_autosize#(lbl#, 1) label_text#(lbl#, "Short") println "Width: " + str$(label_width(lbl#)) ' Shrinks to fit ' Word wrap: text wraps within a fixed width label_autosize#(lbl#, 0) label_size#(lbl#, 200, 80) label_wordwrap#(lbl#, 1) label_text#(lbl#, "This is a longer piece of text that will wrap within the label boundaries.")
⚠ Warning: Word wrap requires
label_autosize#(lbl#, 0) and a fixed width. If auto-size is enabled, the label grows horizontally instead of wrapping.Position & Size
| Function | Signature | Description |
|---|---|---|
label_x(lbl#) | label_x@# | Get X position |
label_x#(lbl#, x) | label_x#@#n | Set X position |
label_y(lbl#) | label_y@# | Get Y position |
label_y#(lbl#, y) | label_y#@#n | Set Y position |
label_width(lbl#) | label_width@# | Get width |
label_width#(lbl#, w) | label_width#@#n | Set width |
label_height(lbl#) | label_height@# | Get height |
label_height#(lbl#, h) | label_height#@#n | Set height |
label_bounds#(lbl#, x, y, w, h) | label_bounds#@#nnnn | Set position and size in one call |
label_move#(lbl#, x, y) | label_move#@#nn | Set position only |
label_size#(lbl#, w, h) | label_size#@#nn | Set size only |
label_bounds#(lbl#, 20, 50, 300, 60) ' Or separately label_move#(lbl#, 20, 50) label_size#(lbl#, 300, 60) println "At: " + str$(label_x(lbl#)) + ", " + str$(label_y(lbl#))
Alignment & Margins
When label_align# is set to a value other than 0, the label is automatically positioned by its parent container. Margins control spacing when alignment is active.
| Function | Signature | Description |
|---|---|---|
label_align(lbl#) | label_align@# | Get control alignment mode |
label_align#(lbl#, n) | label_align#@#n | Set control alignment (0=none, 1=top, 2=left, 3=right, 4=bottom, 9=client, 11=center) |
label_margin#(lbl#, n) | label_margin#@#n | Set uniform margin on all four sides |
label_margins#(lbl#, l, t, r, b) | label_margins#@#nnnn | Set individual margins (left, top, right, bottom) |
label_marginleft(lbl#) | label_marginleft@# | Get left margin |
label_marginleft#(lbl#, n) | label_marginleft#@#n | Set left margin |
label_margintop(lbl#) | label_margintop@# | Get top margin |
label_margintop#(lbl#, n) | label_margintop#@#n | Set top margin |
label_marginright(lbl#) | label_marginright@# | Get right margin |
label_marginright#(lbl#, n) | label_marginright#@#n | Set right margin |
label_marginbottom(lbl#) | label_marginbottom@# | Get bottom margin |
label_marginbottom#(lbl#, n) | label_marginbottom#@#n | Set bottom margin |
' Dock a label to the top of a form as a header label_align#(lbl#, 1) ' Align top label_height#(lbl#, 40) label_margin#(lbl#, 5) ' 5px spacing all sides
Visibility & Behavior
| Function | Signature | Description |
|---|---|---|
label_visible(lbl#) | label_visible@# | Get visibility (0/1) |
label_visible#(lbl#, n) | label_visible#@#n | Set visibility (0=hidden, 1=visible) |
label_enabled(lbl#) | label_enabled@# | Get enabled state (0/1) |
label_enabled#(lbl#, n) | label_enabled#@#n | Set enabled state (0=disabled/grayed, 1=enabled) |
label_opacity(lbl#) | label_opacity@# | Get opacity (0.0–1.0) |
label_opacity#(lbl#, value) | label_opacity#@#n | Set opacity (0.0=transparent, 1.0=opaque) |
label_hittest(lbl#) | label_hittest@# | Get hit-test state (0/1) |
label_hittest#(lbl#, n) | label_hittest#@#n | Enable/disable mouse hit testing (0=click-through, 1=clickable) |
⚠ Warning: Labels have
hittest = 0 by default, meaning they do not receive mouse events. You must call label_hittest#(lbl#, 1) before assigning click, double-click, or mouse callbacks.Tag & Rotation
| Function | Signature | Description |
|---|---|---|
label_tag(lbl#) | label_tag@# | Get user-defined integer tag |
label_tag#(lbl#, n) | label_tag#@#n | Set user-defined integer tag |
label_rotation(lbl#) | label_rotation@# | Get rotation angle in degrees |
label_rotation#(lbl#, angle) | label_rotation#@#n | Set rotation angle in degrees (0–360) |
' Rotated label for a vertical sidebar effect label_rotation#(lbl#, 270) ' 270 degrees = vertical, reading bottom-to-top ' Use tags to identify labels in shared callbacks label_tag#(lblName#, 1) label_tag#(lblEmail#, 2)
Parent & Z-Order
| Function | Signature | Description |
|---|---|---|
label_parent#(lbl#) | label_parent#@# | Get parent control pointer |
label_parent#(lbl#, parent#) | label_parent#@## | Move label to a different parent |
label_bringtofront#(lbl#) | label_bringtofront#@# | Bring to front of Z-order |
label_sendtoback#(lbl#) | label_sendtoback#@# | Send to back of Z-order |
' Move a label from the form into a panel label_parent#(lbl#, panel#) ' Ensure label is drawn on top label_bringtofront#(lbl#)
Events
Each event has a setter (label_onXXX#(lbl#, func$)) and a getter (label_onXXX$(lbl#)) to assign or read the callback name. Use label_clearcallbacks#(lbl#) to disconnect all callbacks at once.
⚠ Warning: Labels have
hittest = 0 by default. You must call label_hittest#(lbl#, 1) before any mouse event will fire.| Event Setter | Getter | Callback Signature |
|---|---|---|
label_onclick#(lbl#, func$) | label_onclick$(lbl#) | function name(sender#) |
label_ondblclick#(lbl#, func$) | label_ondblclick$(lbl#) | function name(sender#) |
label_onmousedown#(lbl#, func$) | label_onmousedown$(lbl#) | function name(sender#, button, x, y, shift$) |
label_onmouseup#(lbl#, func$) | label_onmouseup$(lbl#) | function name(sender#, button, x, y, shift$) |
label_onmousemove#(lbl#, func$) | label_onmousemove$(lbl#) | function name(sender#, x, y, shift$) |
label_onmouseenter#(lbl#, func$) | label_onmouseenter$(lbl#) | function name(sender#) |
label_onmouseleave#(lbl#, func$) | label_onmouseleave$(lbl#) | function name(sender#) |
label_onresize#(lbl#, func$) | label_onresize$(lbl#) | function name(sender#) |
label_clearcallbacks#(lbl#) | — | Disconnect all event callbacks |
' Make a label clickable (hyperlink style) label_hittest#(lbl#, 1) ' Required! label_onclick#(lbl#, "OnLabelClick") function OnLabelClick(sender#) println "Label clicked: " + label_text$(sender#) endfunction
' Mouse hover effect on a label label_hittest#(lbl#, 1) label_onmouseenter#(lbl#, "OnHover") label_onmouseleave#(lbl#, "OnLeave") function OnHover(sender#) label_fontcolor#(sender#, "#0066CC") label_underline#(sender#, 1) endfunction function OnLeave(sender#) label_fontcolor#(sender#, "#000000") label_underline#(sender#, 0) endfunction
Complete Examples
Styled Labels
let frm# = form#("Styled Labels", 400, 300) form_position#(frm#, 4) ' Title label let lblTitle# = label#(frm#, "Welcome to Plan9Basic") label_move#(lblTitle#, 50, 30) label_fontsize#(lblTitle#, 24) label_fontcolor#(lblTitle#, "#0066CC") label_bold#(lblTitle#, 1) ' Subtitle let lblSub# = label#(frm#, "A modern BASIC interpreter") label_move#(lblSub#, 50, 70) label_fontsize#(lblSub#, 14) label_italic#(lblSub#, 1) label_fontcolor#(lblSub#, "gray") ' Description with word wrap let lblDesc# = label#(frm#, "Create cross-platform applications easily.") label_bounds#(lblDesc#, 50, 120, 300, 100) label_wordwrap#(lblDesc#, 1) label_autosize#(lblDesc#, 0) form_show(frm#) while form_visible(frm#) = 1 processmessages() end while
Clickable Hyperlink Label
function OnLabelClick(sender#) label_text#(sender#, "Clicked!") label_fontcolor#(sender#, "red") endfunction let frm# = form#("Clickable Label", 400, 200) form_position#(frm#, 4) let lbl# = label#(frm#, "Click me!") label_move#(lbl#, 150, 80) label_fontsize#(lbl#, 18) label_fontcolor#(lbl#, "blue") label_underline#(lbl#, 1) label_hittest#(lbl#, 1) label_onclick#(lbl#, "OnLabelClick") form_show(frm#) while form_visible(frm#) = 1 processmessages() end while
Dynamic Status Display
function OnStart(sender#) label_text#(lblStatus#, "Running...") label_fontcolor#(lblStatus#, "green") endfunction function OnStop(sender#) label_text#(lblStatus#, "Stopped") label_fontcolor#(lblStatus#, "red") endfunction let frm# = form#("Status Demo", 400, 200) form_position#(frm#, 4) let lblStatus# = label#(frm#, "Ready") label_move#(lblStatus#, 150, 30) label_fontsize#(lblStatus#, 16) let btnStart# = button#(frm#, "Start", 100, 100, 80, 30) let btnStop# = button#(frm#, "Stop", 220, 100, 80, 30) button_onclick#(btnStart#, "OnStart") button_onclick#(btnStop#, "OnStop") form_show(frm#) while form_visible(frm#) = 1 processmessages() end while
Text Alignment Showcase
let frm# = form#("Alignment Demo", 500, 300) form_position#(frm#, 4) ' Left aligned let lbl1# = label#(frm#, "Left aligned text") label_bounds#(lbl1#, 50, 50, 400, 30) label_textalign#(lbl1#, 1) ' Center aligned let lbl2# = label#(frm#, "Center aligned text") label_bounds#(lbl2#, 50, 100, 400, 30) label_textalign#(lbl2#, 0) ' Right aligned let lbl3# = label#(frm#, "Right aligned text") label_bounds#(lbl3#, 50, 150, 400, 30) label_textalign#(lbl3#, 2) form_show(frm#) while form_visible(frm#) = 1 processmessages() end while
Rotated Labels
let frm# = form#("Rotation Demo", 400, 400) form_position#(frm#, 4) let lbl0# = label#(frm#, "0 degrees", 180, 20) label_fontsize#(lbl0#, 14) label_rotation#(lbl0#, 0) let lbl45# = label#(frm#, "45 degrees", 280, 80) label_fontsize#(lbl45#, 14) label_rotation#(lbl45#, 45) let lbl90# = label#(frm#, "90 degrees", 350, 180) label_fontsize#(lbl90#, 14) label_rotation#(lbl90#, 90) let lbl270# = label#(frm#, "270 degrees", 20, 180) label_fontsize#(lbl270#, 14) label_rotation#(lbl270#, 270) form_show(frm#) while form_visible(frm#) = 1 processmessages() end while
Best Practices
| Practice | Why |
|---|---|
Call label_hittest#(lbl#, 1) before assigning mouse events | Labels ignore mouse events by default |
Use label_autosize#(lbl#, 1) for dynamic text | Label automatically resizes to fit content |
| Disable auto-size for fixed layouts with word wrap | Set size manually with label_bounds#, then enable label_wordwrap# |
Use label_tag# to identify labels in shared callbacks | Avoids global variables for distinguishing multiple labels |
| Set font properties after creation | Fonts are applied immediately and affect auto-size calculations |
Use label_textalign# together with fixed width | Text alignment only matters when the label is wider than the text |
Quick Reference
| Function | Signature | Description |
|---|---|---|
label_error / errormsg$ / strerror$ / clearerror | various | Error handling (4) |
label#(parent#[, text$][, x, y][, w, h]) | various | Create label (4 overloads) |
label_free(lbl#) | label_free@# | Destroy label |
label_text$ / text# | label_text$@#, label_text#@#$ | Text get/set |
label_fontfamily / fontsize / fontcolor / bold / italic / underline / strikeout | various | Font properties (14) |
label_textalign / vertalign | various | Text alignment (4) |
label_wordwrap / autosize | various | Wrap & sizing (4) |
label_x/y/width/height (get/set) | various | Position & size (8) |
label_bounds# / move# / size# | various | Batch position/size (3) |
label_align / margin# / margins# / margin[left/top/right/bottom] | various | Alignment & margins (12) |
label_visible / enabled / opacity / hittest | various | Visibility & behavior (8) |
label_tag / rotation | various | Tag & rotation (4) |
label_parent# / bringtofront# / sendtoback# | various | Parent & Z-order (4) |
label_onclick/ondblclick/onmousedown/onmouseup/onmousemove/onmouseenter/onmouseleave/onresize | various | Events set+get (17) |
label_clearcallbacks# | label_clearcallbacks#@# | Disconnect all events |
89 functions. Part of the Plan9Basic GUI library system.