Improve performance and fix index_event parsing
This commit is contained in:
parent
df9e9e93a5
commit
d1ba059652
|
@ -47,6 +47,10 @@ all attributes are lowercase.
|
||||||
While I try to reduce backwards incompatibilities, sometimes they are necessary
|
While I try to reduce backwards incompatibilities, sometimes they are necessary
|
||||||
to either fix bugs in formspec_ast or for implementing new formspec features.
|
to either fix bugs in formspec_ast or for implementing new formspec features.
|
||||||
|
|
||||||
|
#### March 2021
|
||||||
|
|
||||||
|
- The `index_event` value for `dropdown` is now a boolean instead of a string.
|
||||||
|
|
||||||
#### February 2021
|
#### February 2021
|
||||||
|
|
||||||
- The `close_on_enter` value for `field_close_on_enter` is now a boolean
|
- The `close_on_enter` value for `field_close_on_enter` is now a boolean
|
||||||
|
|
22
core.lua
22
core.lua
|
@ -401,22 +401,34 @@ end
|
||||||
local compare_blanks
|
local compare_blanks
|
||||||
do
|
do
|
||||||
local function get_nonempty(a)
|
local function get_nonempty(a)
|
||||||
local nonempty = 0
|
if a.nonempty then
|
||||||
|
return a.nonempty, a.strings
|
||||||
|
end
|
||||||
|
local nonempty, strings = 0, 0
|
||||||
for _, i in ipairs(a) do
|
for _, i in ipairs(a) do
|
||||||
if type(i) == 'string' and i ~= '' then
|
if type(i) == 'string' and i ~= '' then
|
||||||
nonempty = nonempty + 1
|
nonempty = nonempty + 1
|
||||||
|
strings = strings + 1
|
||||||
elseif type(i) == 'table' then
|
elseif type(i) == 'table' then
|
||||||
nonempty = nonempty + get_nonempty(i)
|
nonempty = nonempty + get_nonempty(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
a.nonempty = nonempty
|
a.nonempty, a.strings = nonempty, strings
|
||||||
return nonempty
|
return nonempty, strings
|
||||||
end
|
end
|
||||||
|
|
||||||
function compare_blanks(a, b)
|
function compare_blanks(a, b)
|
||||||
local a_n, b_n = get_nonempty(a), get_nonempty(b)
|
local a_n, a_strings = get_nonempty(a)
|
||||||
|
local b_n, b_strings = get_nonempty(b)
|
||||||
if a_n == b_n then
|
if a_n == b_n then
|
||||||
return #a < #b
|
local a_l = #a
|
||||||
|
local b_l = #b
|
||||||
|
if a_l == b_l then
|
||||||
|
-- Prefer elements with less tables
|
||||||
|
return a_strings > b_strings
|
||||||
|
else
|
||||||
|
return a_l < b_l
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return a_n >= b_n
|
return a_n >= b_n
|
||||||
end
|
end
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -114,7 +114,7 @@ dropdown:
|
||||||
- - - [item, string]
|
- - - [item, string]
|
||||||
- '...'
|
- '...'
|
||||||
- [selected_idx, number]
|
- [selected_idx, number]
|
||||||
- [index_event, string]
|
- [index_event, boolean]
|
||||||
- - - [x, number]
|
- - - [x, number]
|
||||||
- [y, number]
|
- [y, number]
|
||||||
- [w, number]
|
- [w, number]
|
||||||
|
@ -122,7 +122,7 @@ dropdown:
|
||||||
- - - [item, string]
|
- - - [item, string]
|
||||||
- '...'
|
- '...'
|
||||||
- [selected_idx, number]
|
- [selected_idx, number]
|
||||||
- [index_event, string]
|
- [index_event, boolean]
|
||||||
- - - [x, number]
|
- - - [x, number]
|
||||||
- [y, number]
|
- [y, number]
|
||||||
- - [w, number]
|
- - [w, number]
|
||||||
|
|
|
@ -19,7 +19,7 @@ _known = _make_known(
|
||||||
'frame_duration', 'frame_start'),
|
'frame_duration', 'frame_start'),
|
||||||
boolean=('auto_clip', 'fixed_size', 'transparent', 'draw_border', 'bool',
|
boolean=('auto_clip', 'fixed_size', 'transparent', 'draw_border', 'bool',
|
||||||
'noclip', 'drawborder', 'selected', 'force', 'close_on_enter',
|
'noclip', 'drawborder', 'selected', 'force', 'close_on_enter',
|
||||||
'continuous', 'mouse_control'),
|
'continuous', 'mouse_control', 'index_event'),
|
||||||
fullscreen=('fullscreen',),
|
fullscreen=('fullscreen',),
|
||||||
table=('param', 'opt', 'prop'),
|
table=('param', 'opt', 'prop'),
|
||||||
null=('',),
|
null=('',),
|
||||||
|
|
11
tests.lua
11
tests.lua
|
@ -80,6 +80,7 @@ local fs = [[
|
||||||
image[0,1;1,1;air.png]
|
image[0,1;1,1;air.png]
|
||||||
set_focus[name;true]
|
set_focus[name;true]
|
||||||
dropdown[0,0;1;test;abc,def,ghi,jkl;2]
|
dropdown[0,0;1;test;abc,def,ghi,jkl;2]
|
||||||
|
dropdown[0,0;1;test;abc,def,ghi,jkl;2;true]
|
||||||
field_close_on_enter[my-field;false]
|
field_close_on_enter[my-field;false]
|
||||||
bgcolor[blue]
|
bgcolor[blue]
|
||||||
bgcolor[blue;true]
|
bgcolor[blue;true]
|
||||||
|
@ -168,6 +169,16 @@ test_parse_unparse(fs, {
|
||||||
item = {"abc", "def", "ghi", "jkl"},
|
item = {"abc", "def", "ghi", "jkl"},
|
||||||
selected_idx = 2,
|
selected_idx = 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type = "dropdown",
|
||||||
|
x = 0,
|
||||||
|
y = 0,
|
||||||
|
w = 1,
|
||||||
|
name = "test",
|
||||||
|
item = {"abc", "def", "ghi", "jkl"},
|
||||||
|
selected_idx = 2,
|
||||||
|
index_event = true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type = "field_close_on_enter",
|
type = "field_close_on_enter",
|
||||||
name = "my-field",
|
name = "my-field",
|
||||||
|
|
Loading…
Reference in New Issue