Browse Source

integrated smartfs improvements/fixes

master
entuland 4 years ago
parent
commit
de73940b2f
  1. 22
      lib/smartfs.lua

22
lib/smartfs.lua

@ -1046,6 +1046,12 @@ smartfs.element("field", {
self:getCloseOnEnterString()
end
end,
setLabel = function(self,text)
self.data.label = text
end,
getLabel = function(self)
return self.data.label
end,
setText = function(self,text)
self:setValue(text)
end,
@ -1169,6 +1175,10 @@ smartfs.element("list", {
if not self.data.items then
self.data.items = {}
end
local escaped = {}
for i, v in ipairs(self.data.items) do
escaped[i] = minetest.formspec_escape(v)
end
return "textlist["..
self.data.pos.x..","..self.data.pos.y..
";"..
@ -1176,7 +1186,7 @@ smartfs.element("list", {
";"..
self:getAbsName()..
";"..
table.concat(self.data.items, ",")..
table.concat(escaped, ",")..
";"..
tostring(self.data.selected or "")..
";"..
@ -1205,7 +1215,7 @@ smartfs.element("list", {
self._doubleClick = func
end,
addItem = function(self, item)
table.insert(self.data.items, minetest.formspec_escape(item))
table.insert(self.data.items, item)
-- return the index of item. It is the last one
return #self.data.items
end,
@ -1291,6 +1301,14 @@ smartfs.element("dropdown", {
self.data.selected = idx
self.data.value = self:getItem(idx) or ""
end,
setSelectedItem = function(self,itm)
for idx, item in ipairs(self.data.items) do
if item == itm then
self.data.selected = idx
self.data.value = item
end
end
end,
getSelected = function(self)
self.data.selected = 1
if #self.data.items > 1 then

Loading…
Cancel
Save