make table line function a formspec helper

This commit is contained in:
Dirk Sohler 2021-05-15 17:06:41 +02:00
parent 57a9284bca
commit 917de32cfd
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
2 changed files with 28 additions and 27 deletions

@ -3,6 +3,33 @@ local S = m.translator
local esc = minetest.formspec_escape local esc = minetest.formspec_escape
-- Get a table line
--
-- The index determines the position from top within the current container and
-- is calculated to display the string in the correct position.
--
-- If `name` is a literal `'-'` then a line is printed at the position.
--
-- @param index The numerical index for the line
-- @param name Human-readable name for the variable
-- @param variable The variable like its used in the definition
-- @param value The value to show for that variable
-- @return string The created formspec string
mtimer.get_table_line = function (index, name, variable, value)
local position = ((index-1) * 0.4)
if name == '-' then
return 'box[0,'..position..';+contentWidth,0.02;#ffffff]'
end
return table.concat({
'label[0,'..position..';'..name..']',
'label[4,'..position..';'..variable..']',
'label[7,'..position..';'..value..']'
}, ' ')
end
-- Get a button with icon -- Get a button with icon
-- --
-- This function returns a fully formatted button with icon. -- This function returns a fully formatted button with icon.

@ -1,33 +1,7 @@
local m = mtimer local m = mtimer
local S = m.translator local S = m.translator
local esc = minetest.formspec_escape local esc = minetest.formspec_escape
local line = mtimer.get_table_line
-- Return a table line
--
-- The index determines the position from top within the current container and
-- is calculated to display the string in the correct position.
--
-- If `name` is a literal `'-'` then a line is printed at the position.
--
-- @param index The numerical index for the line
-- @param name Human-readable name for the variable
-- @param variable The variable like its used in the definition
-- @param value The value to show for that variable
-- @return string The created formspec string
local line = function (index, name, variable, value)
local position = ((index-1) * 0.4)
if name == '-' then
return 'box[0,'..position..';+contentWidth,0.02;#ffffff]'
end
return table.concat({
'label[0,'..position..';'..name..']',
'label[4,'..position..';'..variable..']',
'label[7,'..position..';'..value..']'
}, ' ')
end
-- Real Time Universal Formspec -- Real Time Universal Formspec