summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2016-10-13 01:50:43 +0200
committerWuzzy <almikes@aol.com>2016-10-13 01:50:43 +0200
commitdb6333b49e5a1f297f517614d658c5a60f4b6310 (patch)
treed79cb14003b08782f3c97415feb58d027b71d09a
parent7ba370400955d9e178859b7d8050575e7ef2a0b6 (diff)
Unique text widget IDs
-rw-r--r--API.md5
-rw-r--r--init.lua7
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