Skip to content
coding.jackalope edited this page Feb 27, 2021 · 9 revisions
Table of Contents

Overview

Text controls displays text on the current window. Slab currently offers three ways to control the text. Examples of each can be found below.

Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})

Slab.Text("Hello World")

Slab.EndWindow()

Text Selectable

Selectable text will respond to user input. This is useful for building lists within the window.

Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})

for I = 1, 10, 1 do
	if Slab.TextSelectable("Selectable Text " .. I) then
		Selected = I
	end
end

Slab.Separator()

if Selected == 0 then
	Slab.Text("No item selected.")
else
	Slab.Text("Selected Text " .. Selected)
end

Slab.EndWindow()

Text Formatted

Text can also be wrapped and aligned within the contents of the window. It will automatically adjust the wrapping as the window size changes.

Slab.BeginWindow('MyFirstWindow', {Title = "My First Window", AutoSizeWindow = false})

Slab.Textf("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut" ..
	" labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi " .. 
	"ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " ..
	"dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")

Slab.EndWindow()

Text URL

Text can also be configured to point to a URL. The text is rendered in a different color and is clickable by the user to open the link in the default browser.

function love.update(dt)
	Slab.Update(dt)

	Slab.BeginWindow('URL_Example', {Title = "URL Example"})
	Slab.Text("Love Website", {URL = "https://love2d.org"})
	Slab.EndWindow()
end

API

Below is a list of functions associated with the Text API.

Text

Adds text to the active window.

Parameter Type Description
Label String The string to be displayed in the window.
Options Table List of options for how this text is displayed.
Option Type Description
Color Table The color to render the text.
Pad Number How far to pad the text from the left side of the current cursor position.
IsSelectable Boolean Whether this text is selectable using the text's Y position and the window X and width as the hot zone.
IsSelectableTextOnly Boolean Will use the text width instead of the window width to determine the hot zone. Will set IsSelectable to true if that option is missing.
IsSelected Boolean Forces the hover background to be rendered.
SelectOnHover Boolean Returns true if the user is hovering over the hot zone of this text.
HoverColor Table The color to render the background if the IsSelected option is true.
Return Description
Boolean Returns true if SelectOnHover option is set to true. False otherwise.

TextSelectable

This function is a shortcut for SlabText with the IsSelectable option set to true.

Parameter Type Description
Label String The string to be displayed in the window.
Options Table List of options for how this text is displayed. See Slab.Text for all options.
Return Description
Boolean Returns true if user clicks on this text. False otherwise.

Textf

Adds formatted text to the active window. This text will wrap to fit within the contents of either the window or a user specified width.

Parameter Type Description
Label String The text to be rendered.
Options Table List of options for how this text is displayed.
Option Type Description
Color Table The color to render the text.
W Number The width to restrict the text to. If this option is not specified, then the window width is used.
Align String The alignment to use for this text. For more information, refer to the love documentation at https://love2d.org/wiki/AlignMode. Below are the available options:
center: Align text center.
left: Align text left.
right: Align text right.
justify: Align text both left and right.

GetTextSize

Retrieves the width and height of the given text. The result is based on the current font.

Parameter Type Description
Label String The string to retrieve the size for.
Return Description
Number, Number The width and height of the given text.

GetTextWidth

Retrieves the width of the given text. The result is based on the current font.

Parameter Type Description
Label String The string to retrieve the width for.
Return Description
Number The width of the given text.

GetTextHeight

Retrieves the height of the current font.

Return Description
Number The height of the current font.
Clone this wiki locally