From 917de32cfdcb45ab8343811d7c55e7f03fab3797 Mon Sep 17 00:00:00 2001 From: Dirk Sohler Date: Sat, 15 May 2021 17:06:41 +0200 Subject: [PATCH] make table line function a formspec helper --- system/formspec_helpers.lua | 27 +++++++++++++++++++++++ system/formspecs/real_time_universal.lua | 28 +----------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/system/formspec_helpers.lua b/system/formspec_helpers.lua index 307833b..f72151a 100644 --- a/system/formspec_helpers.lua +++ b/system/formspec_helpers.lua @@ -3,6 +3,33 @@ local S = m.translator 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 it’s 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 -- -- This function returns a fully formatted button with icon. diff --git a/system/formspecs/real_time_universal.lua b/system/formspecs/real_time_universal.lua index 6e1fcab..83e111d 100644 --- a/system/formspecs/real_time_universal.lua +++ b/system/formspecs/real_time_universal.lua @@ -1,33 +1,7 @@ local m = mtimer local S = m.translator local esc = minetest.formspec_escape - - --- 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 it’s 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 +local line = mtimer.get_table_line -- Real Time Universal Formspec