CogentRedTester / mpv-scroll-list

MIT License
36 stars 3 forks source link

Tree View #1

Closed bjsi closed 3 years ago

bjsi commented 3 years ago

Hey, thanks for the amazing work. Your scripts are excellent.

I'm wondering if it would be possible to extend this script to create a tree view, so pressing enter on the currently selected item would toggle open another scroll list nested under the selected item, and so on?

Would be interested in giving this a shot if you think it's possible.

Thanks!

CogentRedTester commented 3 years ago

Yes extending this API to do that would be quite easy. However, I don't see a way to generalise that functionality in such a way that it would work for everyone, so I think that a tree structure would be best implemented by the other scripts, rather than inside this API.

CogentRedTester commented 3 years ago

Here's an example of an extremely simple implementation of this. In this code a sublist in the tree is stored inside the list key of the item table. I haven't actually bothered to test this so there may be some bug I've missed, but this should give an idea of how easy it would be to implement this.


local function enter()
    local item = list.__current
    if not item or not item.list then return end

    --switching the list for the sublist
    local new_list = item.list
    new_list.parent = list.list
    list.list = new_list
    list:update_ass()
end

local function back()
    if not list.list.parent then return end

    --changing the list back to the parent
    local old_list = list.list
    list.list = old_list.parent
    old_list.parent = nil
    list:update_ass()
end