1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Replace settings tab with button

This commit is contained in:
rubenwardy 2023-08-28 16:56:32 +01:00 committed by Gregor Parzefall
parent 798b9eae4a
commit 48ab1835da
3 changed files with 58 additions and 31 deletions

View file

@ -66,8 +66,8 @@ local function get_formspec(self)
local content, prepend = tab.get_formspec(self, tab.name, tab.tabdata, tab.tabsize)
local tsize = tab.tabsize or { width = self.width, height = self.height }
if self.parent == nil and not prepend then
local tsize = tab.tabsize or {width=self.width, height=self.height}
prepend = string.format("size[%f,%f,%s]", tsize.width, tsize.height,
dump(self.fixed_size))
@ -76,7 +76,28 @@ local function get_formspec(self)
end
end
local formspec = (prepend or "") .. self:tab_header() .. content
local end_button_size = 0.75
local tab_header_size = { width = tsize.width, height = 0.85 }
if self.end_button then
tab_header_size.width = tab_header_size.width - end_button_size - 0.1
end
local formspec = (prepend or "") .. self:tab_header(tab_header_size) .. content
if self.end_button then
formspec = formspec ..
("style[%s;noclip=true;border=false]"):format(self.end_button.name) ..
("tooltip[%s;%s]"):format(self.end_button.name, self.end_button.label) ..
("image_button[%f,%f;%f,%f;%s;%s;]"):format(
self.width - end_button_size,
(-tab_header_size.height - end_button_size) / 2,
end_button_size,
end_button_size,
core.formspec_escape(self.end_button.icon),
self.end_button.name)
end
return formspec
end
@ -91,8 +112,12 @@ local function handle_buttons(self,fields)
return true
end
if self.end_button and fields[self.end_button.name] then
return self.end_button.on_click(self)
end
if self.glb_btn_handler ~= nil and
self.glb_btn_handler(self,fields) then
self.glb_btn_handler(self, fields) then
return true
end
@ -126,8 +151,7 @@ end
--------------------------------------------------------------------------------
local function tab_header(self)
local function tab_header(self, size)
local toadd = ""
for i=1,#self.tablist,1 do
@ -138,8 +162,8 @@ local function tab_header(self)
toadd = toadd .. self.tablist[i].caption
end
return string.format("tabheader[%f,%f;%s;%s;%i;true;false]",
self.header_x, self.header_y, self.name, toadd, self.last_tab_index);
return string.format("tabheader[%f,%f;%f,%f;%s;%s;%i;true;false]",
self.header_x, self.header_y, size.width, size.height, self.name, toadd, self.last_tab_index)
end
--------------------------------------------------------------------------------
@ -230,6 +254,8 @@ local tabview_metatable = {
function(self,handler) self.glb_evt_handler = handler end,
set_fixed_size =
function(self,state) self.fixed_size = state end,
set_end_button =
function(self, v) self.end_button = v end,
tab_header = tab_header,
handle_tab_buttons = handle_tab_buttons
}