Add srollbar formspec element

This commit is contained in:
sapier 2014-06-19 18:17:35 +02:00 committed by Nils Dagsson Moskopp
parent 79490bfcdc
commit dd0e0e019f
Signed by: erle
GPG Key ID: A3BC671C35191080
2 changed files with 76 additions and 47 deletions

View File

@ -140,58 +140,58 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function get_last_folder(text,count) function get_last_folder(text,count)
local parts = text:split(DIR_DELIM) local parts = text:split(DIR_DELIM)
if count == nil then if count == nil then
return parts[#parts] return parts[#parts]
end end
local retval = "" local retval = ""
for i=1,count,1 do for i=1,count,1 do
retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM
end end
return retval return retval
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function cleanup_path(temppath) function cleanup_path(temppath)
local parts = temppath:split("-") local parts = temppath:split("-")
temppath = "" temppath = ""
for i=1,#parts,1 do for i=1,#parts,1 do
if temppath ~= "" then if temppath ~= "" then
temppath = temppath .. "_" temppath = temppath .. "_"
end end
temppath = temppath .. parts[i] temppath = temppath .. parts[i]
end end
parts = temppath:split(".") parts = temppath:split(".")
temppath = "" temppath = ""
for i=1,#parts,1 do for i=1,#parts,1 do
if temppath ~= "" then if temppath ~= "" then
temppath = temppath .. "_" temppath = temppath .. "_"
end end
temppath = temppath .. parts[i] temppath = temppath .. parts[i]
end end
parts = temppath:split("'") parts = temppath:split("'")
temppath = "" temppath = ""
for i=1,#parts,1 do for i=1,#parts,1 do
if temppath ~= "" then if temppath ~= "" then
temppath = temppath .. "" temppath = temppath .. ""
end end
temppath = temppath .. parts[i] temppath = temppath .. parts[i]
end end
parts = temppath:split(" ") parts = temppath:split(" ")
temppath = "" temppath = ""
for i=1,#parts,1 do for i=1,#parts,1 do
if temppath ~= "" then if temppath ~= "" then
temppath = temppath temppath = temppath
end end
temppath = temppath .. parts[i] temppath = temppath .. parts[i]
end end
return temppath return temppath
end end
@ -211,7 +211,7 @@ function core.splittext(text,charlimit)
local retval = {} local retval = {}
local current_idx = 1 local current_idx = 1
local start,stop = string.find(text," ",current_idx) local start,stop = string.find(text," ",current_idx)
local nl_start,nl_stop = string.find(text,"\n",current_idx) local nl_start,nl_stop = string.find(text,"\n",current_idx)
local gotnewline = false local gotnewline = false
@ -226,30 +226,30 @@ function core.splittext(text,charlimit)
table.insert(retval,last_line) table.insert(retval,last_line)
last_line = "" last_line = ""
end end
if last_line ~= "" then if last_line ~= "" then
last_line = last_line .. " " last_line = last_line .. " "
end end
last_line = last_line .. string.sub(text,current_idx,stop -1) last_line = last_line .. string.sub(text,current_idx,stop -1)
if gotnewline then if gotnewline then
table.insert(retval,last_line) table.insert(retval,last_line)
last_line = "" last_line = ""
gotnewline = false gotnewline = false
end end
current_idx = stop+1 current_idx = stop+1
start,stop = string.find(text," ",current_idx) start,stop = string.find(text," ",current_idx)
nl_start,nl_stop = string.find(text,"\n",current_idx) nl_start,nl_stop = string.find(text,"\n",current_idx)
if nl_start ~= nil and (start == nil or nl_start < start) then if nl_start ~= nil and (start == nil or nl_start < start) then
start = nl_start start = nl_start
stop = nl_stop stop = nl_stop
gotnewline = true gotnewline = true
end end
end end
--add last part of text --add last part of text
if string.len(last_line) + (string.len(text) - current_idx) > charlimit then if string.len(last_line) + (string.len(text) - current_idx) > charlimit then
table.insert(retval,last_line) table.insert(retval,last_line)
@ -258,7 +258,7 @@ function core.splittext(text,charlimit)
last_line = last_line .. " " .. string.sub(text,current_idx) last_line = last_line .. " " .. string.sub(text,current_idx)
table.insert(retval,last_line) table.insert(retval,last_line)
end end
return retval return retval
end end
@ -400,6 +400,17 @@ function core.explode_textlist_event(evt)
return {type="INV", index=0} return {type="INV", index=0}
end end
--------------------------------------------------------------------------------
function core.explode_scrollbar_event(evt)
local retval = core.explode_textlist_event(evt)
retval.value = retval.index
retval.index = nil
return retval
end
--------------------------------------------------------------------------------
function core.pos_to_string(pos) function core.pos_to_string(pos)
return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")" return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")"
end end
@ -410,14 +421,14 @@ end
if INIT == "mainmenu" then if INIT == "mainmenu" then
function core.get_game(index) function core.get_game(index)
local games = game.get_games() local games = game.get_games()
if index > 0 and index <= #games then if index > 0 and index <= #games then
return games[index] return games[index]
end end
return nil return nil
end end
function fgettext(text, ...) function fgettext(text, ...)
text = core.gettext(text) text = core.gettext(text)
local arg = {n=select('#', ...), ...} local arg = {n=select('#', ...), ...}

View File

@ -75,29 +75,38 @@ local function showconfirm_reset(tabview)
new_dlg:show() new_dlg:show()
end end
local function gui_scale_index() local function gui_scale_to_scrollbar()
local current_value = tonumber(core.setting_get("gui_scaling")) local current_value = tonumber(core.setting_get("gui_scaling"))
if (current_value == nil) then if (current_value == nil) or current_value < 0.25 then
return 0 return 0
elseif current_value <= 0.5 then
return 1
elseif current_value <= 0.625 then
return 2
elseif current_value <= 0.75 then
return 3
elseif current_value <= 0.875 then
return 4
elseif current_value <= 1.0 then
return 5
elseif current_value <= 1.25 then
return 6
elseif current_value <= 1.5 then
return 7
else
return 8
end end
if current_value <= 1.25 then
return ((current_value - 0.25)/ 1.0) * 700
end
if current_value <= 6 then
return ((current_value -1.25) * 100) + 700
end
return 1000
end
local function scrollbar_to_gui_scale(value)
value = tonumber(value)
if (value <= 700) then
return ((value / 700) * 1.0) + 0.25
end
if (value <=1000) then
return ((value - 700) / 100) + 1.25
end
return 1
end end
local function formspec(tabview, name, tabdata) local function formspec(tabview, name, tabdata)
@ -138,8 +147,11 @@ local function formspec(tabview, name, tabdata)
tab_string = tab_string .. tab_string = tab_string ..
"box[0.75,4.25;3.25,1.25;#999999]" .. "box[0.75,4.25;3.25,1.25;#999999]" ..
"label[1,4.25;" .. fgettext("GUI scale factor") .. "]" .. "label[1,4.25;" .. fgettext("GUI scale factor") .. "]" ..
"dropdown[1,4.75;3.0;dd_gui_scaling;0.5,0.625,0.75,0.875,1.0,1.25,1.5,2.0;" "scrollbar[1,4.75;2.75,0.4;sb_gui_scaling;horizontal;" ..
.. gui_scale_index() .. "]" gui_scale_to_scrollbar() .. "]" ..
"tooltip[sb_gui_scaling;" ..
fgettext("Scaling factor applied to menu elements: ") ..
dump(core.setting_get("gui_scaling")) .. "]"
if ANDROID then if ANDROID then
tab_string = tab_string .. tab_string = tab_string ..
@ -257,6 +269,16 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
core.show_keys_menu() core.show_keys_menu()
return true return true
end end
if fields["sb_gui_scaling"] then
local event = core.explode_scrollbar_event(fields["sb_gui_scaling"])
if event.type == "CHG" then
local tosave = string.format("%.2f",scrollbar_to_gui_scale(event.value))
core.setting_set("gui_scaling",tosave)
return true
end
end
if fields["cb_touchscreen_target"] then if fields["cb_touchscreen_target"] then
core.setting_set("touchtarget", fields["cb_touchscreen_target"]) core.setting_set("touchtarget", fields["cb_touchscreen_target"])
return true return true
@ -272,10 +294,6 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"]) core.setting_set("touchscreen_threshold",fields["dd_touchthreshold"])
ddhandled = true ddhandled = true
end end
if fields["dd_gui_scaling"] then
core.setting_set("gui_scaling",fields["dd_gui_scaling"])
ddhandled = true
end
return ddhandled return ddhandled
end end