[Library] Popo

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

[Library] Popo

Post by adnzzzzZ » Mon Jan 19, 2015 6:17 am

Hi. I've created a library for getting programmable text happening with LÖVE. The idea is that you can program the text in a character based fashion so that you can hopefully achieve a huge number of effects just like you can when you're programming anything else.

Popo

Muris
Party member
Posts: 131
Joined: Fri May 23, 2014 9:18 am

Re: [Library] Popo

Post by Muris » Mon Jan 19, 2015 7:20 am

Looks really nice. I was just thinking the other day how I would do a textbox with varying colors for "important names" inside a textbox and this looks like it could solve that problem.

Would it be possible to use different fonts/fontsizes in one string? Like using bolded text on some parts of the text. Not that I am in need for such thing, but just out of curiosity.

I didn't try using it, but did a quick glimpse on the code, I guess you cannot use text alignment with it by default, but that would be just a matter of changing the print into printf.

Edit: Actually I guess that doesn't work. I guess the code is printing one letter per time with the print.

User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: [Library] Popo

Post by adnzzzzZ » Mon Jan 19, 2015 7:28 am

Muris wrote: Would it be possible to use different fonts/fontsizes in one string? Like using bolded text on some parts of the text. Not that I am in need for such thing, but just out of curiosity.
I don't think this is possible right now. I could implement it in the future though. One way you can get different sizes on certain characters though is by playing with the sx, sy parameters which control the character's scale. As for bolding I'm not sure if there's a good way that will look as good as if you were doing it with a bold font, but drawing the character multiple times with small offsets could work. To do that just check how I draw each character internally and copy that.

davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: [Library] Popo

Post by davisdude » Mon Jan 19, 2015 4:28 pm

Nice library! Looks useful.
For what Muris mentioned you could try implementing something found in Robin's richtext.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim

User avatar
SiENcE
Party member
Posts: 772
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: [Library] Popo

Post by SiENcE » Mon Jan 19, 2015 4:45 pm

@adnzzzzZ
I already saw it on github today and it's very nice!

It's somewhat similar to richtext as davisdude already mentioned. I would appreciate a more advanced version similar like "richtext". "richtext" had some flaws like you cannot dynamically change what you have defined. Everything is rendered (and only than) when creating an richtext object.

So applying functions to characters or words is still missing.

User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: [Library] Popo

Post by adnzzzzZ » Mon Jan 19, 2015 6:34 pm

davisdude wrote:Nice library! Looks useful.
For what Muris mentioned you could try implementing something found in Robin's richtext.
What I have in mind for what Muris mentioned is to just enable love.graphics.setFont() to be called whenever a special function is defined. Something like this:

Code: Select all

local bold_font = love.graphics.newFont('bold_font.ttf', 36)
text = Text('[BOLD](font) not bold', {
    font = function(dt, c)
        love.graphics.setFont(bold_font)
    end
})
So when this font function is defined it overrides the text's normal font.

Muris
Party member
Posts: 131
Joined: Fri May 23, 2014 9:18 am

Re: [Library] Popo

Post by Muris » Mon Jan 19, 2015 11:30 pm

Sorry that I am quite noob and I am quite unfamiliar with making issues and proposing fixes. Anyways I had a problem with the word wrapping, I noticed there is self.wrap_width in your Popo, and it does indeed wrap the text, but sadly sometimes it does it in a middle of a word. So I managed to do a following fix, it might not be all that good but here goes and especially if there is font changing going on, this will become quite problematic.

Code: Select all

-- define nextWhiteSpace before the loop, at here
    local nextWhiteSpace = 0
    self.characters = {}
    local str = ""
    local line = 0

.....
        -- Move to new line if over wrap_width
        if self.wrap_width and nextWhiteSpace and nextWhiteSpace <= i then
            nextWhiteSpace = stripped_text:find("%s", i )
            local w = self.font:getWidth( str .. stripped_text:sub( i, nextWhiteSpace ) )
            if w > self.wrap_width then 
                line = line + 1
                str = c
            end      
        end
        local w =	self.font:getWidth(c)
        text_w = self.font:getWidth(str)
        


User avatar
Positive07
Party member
Posts: 1005
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: [Library] Popo

Post by Positive07 » Tue Jan 20, 2015 12:11 am

Can this lib handle UTF8 characters? Because if it doesnt, splitting the text into characters is not a good idea

I proposed a method to get the string in the issue tracker, with that and the font you could get the width of the text, with that you could use this function to center align your text:

Code: Select all

local tw = font:getWidth(text)
local w = love.graphics.getWidth()

function n (dt,c)
    c.x = c.x + (w-tw)/2
end
Not sure how you could do that when wrapping, but I guess it is possible (internally at least)
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: [Library] Popo

Post by adnzzzzZ » Tue Jan 20, 2015 12:17 am

Positive07 wrote:Can this lib handle UTF8 characters? Because if it doesnt, splitting the text into characters is not a good idea

I proposed a method to get the string in the issue tracker, with that and the font you could get the width of the text, with that you could use this function to center align your text:

Code: Select all

local tw = font:getWidth(text)
local w = love.graphics.getWidth()

function n (dt,c)
    c.x = c.x + (w-tw)/2
end
Not sure how you could do that when wrapping, but I guess it is possible (internally at least)
If you wanna get the text as it will be printed then you can access it via str_text from a character. So in your example you can do:

Code: Select all

function n(dt, c)
    c.x = c.x + (love.graphics.getWidth() - c.text.font:getWidth(c.str_text))/2
end

User avatar
Positive07
Party member
Posts: 1005
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: [Library] Popo

Post by Positive07 » Tue Jan 20, 2015 12:28 am

adnzzzzZ wrote:

Code: Select all

function n(dt, c)
    c.x = c.x + (love.graphics.getWidth() - c.text.font:getWidth(c.str_text))/2
end
Nice! :awesome:

So I'll ask again just in case you didnt read it: Can this lib handle UTF-8?
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests