Add sample

This commit is contained in:
Evgeny
2023-10-18 09:02:16 +04:00
parent b202daa621
commit 015252323a
2 changed files with 3 additions and 48 deletions

View File

@@ -1,48 +0,0 @@
-- name = "Screen state"
local json = require "json"
function on_resume()
ui:show_buttons{
"Save screen",
"Restore screen",
}
end
function on_click(idx)
if idx == 1 then
save_state()
else
restore_state()
end
end
function save_state()
local state = aio:get_active_widgets()
local json_str = json.encode(state)
files:write("screen-state", json_str)
ui:show_toast("Screen state saved!")
end
function restore_state()
local json_str = files:read("screen-state")
local state = json.decode(json_str)
remove_all_widgets()
for k,v in pairs(state) do
aio:add_widget(v.name, v.position)
end
ui:show_toast("Screen state restored!")
end
function remove_all_widgets()
local curr_state = aio:get_active_widgets()
for k,v in pairs(curr_state) do
if (v.name ~= "screen-state-widget.lua") then
aio:remove_widget(v.position)
end
end
end

View File

@@ -0,0 +1,3 @@
function on_resume()
ui:show_text("%%fa:cube%% <b>This</b> is text with icons %%fa:face-smile%% %%fa:poo%% <i>and styles</i> %%fa:cube%%")
end