Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix menu selection initialization and scroll position #97

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions uosc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ function Menu:open(items, open_item, opts)
-- Set initial dimensions
this:on_display_change()

-- Scroll to active item
this:scroll_to_item(this.active_item)
-- Scroll to selected item
this:scroll_to_item(this.selected_item)

-- Transition in animation
menu.transition = {to = 'child', target = this}
Expand Down Expand Up @@ -968,13 +968,13 @@ function Menu:open(items, open_item, opts)
for key, value in pairs(props) do this[key] = value end
end

-- Trigger changes and re-render
this:on_display_change()

-- Reset indexes and scroll
this:select_index(this.selected_item)
this:activate_index(this.active_item)
this:scroll_to(this.scroll_y)

-- Trigger changes and re-render
this:on_display_change()
request_render()
end,
set_offset_x = function(this, offset)
Expand Down Expand Up @@ -1030,6 +1030,10 @@ function Menu:open(items, open_item, opts)
end,
activate_index = function(this, index)
this.active_item = (index and index >= 1 and index <= #this.items) and index or nil
if not this.selected_item then
this.selected_item = this.active_item
this:scroll_to_item(this.selected_item)
end
request_render()
end,
activate_value = function(this, value)
Expand Down