Skip to content

Commit

Permalink
feat: navigating menu with up/down/home/end keys is now instant with …
Browse files Browse the repository at this point in the history
…no animation

Left Page Up/Down as the animation is useful there (gives a sense of where the menu has animated from & to), but up/down/home/end just work better when instant.
  • Loading branch information
tomasklaen committed Oct 8, 2023
1 parent 1440fde commit 61ce329
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions scripts/uosc/elements/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,6 @@ function Menu:delete_value(value, menu)
self:delete_index(index)
end

function Menu:prev()
self:navigate_by_offset(-1)
end

function Menu:next()
self:navigate_by_offset(1)
end

---@param menu MenuStack One of menus in `self.all`.
---@param x number `x` coordinate to slide from.
function Menu:slide_in_menu(menu, x)
Expand Down Expand Up @@ -666,9 +658,18 @@ function Menu:select_by_offset(offset, menu)
end

---@param offset integer
function Menu:navigate_by_offset(offset)
---@param immediate? boolean
function Menu:navigate_by_offset(offset, immediate)
self:select_by_offset(offset)
if self.current.selected_index then self:scroll_to_index(self.current.selected_index) end
if self.current.selected_index then self:scroll_to_index(self.current.selected_index, self.current, immediate) end
end

function Menu:prev()
self:navigate_by_offset(-1, true)
end

function Menu:next()
self:navigate_by_offset(1, true)
end

function Menu:on_pgup()
Expand All @@ -682,11 +683,11 @@ function Menu:on_pgdwn()
end

function Menu:on_home()
self:navigate_by_offset(-INFINITY)
self:navigate_by_offset(-INFINITY, true)
end

function Menu:on_end()
self:navigate_by_offset(INFINITY)
self:navigate_by_offset(INFINITY, true)
end

---@param menu MenuStack
Expand Down

2 comments on commit 61ce329

@christoph-heinrich
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree with up/down, I do miss the animation of home/end 😐

@tomasklaen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, I was undecided about home/end. I'll revert it :)

Please sign in to comment.