## TextBox in LOVE2d?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Tiago059
Prole
Posts: 5
Joined: Fri Nov 03, 2017 9:34 pm

### TextBox in LOVE2d?

Good evening

I try to create a simple text box what the user digita using the keyboard in love2d. I dit it, but i wanna insert a way to establish a limit of the caracthers what can be inserted.

Anybody can help me?
The code what i use to create the text box is equal to example in Wikia of love2d, in function love.textinput.
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: TextBox in LOVE2d?

Shameless plug: Here is how to do it with SUIT. The important part is in the validate function, which uses string.gsub() to remove unwanted characters. You can do anything you like here.

Code: Select all

local suit = require 'suit'
local utf8 = require 'utf8'

local function validate(input)
local len = utf8.len(input.text)

-- allow only lowercase a-z (also no spaces, etc)
input.text = input.text:gsub("[^a-z]", "")

-- reset cursor to where it was before charater removal
input.cursor = input.cursor - (len - utf8.len(input.text))
end

local input = {text = ""}
function love.update(dt)
-- place textbox at (100,100) with with 200px and height 30px
suit.Input(input, 100,100,200,30)
validate(input)
end

function love.draw(dt)
suit.draw()
end

function love.textinput(t)
suit.textinput(t)
end

function love.keypressed(key)
suit.keypressed(key)
end

-- if you want IME input, requires a font that can display the characters
function love.textedited(text, start, length)
suit.textedited(text, start, length)
end
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Tiago059
Prole
Posts: 5
Joined: Fri Nov 03, 2017 9:34 pm

### Re: TextBox in LOVE2d?

Wow, i like veryyyyyy your code. I'm not home now, but i'll test your code in my program. Thanks very much and forgive my poor english
Tiago059
Prole
Posts: 5
Joined: Fri Nov 03, 2017 9:34 pm

### Re: TextBox in LOVE2d?

To use suit in my code, i need to install the 'SUIT' how? How i install or a don't need to install? I like very much the SUIT.
derekbaker90
Prole
Posts: 2
Joined: Fri Nov 06, 2020 10:41 pm

### Re: TextBox in LOVE2d?

Tiago059 wrote: Mon Nov 06, 2017 6:25 pm To use suit in my code, i need to install the 'SUIT' how? How i install or a don't need to install? I like very much the SUIT.
suit = require 'vendor/suit'