From db6333b49e5a1f297f517614d658c5a60f4b6310 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 13 Oct 2016 01:50:43 +0200 Subject: Unique text widget IDs --- API.md | 5 +++++ init.lua | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index 3003a5c..858d4e6 100644 --- a/API.md +++ b/API.md @@ -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. diff --git a/init.lua b/init.lua index 444732d..145b144 100644 --- a/init.lua +++ b/init.lua @@ -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 -- cgit v1.2.3