Fänfic: A Textbox module for Löve

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Solumin
Prole
Posts: 9
Joined: Wed Mar 16, 2011 4:44 am
Location: NJ

Fänfic: A Textbox module for Löve

Post by Solumin »

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
  1. Code: Select all

    require 'fanfic'
  2. In love.load:

    Code: Select all

    txtbox = fanfic.new(x,y, label, password, font, size)
    (More on this later!)
  3. In love.update:

    Code: Select all

    txtbox:update(dt)
  4. In love.draw:

    Code: Select all

    txtbox:draw()
  5. Finally, in love.keypressed:

    Code: Select all

    text:keypressed(key, unicode)
That's the basic things that are needed to use this module. It's pretty simple!
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
enteredText will only return the text if the textbox has been locked, otherwise it returns nil.

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)
Attachments
fanfic.lua
(3.58 KiB) Downloaded 189 times
FanficExample.love
(2.05 KiB) Downloaded 245 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Fänfic: A Textbox module for Löve

Post by bartbes »

I'd love for the text to be moved to the right slightly, because judging from that example the text can actually touch the border of the textbox.
Another thing I'd like to see, is the usage of font objects, sometimes I already have a ready-made font, or an ImageFont, it would be nice if I could pass that instead.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Fänfic: A Textbox module for Löve

Post by Robin »

Note some GUI toolkits have textboxes. Most notably, I think LoveUI has a very decent implementation.
Help us help you: attach a .love.
Solumin
Prole
Posts: 9
Joined: Wed Mar 16, 2011 4:44 am
Location: NJ

Re: Fänfic: A Textbox module for Löve

Post by Solumin »

bartbes wrote:I'd love for the text to be moved to the right slightly, because judging from that example the text can actually touch the border of the textbox.
Another thing I'd like to see, is the usage of font objects, sometimes I already have a ready-made font, or an ImageFont, it would be nice if I could pass that instead.
Good points, thank you. I'll add those to the TODO list...

Robin wrote:Note some GUI toolkits have textboxes. Most notably, I think LoveUI has a very decent implementation.
...or maybe I won't worry about that TODO list. :P

Fanfic has the advantage of being lightweight and (hopefully) easy to use. Of the two Love GUI kits that I've found, which are LoveUI and Goo, there are some limitations. The former is only compatible with Love v0.6.x. The latter has "known issues, including stubbed functionality" according to its wiki page. (However, I haven't actually used either of these, and I do not know how serious these limitations are.) If someone is making a serious GUI for their game, then those are undoubtedly better choices. This is just nice and lightweight...and also a chance for me to write a little library :)
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Fänfic: A Textbox module for Löve

Post by Jasoco »

Has anyone noticed these things never make any grammatical sense at all? It's just laughable.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests