Grid view
playdate.ui.gridview provides a means for drawing a grid view composed of cells, and optionally sections with section headers.
You must import CoreLibs/ui to use gridview.
Some notes:
playdate.ui.gridview uses playdate.timer internally, so playdate.timer.updateTimers() must be called in the main playdate.update() function.
If the gridview’s cell width is set to 0, cells will be drawn the same width as the table (minus any padding).
Section headers always draw the full width of the grid (minus padding), and do not scroll horizontally along with the rest of the content.
playdate.ui.gridview.new(cellWidth, cellHeight)
Returns a new playdate.ui.gridview with cells sized cellWidth, cellHeight. (Sizes are in pixels.) If cells should span the entire width of the grid (as in a list view), pass zero (0) for cellWidth.
Drawing
playdate.ui.gridview:drawCell(section, row, column, selected, x, y, width, height)
Override this method to draw the cells in the gridview. selected is a boolean, true if the cell being drawn is the currently-selected cell.
playdate.ui.gridview:drawSectionHeader(section, x, y, width, height)
Override this method to draw section headers. This function will only be called if the header height has been set to a value greater than zero (0).
playdate.ui.gridview:drawHorizontalDivider(x, y, width, height)
Override this method to customize the drawing of horizontal dividers. This function will only be called if the horizontal divider height is greater than zero (0) and at least one divider has been added.
playdate.ui.gridview:drawInRect(x, y, width, height)
Draws the gridview in the specified rect. Ideally this should be called on every playdate.update() to accommodate scrolling.
playdate.ui.gridview.needsDisplay
This read-only variable returns true if the gridview needs to be redrawn. This can be used to help optimize drawing in your app. Keep in mind that a gridview cannot know all reasons it may need to be redrawn, such as changes in your drawing callback functions, coordinate or size changes, or overlapping drawing, so you may need to additionally redraw at other times.
Conditionally draw a grid view
if myGridView.needsDisplay == true then
myGridView:drawInRect(x, y, w, h)
end
Configuration
playdate.ui.gridview:setNumberOfSections(num)
Sets the number of sections in the grid view. Each section contains at least one row, and row numbering starts at 1 in each section.
playdate.ui.gridview:getNumberOfSections()
Returns the number of sections in the grid view.
playdate.ui.gridview:setNumberOfRowsInSection(section, num)
Sets the number of rows in section.
playdate.ui.gridview:getNumberOfRowsInSection(section)
Returns the number of rows in section.
playdate.ui.gridview:setNumberOfColumns(num)
Sets the number of columns in the gridview. 1 by default.
playdate.ui.gridview:getNumberOfColumns()
Returns the number of columns in the gridview. 1 by default.
playdate.ui.gridview:setNumberOfRows(…)
Convenience method for list-style gridviews, or for setting the number of rows for multiple sections at a time. Pass in a list of numbers of rows for sections starting from section 1.
playdate.ui.gridview:setCellSize(cellWidth, cellHeight)
Sets the size of the cells in the gridview. If cells should span the entire width of the grid (as in a list view), pass zero (0) for cellWidth.
playdate.ui.gridview:setCellPadding(left, right, top, bottom)
Sets the amount of padding around cells.
playdate.ui.gridview:setContentInset(left, right, top, bottom)
Sets the amount of space the content is inset from the edges of the gridview. Useful if a background image is being used as a border.
playdate.ui.gridview:getCellBounds(section, row, column, [gridWidth])
Returns multiple values (x, y, width, height) representing the bounds of the cell, not including padding, relative to the top-right corner of the grid view.
If the grid view is configured with zero width cells (see playdate.ui.gridview:new), gridWidth is required, and should be the same value you would pass to playdate.ui.gridview:drawInRect.
playdate.ui.gridview:setSectionHeaderHeight(height)
Sets the height of the section headers. 0 by default, which causes section headers not to be drawn.
playdate.ui.gridview.getSectionHeaderHeight()
Returns the current height of the section headers.
playdate.ui.gridview:setSectionHeaderPadding(left, right, top, bottom)
Sets the amount of padding around section headers.
playdate.ui.gridview:setHorizontalDividerHeight(height)
Sets the height of the horizontal dividers. The default height is half the cell height specified when creating the grid view.
playdate.ui.gridview:getHorizontalDividerHeight()
Returns the height of the horizontal dividers.
playdate.ui.gridview:addHorizontalDividerAbove(section, row)
Causes a horizontal divider to be drawn above the specified row. Drawing can be customized by overriding playdate.ui.gridview:drawHorizontalDivider.
playdate.ui.gridview:removeHorizontalDividers()
Removes all horizontal dividers from the grid view.
. Switch to gridView sections for each Day.