Page 1 of 10

a Rich Text library for LÖVE

Posted: Mon Sep 20, 2010 8:56 am
by Robin
Update: For the latest version, go to GitHub.

Yet another idea, which will have to wait for implementation until that friggin laptop arrives.

Anyway, the idea is this: a library that knows how to draw text with different fonts, and how to insert images between them.

The lover would specify what to draw by doing something like:

Code: Select all

rt = rich.new("Hello, {font:big}world! {img:smile}", {big = bigFont, smile = smileyImage})
--or
rt = rich.new{"Hello, {font:big}world! {img:smile}", big = bigFont, smile = smileyImage})
--or
rt = rich.new{"Hello, {big}world! {smile}", big = bigFont, smile = smileyImage}
(I'm not sure yet which is better.)

Then one would do:

Code: Select all

function love.draw()
    rt:draw()
end
rich.new() will probably start by rendering to a Framebuffer, because such text is probably static while quite expensive to generate.

I'm also planning on having it word-wrap and handle NPO2 images gracefully.

What do you think? Useful or useless?

EDIT: closed poll. Popular vote decided RT to be licensed zlib.

Re: Idea: RichText

Posted: Mon Sep 20, 2010 10:19 am
by nevon
Yes please! I've had to do stuff like this manually oh-so-many times, and it's a freaking pain.

Re: Idea: RichText

Posted: Mon Sep 20, 2010 10:56 am
by Robin
Good. You (and other lovers who'd like to use this) could help by listing requirements and such while I wait for my new laptop to arrive. ;)

Re: Idea: RichText

Posted: Mon Sep 20, 2010 2:24 pm
by nevon
Optional parameters for specifying the width and height of the image(s), since you often have to pad for Po2-ness, is the first thing that comes to mind.

Re: Idea: RichText

Posted: Mon Sep 20, 2010 2:44 pm
by Robin
nevon wrote:Optional parameters for specifying the width and height of the image(s), since you often have to pad for Po2-ness, is the first thing that comes to mind.
Ah, yes, I had that in mind as well.

Here's the idea: you can specify an image as, well, an image:

Code: Select all

... keyz = love.graphics.newImage("images/keys/z.png"), ...
or as a table:

Code: Select all

... keyz = {love.graphics.newImage("images/keys/z.png"), width = 36, height = 26}, ... -- where that image is padded in the image editor to 64x32
(or perhaps even with a string:

Code: Select all

... keyz = "images/keys/z.png", ...
)

The big idea is, that if you don't manually specify a width and height, the library will autopad the image itself, remember the original dimensions, and use those for drawing.

Re: Idea: RichText

Posted: Mon Sep 20, 2010 3:06 pm
by VideroBoy
If we can specify dimensions, we should also have Quad support.

Code: Select all

rt = rich.new("Hello, {font:big}world! {img:smile quad:myQuad}", {big = bigFont, smile = smileyImage, myQuad = whateverQuad})
Also, may I propose either HTML or BBCode as the syntax?

Re: Idea: RichText

Posted: Mon Sep 20, 2010 3:18 pm
by Robin
VideroBoy wrote:If we can specify dimensions, we should also have Quad support.

Code: Select all

rt = rich.new("Hello, {font:big}world! {img:smile quad:myQuad}", {big = bigFont, smile = smileyImage, myQuad = whateverQuad})
Good idea. However, I don't think it would be specified in-string, but rather as something like:

Code: Select all

rt = rich.new("Hello, {font:big}world! {img:smile}", {big = bigFont, smile = {smileyImage, quad = whateverQuad}})
This to keep the strings relatively easy to parse.
VideroBoy wrote:Also, may I propose either HTML or BBCode as the syntax?
You may. Syntax is of course subject to change (since I haven't written a damned line for it yet), but I think I might actually prefer the BBCode-inspired "tags", since [] do not require the shift key to type them (as opposed to {} and <>, at least on my keyboard).

And another thing: I think the font: and img: prefixes will be dropped, since their type can be inferred.

Example:

Code: Select all

rt = rich.new("Hello, [big]world! [smile]", {big = bigFont, smile = {smileyImage, quad = whateverQuad}})

Re: Idea: RichText

Posted: Mon Sep 20, 2010 3:30 pm
by nevon
Robin wrote:I think I might actually prefer the BBCode-inspired "tags", since [] do not require the shift key to type them (as opposed to {} and <>, at least on my keyboard).
Instead they require Ctrl + Alt or Alt Gr. Wee! :P (Don't really care either way)

Re: Idea: RichText

Posted: Mon Sep 20, 2010 4:53 pm
by bartbes
I prefer rich.new{} syntax btw.

Re: Idea: RichText

Posted: Mon Sep 20, 2010 5:27 pm
by Robin
Heh, as soon as I saw you replied, I thought "bartbes is going to burn this idea to the ground, showing three different reasons why it is both unneccesary and destined for failure". (Actually I was waiting for this since I wrote the OP.) :crazy:

But anyway, you reminded me of something rather important I forgot: the alternate alternate syntax I had in mind:

Code: Select all

rt = rich.new("Hello, ", bigFont, "world! ", {smileyImage, quad = someQuad})
... only this may not be feasible, since I intend to add optional extra parameters for wrapping and such.