Allow label to change size upon wordwrap or newline.

Post Reply
Jaren
Posts: 21
Joined: Sun Nov 17, 2013 1:55 pm

Allow label to change size upon wordwrap or newline.

Post by Jaren » Mon Feb 11, 2019 8:03 pm

Is there a way to tell a label to change it's size dynamically depending on how many lines of info it is displaying?

For example say I have the line:
"A taco appears before you."

It takes up about 25 pixels of height so right now my label is just high enough and just wide enough to display that specific text.

But if the text changes to:
"A taco appears before you and a llama dances the macarena."

Now the label is too small to display all the text but there is more information hiding that is not displayed. My question is this, Is there a way to have the label size change to show all the text and sort of 'vacuum wrap' itself vertically to meet the demands of the more space that is needed upon echoing to the label?

As always thank you for any tips or help you can provide.

Jaren
Posts: 21
Joined: Sun Nov 17, 2013 1:55 pm

Re: Allow label to change size upon wordwrap or newline.

Post by Jaren » Tue Feb 12, 2019 4:58 am

It's kinda wonky but I figured out a way to do this. I switched to a miniconsole but this should also work with a label. Basically it grabs the string I want to plop into a label or miniconsole etc, calculates the font size of each character, finds how many characters in the string and if the size of the string exceeds the width of the window then it adds another lines worth of pixels to the window.

Code: Select all

function lookwindow2()
    local msg = gmcp.cg_gmcp.occupants
    msg = string.len(msg)
    msg = msg + 11
    local width,height = calcFontSize(10)
    local totalwidth = msg * width
    local lines = 19
    if totalwidth > 1150 then
        lines = math.ceil(totalwidth / 1150)
        lines = lines * 19
    end
    setBorderBottom(lines)
    Occupants = Geyser.MiniConsole:new({
        name="Occupants",
        x=0, y=-(lines),
        autoWrap = true,
        color = "black",
        scrollBar = false,
        fontSize = 10,
        width="1150px", height=lines,
    })
    cecho("Occupants", "<medium_aquamarine>Also here: "..gmcp.cg_gmcp.occupants)
end

User avatar
Vadi
Posts: 4643
Joined: Sat Mar 14, 2009 3:13 pm

Re: Allow label to change size upon wordwrap or newline.

Post by Vadi » Tue Feb 12, 2019 6:45 am

I think you can just call :resize (width, height), might be a bit better.

Jaren
Posts: 21
Joined: Sun Nov 17, 2013 1:55 pm

Re: Allow label to change size upon wordwrap or newline.

Post by Jaren » Tue Feb 12, 2019 3:59 pm

Ok, I stopped recreating the container each time and just used these:

Code: Select all

Occupants:move(0, -(lines))
Occupants:resize(windowwidth, lines)
For some reason these did not work, which was why I was doing it the other way.

Code: Select all

moveWindow("Occupants", 0, -(lines))
resizeWindow("Occupants", 1150, lines)

User avatar
Vadi
Posts: 4643
Joined: Sat Mar 14, 2009 3:13 pm

Re: Allow label to change size upon wordwrap or newline.

Post by Vadi » Tue Feb 12, 2019 5:03 pm

Can you make a small test case of the move/resizing not working and post it up on https://github.com/Mudlet/Mudlet/issues/new?

Jaren
Posts: 21
Joined: Sun Nov 17, 2013 1:55 pm

Re: Allow label to change size upon wordwrap or newline.

Post by Jaren » Tue Feb 12, 2019 6:36 pm

Done. Included as much info as I can.
https://github.com/Mudlet/Mudlet/issues/2356

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest