[DONE] Formspec for multi-line text

Post Reply
User avatar
Wuzzy
Member
Posts: 4804
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

[DONE] Formspec for multi-line text

by Wuzzy » Post

It would be useful if Minetest supports a formspec element to show a text box.

The properties I wish are:
  • Read only
  • Looks like a label, only with multiple lines
  • Lua scripter specifies position, size and text of the textbox. Line breaks happen automatically at the end of the textbox, like for textareas.
  • Optional: A scrollbar for the whole textarea if the text is too long (like for textlists).
  • I don’t care about background. That could be added with the box element anyways, so I don’t see a need for it.

All current solutions I can imagine for multi-line text are ugly work arounds:
  • Create text from textlist. Downside: You must manually place line breaks as “,”. This in turn forces you to escape manually, because you can’t throw the text into minetest.formspec_escape, because those commas would be escaped, too!
  • Textarea. Downside: This is an input field which can be edited.
  • Manually placing labels line per line. Way too much work.

EDIT: Textarea supports multi-line text now, with scrollbar.
Last edited by Wuzzy on Sat Apr 09, 2022 13:53, edited 1 time in total.

Sokomine
Member
Posts: 4290
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Formspec for multi-line text

by Sokomine » Post

Such a formspec element would be great! There had been multiple instances where I had to patch together information texts from labels or use textareas, although those don't look particulary fine. It's a pain to get a decently formatted message that's longer than two or three words at the player.
A list of my mods can be found here.

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

Re: Formspec for multi-line text

by 4aiman » Post

Do want too!
For now it can be done with tables:

Code: Select all

table[<X>,<Y>;<W>,<H>;<name>;<cell 1>,<cell 2>,...,<cell n>;<selected idx>]
^ show scrollable table using options defined by the previous tableoptions[]
^ displays cells as defined by the previous tablecolumns[]
^ x and y position the itemlist relative to the top left of the menu
^ w and h are the size of the itemlist
^ name fieldname sent to server on row select or doubleclick
^ cell 1...n cell contents given in row-major order
^ selected idx: index of row to be selected within table (first row = 1)
^ see also minetest.explode_table_event (main menu: engine.explode_table_event)

tableoptions[<opt 1>;<opt 2>;...]
^ sets options for table[]:
^ color=#RRGGBB
^^ default text color (HEX-Color), defaults to #FFFFFF
^ background=#RRGGBB
^^ table background color (HEX-Color), defaults to #000000
^ border=<true/false>
^^ should the table be drawn with a border? (default true)
^ highlight=#RRGGBB
^^ highlight background color (HEX-Color), defaults to #466432
^ highlight_text=#RRGGBB
^^ highlight text color (HEX-Color), defaults to #FFFFFF
^ opendepth=<value>
^^ all subtrees up to depth < value are open (default value = 0)
^^ only useful when there is a column of type "tree"

User avatar
jp
Banned
Posts: 947
Joined: Wed Dec 18, 2013 09:03
GitHub: kilbith
Location: France

Re: Formspec for multi-line text

by jp » Post

EDIT: nvm.

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: Formspec for multi-line text

by Krock » Post

Yes please. A scrollbar is missing on the textarea and the textlist is just unfriendly for that.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Wuzzy
Member
Posts: 4804
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

It's possible?!?!?!

by Wuzzy » Post

OMG!
While I was adding tooltips for the main menu, I figured out that textarea can be made read-only and looking like a multi-line label by leaving the “name” and “default” arguments empty and using the “label” as text.

Example formspec code:

Code: Select all

textlist[1,1;6,3;;Your text goes here;]
Nothing of this is mentioned in lua_api.txt. Grrrrrrrrrrrrrrrrrr!

However, it is not perfect; it still lacks a scroll bar.

User avatar
BrunoMine
Member
Posts: 1082
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine
Location: SP-Brasil
Contact:

Re: Formspec for multi-line text

by BrunoMine » Post

Wow. I must thank you immensely for the discovery. and google.

User avatar
ExeterDad
Member
Posts: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

Re: Formspec for multi-line text

by ExeterDad » Post

@BrunoMine
I have to thank you for bumping this. I remember Wuzzy writing about his discovery, but couldn't find it when I was searching for it. Since I can still make use of it... I'm bookmarking. :)

ntnsndr
Member
Posts: 16
Joined: Mon Jan 18, 2021 04:13
GitHub: ntnsndr

Re: Formspec for multi-line text

by ntnsndr » Post

Bumping this—I still haven't found a great solution for the initial spec. Textlist isn't great for me, because it is less flexible than open text, and it doesn't have horizontal scrollbars for long lines.

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

Re: Formspec for multi-line text

by rubenwardy » Post

ntnsndr wrote:
Wed Dec 29, 2021 19:54
Bumping this—I still haven't found a great solution for the initial spec. Textlist isn't great for me, because it is less flexible than open text, and it doesn't have horizontal scrollbars for long lines.
You can use hypertext or a text field with no name
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

ntnsndr
Member
Posts: 16
Joined: Mon Jan 18, 2021 04:13
GitHub: ntnsndr

Re: Formspec for multi-line text

by ntnsndr » Post

Thanks! Hypertext is working great for me.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests