Add ability to hide elements using get/setVisible

This commit is contained in:
bell07 2017-03-04 21:27:15 +01:00 committed by rubenwardy
parent 4210c3e61b
commit 9acbd42aeb
3 changed files with 26 additions and 2 deletions

View File

@ -60,6 +60,8 @@
* element:getSize() - get the size
* element:setBackground(image) - Set the background of element. Please note a size needs to be defined on element
* element:getBackground() - get the current background
* element:setVisible(bool) - set the visibility status (set hidden=>false, unhide=>true or nil)
* element:getVisible() - get the visibility status
###Button
* element:setText( text ) - set the caption of the button

View File

@ -10,7 +10,15 @@ local s = smartfs.create("smartfs:form", function(state)
usr:setBackground("halo.png")
state:field(7.25,1.25,3,1,"txt","Textbox")
state:image(0,0,2,2,"img","default_stone.png")
state:toggle(0,2,3,1,"tg",{"plenty..","of..","custom..","elements"})
local toggle = state:toggle(0,2,3,1,"tg",{"plenty..","of..","custom..","elements"})
toggle:onToggle(function(self, state, player)
if state:get("ta"):getVisible() == false then
state:get("ta"):setVisible()
else
state:get("ta"):setVisible(false)
end
end)
state:checkbox(2,1,"c","Easy code",true)
local area = state:textarea(1,3.5,9,4,"ta","Code:")
local res = [[

View File

@ -304,7 +304,9 @@ function smartfs._makeState_(form, newplayer, params, is_inv, nodepos)
res = "size["..self._size.w..","..self._size.h.."]"
end
for key,val in pairs(self._ele) do
res = res .. val:getBackgroundString() .. val:build()
if val:getVisible() then
res = res .. val:getBackgroundString() .. val:build()
end
end
return res
end,
@ -432,6 +434,16 @@ function smartfs._makeState_(form, newplayer, params, is_inv, nodepos)
getSize = function(self)
return self.data.size
end,
setVisible = function(self, visible)
if visible == nil then
self.data.visible = true
else
self.data.visible = visible
end
end,
getVisible = function(self)
return self.data.visible
end,
setBackground = function(self, image)
self.data.background = image
end,
@ -455,6 +467,8 @@ function smartfs._makeState_(form, newplayer, params, is_inv, nodepos)
end,
}
ele.data.visible = true --visible by default
for key, val in pairs(type) do
ele[key] = val
end