Skip to content

Commit

Permalink
scroll category into view on selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Bauumm committed Nov 4, 2023
1 parent eac672b commit d42a850
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ui/keyboard_navigation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ function keyboard_navigation.set_screen(screen)
end
end

local function scroll_into_view(element, scroll_to_elem, x, y)
---scroll an element into view
---@param element any
---@param scroll_to_elem any (used internally (recursion))
---@param x any (used internally (recursion))
---@param y any (used internally (recursion))
function keyboard_navigation.scroll_into_view(element, scroll_to_elem, x, y)
scroll_to_elem = scroll_to_elem or element
if not x or not y then
x, y = scroll_to_elem.transform:transformPoint(scroll_to_elem._transform:transformPoint(0, 0))
Expand All @@ -53,7 +58,7 @@ local function scroll_into_view(element, scroll_to_elem, x, y)
element.parent:scroll_into_view(x, y, scroll_to_elem.width, scroll_to_elem.height)
end
x, y = element.parent.transform:transformPoint(element.parent._transform:transformPoint(x, y))
scroll_into_view(element.parent, scroll_to_elem, x, y)
keyboard_navigation.scroll_into_view(element.parent, scroll_to_elem, x, y)
end
end

Expand Down Expand Up @@ -82,7 +87,7 @@ function keyboard_navigation.select_element(element, call_handlers)
end
elem = parent
end
scroll_into_view(element)
keyboard_navigation.scroll_into_view(element)
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions ui/overlay/settings.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local overlay = require("ui.overlay")
local keyboard_navigation = require("ui.keyboard_navigation")
local transitions = require("ui.anim.transitions")
local quad = require("ui.elements.quad")
local flex = require("ui.layout.flex")
Expand Down Expand Up @@ -119,6 +120,17 @@ for i = 1, #category_names do
category_layouts[#category_layouts + 1] = category_settings
category_indicators[#category_indicators + 1] = quad:new({
child_element = icon:new(category_icons[category]),
selectable = true,
selection_handler = function(self)
if self.selected then
self.border_color = { 0, 0, 1, 1 }
else
self.border_color = { 1, 1, 1, 1 }
end
keyboard_navigation.scroll_into_view(category_settings)
-- make keyboard navigation go into the category and not wherever it was last when going into the settings column
category_settings.parent.last_selection = category_settings
end,
})
end

Expand Down

0 comments on commit d42a850

Please sign in to comment.