Files
Basalt/docs/objects/Textfield.md
Robert Jelic bb1b1beb79 Basalt 1.7 Update
- New Objects (Flexbox, Graph, Treeview)
- Pluginsystem to add/remove functionality
- Reworked the entire Object system, instead of one big Object Class we have multiple classes: Object, VisualObject, ChangeableObject
- Instead of one big Frame Class we have multiple Frame Classes: BaseFrame, Frame, MovableFrame, ScrollableFrame, MonitorFrame, Flexbox
- Removed the Animation Object, and added a animation plugin instead
- Removed the Graphic Object and merged it's functionality with the image object
- Updated currently existing objects
2023-04-30 17:05:34 +02:00

2.1 KiB

Textfields are objects that allow users to write text in multiple lines, similar to the default edit script.

In addition to the Object and VisualObject methods, Textfield objects have the following methods:

getLines Returns all lines of text
getLine Returns a specific line of text
editLine Edits a specific line of text
addLine Adds a new line of text
removeLine Removes a specific line of text
getTextCursor Returns the current text cursor position
addKeywords Adds syntax highlighting keywords
addRule Adds a custom syntax highlighting rule
editRule Edits an existing syntax highlighting rule
removeRule Removes an existing syntax highlighting rule
getOffset Returns the current offset inside the Textfield
setOffset Changes the offset inside the Textfield
clear Clears the Textfield content
setSelection Sets the selection color (text color and background color)
getSelection Returns the current selection color

In version 1.7, Textfields now allow the user to select text with the mouse. The setSelection method is used to choose the text color and background color for selected text.

Example

local main = basalt.createFrame()
local aTextfield = main:addTextfield()

-- Add some lines of text to the Textfield
aTextfield:addLine("This is the first line.")
aTextfield:addLine("This is the second line.")
aTextfield:addLine("This is the third line.")

-- Edit the second line
aTextfield:editLine(2, "This is the modified second line.")

-- Remove the third line
aTextfield:removeLine(3)

-- Add a keyword for syntax highlighting
aTextfield:addKeywords(colors.red, {"first", "second", "third"})