Skip to content

Commit

Permalink
Merge pull request #367 from Xertis/main
Browse files Browse the repository at this point in the history
Added search to the content_menu
  • Loading branch information
MihailRis authored Nov 13, 2024
2 parents 4b0b643 + af8cd53 commit d8cf3ce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
12 changes: 8 additions & 4 deletions res/layouts/pages/content_menu.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<container size='1000,480' color='#0F1E2DB2' padding='8' interval='5' context='menu'>
<panel id='contents' pos='15,15' size='440,390' color='0' max-length='406' scrollable='true'>
<container size='1000,580' color='#0F1E2DB2' interval='5' context='menu'>
<panel id='contents' pos='15,15' size='440,490' color='0' max-length='455' scrollable='true'>
<!-- content is generated in script -->
</panel>
<button pos='15,430' size='440,40' onclick='menu:back()'>@Back</button>
<button pos='485,430' size='500,40' onclick='core.open_folder("user:content")'>@Open content folder</button>
<button pos='15,525' size='440,40' onclick='menu:back()'>@Back</button>
<button pos='485,525' size='500,40' onclick='core.open_folder("user:content")'>@Open content folder</button>

<panel id='search_panel' size='440,35' pos='15,485' interval='1' color='#0000004C'>
<textbox id='search_textbox' multiline='false' size='440,25' sub-consumer='function(x) refresh_search() end'></textbox>
</panel>

<panel id='content_info' pos='485,15' size='440,406' color='0' max-length='406' scrollable='true'>
<label>@Creator</label>
Expand Down
33 changes: 29 additions & 4 deletions res/layouts/pages/content_menu.xml.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local packs_installed = {}

function on_open(params)
refresh()
end
Expand All @@ -13,11 +15,33 @@ function place_pack(panel, packinfo, callback)
end
packinfo.callback = callback
panel:add(gui.template("pack", packinfo))
if not callback then
document["pack_"..packinfo.id].enabled = false
end

function refresh_search()
local search_text = document.search_textbox.text:lower()
local visible = 0
local interval = 4
local step = -1

for i, v in ipairs(packs_installed) do
local id = v[1]
local title = v[2]
local content = document["pack_" .. id]
local pos = content.pos
local size = content.size

if title:lower():find(search_text) or search_text == '' then
content.enabled = true
content.pos = {pos[1], visible * (size[2] + interval) - step}
visible = visible + 1
else
content.enabled = false
content.pos = {pos[1], (visible + #packs_installed - i) * (size[2] + interval) - step}
end
end
end


function open_pack(id)
local packinfo = pack.get_info(id)

Expand All @@ -28,8 +52,8 @@ function open_pack(id)
end

function refresh()
local packs_installed = pack.get_installed()
local packs_available = pack.get_available()
packs_installed = pack.get_installed()

for i,k in ipairs(packs_available) do
table.insert(packs_installed, k)
Expand All @@ -41,7 +65,8 @@ function refresh()
for i,id in ipairs(packs_installed) do
local packinfo = pack.get_info(id)

packinfo.index = i
packinfo.id = id
packs_installed[i] = {packinfo.id, packinfo.title}
local callback = string.format('open_pack("%s")', id)
place_pack(contents, packinfo, callback)
end
Expand Down

0 comments on commit d8cf3ce

Please sign in to comment.