Fänfic: A Textbox module for Löve
Posted: Sat May 28, 2011 6:16 pm
Fänfic: Functional and Needed Fully Insertable Characters
Hello, Lövers! The other night, I had a smashing idea: textboxes. Ok, it's exactly breaking new ground, but it's something that I haven't seen in Löve before. This is version 0.2. The textbox is a very simple white rectangle, the text is black. Anything you type should appear in the textbox. Pressing "Enter" locks the textbox, signalling that the data is ready to be collected. Backspace deletes the last character of the text. Attached is both the textbox code (only one file!) and an example.
Set up
The options for fanfic.new:
x,y are the position of the textbox
label is the text that appears near the textbox and identifies the box.
password is a boolean. setting it to 'true' makes the box only display '*' instead of characters.
font is a filename pointing to a font to be loaded.
size is, well, the size of the font to use. This affects the size of the textbox.
**IF size is excluded, font is assumed to be a size. The textbox will use the current loaded font with the custom size.
Furthermore, if font is also excluded, the textbox will use the current font.
If the textbox has been locked, the text can be retried from it using textbox:enteredText(), like so:
enteredText will only return the text if the textbox has been locked, otherwise it returns nil.
Todo:
Hello, Lövers! The other night, I had a smashing idea: textboxes. Ok, it's exactly breaking new ground, but it's something that I haven't seen in Löve before. This is version 0.2. The textbox is a very simple white rectangle, the text is black. Anything you type should appear in the textbox. Pressing "Enter" locks the textbox, signalling that the data is ready to be collected. Backspace deletes the last character of the text. Attached is both the textbox code (only one file!) and an example.
Set up
Code: Select all
require 'fanfic'
- In love.load:
Code: Select all
txtbox = fanfic.new(x,y, label, password, font, size)
- In love.update:
Code: Select all
txtbox:update(dt)
- In love.draw:
Code: Select all
txtbox:draw()
- Finally, in love.keypressed:
Code: Select all
text:keypressed(key, unicode)
The options for fanfic.new:
x,y are the position of the textbox
label is the text that appears near the textbox and identifies the box.
password is a boolean. setting it to 'true' makes the box only display '*' instead of characters.
font is a filename pointing to a font to be loaded.
size is, well, the size of the font to use. This affects the size of the textbox.
**IF size is excluded, font is assumed to be a size. The textbox will use the current loaded font with the custom size.
Furthermore, if font is also excluded, the textbox will use the current font.
If the textbox has been locked, the text can be retried from it using textbox:enteredText(), like so:
Code: Select all
function love.update(dt)
text:update(dt)
data = text:enteredText()
end
Todo:
- Getters and setters for changing features.
- Focus on the textbox (i.e. clicking it or Tabbing to it to type)
- Colors for the textbox and textbox font
- Colors and styles for the labels.
- Specifying width and height of the box (either by # of characters or by pixels)
- Customizing cursor and preventing the cursor from blinking if it is moved (so it doesn't get lost...)
- Arrow keys to move around in the box
- Creating 'forms' to link together multiple textboxes (for more advanced UIs)