flamendless / Slab

An immediate mode GUI for the Love2D framework.
MIT License
294 stars 25 forks source link

Can't find a way to force buttons to text wrap if the button text is too long. #81

Closed togfoxy closed 3 years ago

togfoxy commented 3 years ago

Wrapping button text across multiple lines then doing a corresponding auto-size would be handy.

flamendless commented 3 years ago

Hi @togfoxy. There are two ways to do this as far as i can think of right now:

  1. Parse the text and check for numbers of \n occurences.
  2. Just let the user pass a number of multilines

First one would be costly as it will be calculated per frame. Second one will allow for more control and users can even use this to easily make buttons with higher height.

Fixed in 84fc55e4a7bfbd09482caad43c7a91196401156e

here's an example of how to use it:

local str = "dsadsadsadasdasdsadsa\ndasdsadasdsadsadsdsadas" --2 lines

function love.update(dt)
    Slab.Update(dt)
    Slab.BeginWindow("test", {Title = "Test"})
    if Slab.Button(str, {
        VLines = 2
    }) then
    end
    Slab.EndWindow()
end