Skip to content

Commit 5c7741e

Browse files
committed
Fix offset of UIPaginatedList items upon resize
Fixes #221.
1 parent b258c50 commit 5c7741e

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/ui/elements/lists/UIPaginatedList.lua

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ local function fillPages( items, maximumPages, height, ax, ay )
5959

6060
for i = 1, #items do
6161
currentPage[#currentPage + 1] = items[i]
62-
items[i]:setRelativePosition( ax, ay + #currentPage-1 )
62+
items[i]:setOrigin( ax, ay )
63+
items[i]:setRelativePosition( 0, #currentPage-1 )
6364

6465
-- Add the current page to the "pages" table if it is full or if we have
6566
-- added all the items to add.
@@ -179,9 +180,9 @@ end
179180
-- Creates the buttons to scroll through the pages.
180181
--
181182
function UIPaginatedList:addButtons()
182-
self.buttonPrev = UIButton( 0, 0, self.ax + self.w-2, self.ay + self.h-1, 1, 1, function() self:scrollPage( -1 ) end )
183+
self.buttonPrev = UIButton( self.ax, self.ay, self.w-2, self.h-1, 1, 1, function() self:scrollPage( -1 ) end )
183184
self.buttonPrev:setIcon( 'ui_prev_element' )
184-
self.buttonNext = UIButton( 0, 0, self.ax + self.w-1, self.ay + self.h-1, 1, 1, function() self:scrollPage( 1 ) end )
185+
self.buttonNext = UIButton( self.ax, self.ay, self.w-1, self.h-1, 1, 1, function() self:scrollPage( 1 ) end )
185186
self.buttonNext:setIcon( 'ui_next_element' )
186187

187188
self:addChild( self.buttonPrev )
@@ -277,4 +278,20 @@ function UIPaginatedList:setFocus( focus )
277278
self.pages[self.currentPage][self.cursor]:setFocus( focus )
278279
end
279280

281+
---
282+
-- Forwards changes to the origin of the paginated list to the children and
283+
-- all items on each page.
284+
-- @tparam number ox The new origin along the x-axis.
285+
-- @tparam number oy The new origin along the y-axis.
286+
--
287+
function UIPaginatedList:setOrigin( ox, oy )
288+
UIPaginatedList.super.setOrigin( self, ox, oy )
289+
290+
for _, page in ipairs( self.pages ) do
291+
for _, item in ipairs( page ) do
292+
item:setOrigin( ox, oy )
293+
end
294+
end
295+
end
296+
280297
return UIPaginatedList

src/ui/screens/KeybindingScreen.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,11 @@ function KeybindingScreen:receive( event, ... )
262262
end
263263
end
264264

265+
function KeybindingScreen:resize( _, _ )
266+
local lx = GridHelper.centerElement( BUTTON_LIST_WIDTH, 1 )
267+
268+
self.paginatedList:setOrigin( lx, BUTTON_LIST_Y )
269+
self.buttonList:setOrigin( lx, BUTTON_LIST_Y + BUTTON_LIST_HEIGHT + 1 )
270+
end
271+
265272
return KeybindingScreen

0 commit comments

Comments
 (0)