Formspec clipping and text wrapping

Post Reply
minetestlover
Member
Posts: 25
Joined: Sat Feb 18, 2023 13:31

Formspec clipping and text wrapping

by minetestlover » Post

Sorry if this is a really dumb question, I have my formspec written and looking nice, until I test it with a lower resolution screen, then the text clips over images and goes outside the box I made for it. Trying to look up the problem I found this:
http://minetest.gitlab.io/minetest/formspec/
box[] and image[] elements enable clipping by default
and
The text is displayed directly without automatic line breaking, so label should not be used for big text chunks. Newlines can be used to make labels multiline.
I thought of just dumping my text into an image and just scaling it that way but I was wondering if there was a better way. Basically, is there a way to wrap text in a box and stop it going over my images. Here is my current code and my use case scenario is a help tab.

Code: Select all

sfinv.register_page("help:help", {
    title = S("Help"),
get = function(self, player, context)
    return sfinv.make_formspec(player, context, [[
        "container[0,0]bgcolor[#333333]box[0,0;7.8,5;#111111]
        label[0.6,0;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]
        label[0.6,0.3;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]
        
        image[0.6,1;1,1;rule1.png]
		label[1.8,1;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]
		label[1.8,1.3;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]

        image[6.1,2;2,1;rule2.png]
        label[0.6,2;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]
        label[0.6,2.3;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]

        image[0.1,3;2,1;rule3.png]
        label[1.8,3;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]
        label[1.8,3.3;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]

        image[6.4,4;1,1;rule4.png]
        label[0.6,4;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum.]
         label[0.6,4.3;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non mi auctor elit elementum vestibulum. Maecenas at mollis sapien. Cras tempus fringilla odio eu aliquet.]"
        ]], true)
    end
})

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Formspec clipping and text wrapping

by rubenwardy » Post

A common technique is to use a readonly textarea without styling:

Code: Select all

style_type[textarea;border=false]
textarea[0.6,0;3,2;;Your text here]
This gives you an area of text that wraps and allows scrolling. Can also select and copy, but can't edit or paste
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

minetestlover
Member
Posts: 25
Joined: Sat Feb 18, 2023 13:31

Re: Formspec clipping and text wrapping

by minetestlover » Post

rubenwardy wrote:
Wed Mar 29, 2023 09:44
A common technique is to use a readonly textarea without styling
Thank you. This is effective though looks a little ugly. I was playing with a script idea where I could take the settings DPI to calculate a font size and take the settings screen width to calculate a character limit, then have all the labels stored in tables, a function then splits the text into separate labels and supplies the formspec. However, this would only work on the server. I can see there is:
minetest.get_player_window_information(player_name)
which supplies the window size which could be useful...

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Formspec clipping and text wrapping

by rubenwardy » Post

Yeah, you can use gui_scaling from minetest.get_player_window_information(player_name) in 5.7+. It's equivalent to DPI
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests