tboox / ltui

🍖 A cross-platform terminal ui library based on Lua
https://tboox.org
Apache License 2.0
818 stars 49 forks source link

circular behaviour of views in a panel #17

Closed laelnasan closed 3 years ago

laelnasan commented 3 years ago

Hi, it is me again I don't know if this feature is intended or not (that is why I couldn't decide between feature or bug) but whenever a selected view in a panel is removed, the next view is selected, in a circular list fashion. Imho a stack behavior would be more useful here, maintaining the order of, for example, multiple layers of dialogs.

My suggestion would be to add an optional flag in the panel:remove() function so that one willing to apply this behavior to a dialog (like in my case) would be able to do it by simply overwriting the dialog:quit() function as such:

-- remove view
function panel:remove(v, stackish)

(...)

    -- select next view
    if self:current() == v then
        if stackish then self:select_prev() else self:select_next(nil, true) end
    end

(...)

end

then one would be able to write its own dialog:quit() function like so

dialog.quit = function (self)
    local parent = self:parent()
    if parent then
        self:action_on(action.ac_on_exit)
        parent:remove(self, true)
    end
end

If you dont think it is worth the trouble, though, I am happy to continue hacking my way through this beautiful code

waruqi commented 3 years ago

I have improved it on master branch. You can use panel:remove(v, {select_prev = true}) to select previous view.

laelnasan commented 3 years ago

thank you very much