diff options
author | Wuzzy <almikes@aol.com> | 2016-10-13 01:50:43 +0200 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2016-10-13 01:50:43 +0200 |
commit | db6333b49e5a1f297f517614d658c5a60f4b6310 (patch) | |
tree | d79cb14003b08782f3c97415feb58d027b71d09a | |
parent | 7ba370400955d9e178859b7d8050575e7ef2a0b6 (diff) |
Unique text widget IDs
-rw-r--r-- | API.md | 5 | ||||
-rw-r--r-- | init.lua | 7 |
2 files changed, 10 insertions, 2 deletions
@@ -400,3 +400,8 @@ this function may be deprecated if it isn't needed anymore. #### Return value A string which contains a complete formspec definition building the widget. + +#### Note +When you use this function to build a formspec string, do not use identifiers +beginning with `doc_widget_text` to avoid naming collisions, as this function +makes use of such identifiers internally. @@ -338,6 +338,7 @@ end doc.widgets = {} +local text_id = 1 -- Scrollable freeform text doc.widgets.text = function(data, x, y, width, height) local baselength = 80 @@ -345,9 +346,11 @@ doc.widgets.text = function(data, x, y, width, height) local linelength = math.max(20, math.floor(baselength * (width / widget_basewidth))) -- TODO: Wait for Minetest to provide a native widget for scrollable read-only text with automatic line breaks. -- Currently, all of this had to be hacked into this script manually by using/abusing the table widget - return "tablecolumns[text]".. + local formstring = "tablecolumns[text]".. "tableoptions[background=#00000000;highlight=#00000000;border=false]".. - "table["..tostring(x)..","..tostring(y)..";"..tostring(width)..","..tostring(height)..";text;"..text_for_textlist(data, linelength).."]" + "table["..tostring(x)..","..tostring(y)..";"..tostring(width)..","..tostring(height)..";doc_widget_text"..tostring(text_id)..";"..text_for_textlist(data, linelength).."]" + text_id = text_id + 1 + return formstring end -- Direct formspec |