UI polishing.
This commit is contained in:
parent
53ba9ed087
commit
d3c12e9952
55
index.lua
55
index.lua
|
@ -53,6 +53,18 @@ local function get_properties_list(list_name)
|
||||||
end
|
end
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local property_names = {
|
||||||
|
h = 'Height',
|
||||||
|
w = 'Width',
|
||||||
|
drawborder = 'Draw border',
|
||||||
|
listelem = 'Items',
|
||||||
|
selected_idx = 'Selected item',
|
||||||
|
}
|
||||||
|
local function get_property_name(n)
|
||||||
|
return property_names[n] or n:sub(1, 1):upper() .. n:sub(2):gsub('_', ' ')
|
||||||
|
end
|
||||||
|
|
||||||
local function show_properties(elem, node)
|
local function show_properties(elem, node)
|
||||||
if not properties_elem then
|
if not properties_elem then
|
||||||
properties_elem = document:createElement('div')
|
properties_elem = document:createElement('div')
|
||||||
|
@ -80,7 +92,7 @@ local function show_properties(elem, node)
|
||||||
-- however the "reset" button works.
|
-- however the "reset" button works.
|
||||||
local k = k
|
local k = k
|
||||||
formspec = formspec .. 'label[0.25,' .. y - 0.2 .. ';' ..
|
formspec = formspec .. 'label[0.25,' .. y - 0.2 .. ';' ..
|
||||||
formspec_escape(k) .. ' (list)]'
|
formspec_escape(get_property_name(k)) .. ' (list)]'
|
||||||
y = y + 0.1
|
y = y + 0.1
|
||||||
for i, item in ipairs(v) do
|
for i, item in ipairs(v) do
|
||||||
formspec = formspec .. 'label[0.4,' .. y + 0.3 .. ';•]' ..
|
formspec = formspec .. 'label[0.4,' .. y + 0.3 .. ';•]' ..
|
||||||
|
@ -117,8 +129,8 @@ local function show_properties(elem, node)
|
||||||
y = y + 1.1
|
y = y + 1.1
|
||||||
end
|
end
|
||||||
formspec = formspec .. ';' .. formspec_escape('prop_' .. k) .. ';' ..
|
formspec = formspec .. ';' .. formspec_escape('prop_' .. k) .. ';' ..
|
||||||
formspec_escape(k .. ' (' .. value_type .. ')') .. ';' ..
|
formspec_escape(get_property_name(k) .. ' (' .. value_type .. ')')
|
||||||
formspec_escape(tostring(v)) .. ']'
|
.. ';' .. formspec_escape(tostring(v)) .. ']'
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -165,7 +177,9 @@ local function show_properties(elem, node)
|
||||||
if type(node[k]) == 'string' then
|
if type(node[k]) == 'string' then
|
||||||
node[k] = elem.lastChild.value
|
node[k] = elem.lastChild.value
|
||||||
elseif type(node[k]) == 'number' then
|
elseif type(node[k]) == 'number' then
|
||||||
node[k] = tonumber(elem.lastChild.value) or node[k]
|
-- Allow commas to be used as decimal points.
|
||||||
|
local raw = elem.lastChild.value:gsub(',', '.')
|
||||||
|
node[k] = tonumber(raw) or node[k]
|
||||||
elseif type(node[k]) == 'boolean' then
|
elseif type(node[k]) == 'boolean' then
|
||||||
node[k] = elem:getAttribute('data-checked') == 'true'
|
node[k] = elem:getAttribute('data-checked') == 'true'
|
||||||
end
|
end
|
||||||
|
@ -611,10 +625,15 @@ function renderer.export(tree, opts)
|
||||||
return fs, nil
|
return fs, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function render_into(base, formspec, callbacks)
|
||||||
|
base.innerHTML = ''
|
||||||
|
base:appendChild(assert(renderer.render_formspec(formspec, callbacks,
|
||||||
|
false)))
|
||||||
|
end
|
||||||
|
|
||||||
local element_dialog
|
local element_dialog
|
||||||
local load_save_opts = {}
|
local load_save_opts = {}
|
||||||
local function show_load_save_dialog()
|
local function show_load_save_dialog()
|
||||||
element_dialog.innerHTML = ''
|
|
||||||
local callbacks = {}
|
local callbacks = {}
|
||||||
local fs = [[
|
local fs = [[
|
||||||
formspec_version[2]size[6,9.5]button[0,0;1,0.6;back;←]
|
formspec_version[2]size[6,9.5]button[0,0;1,0.6;back;←]
|
||||||
|
@ -651,9 +670,9 @@ local function show_load_save_dialog()
|
||||||
renderer.show_element_dialog(element_dialog_base)
|
renderer.show_element_dialog(element_dialog_base)
|
||||||
end
|
end
|
||||||
|
|
||||||
function callbacks.load()
|
local function load()
|
||||||
local fs = window:prompt('Paste formspec here')
|
local textarea = element_dialog.firstChild.firstChild.lastChild
|
||||||
get_options()
|
local fs = textarea.lastChild.value
|
||||||
local tree, err = renderer.import(fs, load_save_opts)
|
local tree, err = renderer.import(fs, load_save_opts)
|
||||||
if not tree then
|
if not tree then
|
||||||
window:alert('Error loading formspec:\n' .. err)
|
window:alert('Error loading formspec:\n' .. err)
|
||||||
|
@ -667,6 +686,18 @@ local function show_load_save_dialog()
|
||||||
renderer.show_element_dialog(element_dialog_base)
|
renderer.show_element_dialog(element_dialog_base)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function callbacks.load()
|
||||||
|
get_options()
|
||||||
|
local fs = 'formspec_version[2]size[6,9.5]button[0,0;1,0.6;back;←]' ..
|
||||||
|
'label[1.25,0.3;Load formspec]' ..
|
||||||
|
'button[0.25,8.25;5.5,1;load;Load formspec]' ..
|
||||||
|
'textarea[0.25,1.25;5.5,6.75;formspec;Paste your formspec here.;]'
|
||||||
|
render_into(element_dialog, fs, {
|
||||||
|
back = show_load_save_dialog,
|
||||||
|
load = load
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
function callbacks.save()
|
function callbacks.save()
|
||||||
get_options()
|
get_options()
|
||||||
local tree = renderer.elem_to_ast(element_dialog_base)
|
local tree = renderer.elem_to_ast(element_dialog_base)
|
||||||
|
@ -682,14 +713,12 @@ local function show_load_save_dialog()
|
||||||
'Error exporting formspec!;' .. formspec_escape(err)
|
'Error exporting formspec!;' .. formspec_escape(err)
|
||||||
end
|
end
|
||||||
fs = fs .. ']'
|
fs = fs .. ']'
|
||||||
element_dialog.innerHTML = ''
|
render_into(element_dialog, fs, {
|
||||||
element_dialog:appendChild(assert(renderer.render_formspec(fs, {
|
|
||||||
back = show_load_save_dialog,
|
back = show_load_save_dialog,
|
||||||
})))
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
element_dialog:appendChild(assert(renderer.render_formspec(fs, callbacks,
|
render_into(element_dialog, fs, callbacks)
|
||||||
false)))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function renderer.show_element_dialog(base)
|
function renderer.show_element_dialog(base)
|
||||||
|
|
Loading…
Reference in New Issue