flamendless / Slab

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

Slab.Textf alignment not working #76

Closed togfoxy closed 3 years ago

togfoxy commented 3 years ago

Slab.Textf("some text",{Align = 'center'})

will center correctly if SOME TEXT expands across more than one line (i.e. wraps). Using 'Align' on a short string should center that text on that one line based on the window width instead of left aligning against the left margin.

togfoxy commented 3 years ago

Perhaps X and Y is being passed incorrectly?

local function DrawTextFormatted(Text)
    local StatHandle = Stats.Begin('DrawTextFormatted', StatsCategory)

    print(Text.Text, Text.X, Text.Y, Text.W, Text.Align)

    love.graphics.setFont(Text.Font)
    love.graphics.setColor(Text.Color)
    love.graphics.printf(Text.Text, Text.X, Text.Y, Text.W, Text.Align)

    Stats.End(StatHandle)
end
togfoxy commented 3 years ago

Did a workaround with

Slab.BeginLayout('mylayout', {AlignX = 'center'})

Is this intended behaviour?

coding-jackalope commented 3 years ago

Hi @togfoxy, yes Slab.BeginLayout is the intended behavior for aligning controls to a specific layout. Be sure to call Slab.EndLayout when you are finished with controls that need to be affected by this layout.

If you feel the layout system is confusing or limited, feel free to let me know. This feature is really early and will be updated frequently as more developers use this system. I am also currently working on a 'Panel' control which should give developers another way of organizing their controls.

togfoxy commented 3 years ago

I guess the original comment was that I can't align text with textf unless the provided text is long enough to wrap. I'll do some more testing.

Regarding layout, it was very intuitive and worked first time. :)