Program: Visual Studio
OS: Windows 11
I am noticing that after scrolling in a gridview, the cells appear to be changing size by 1 pixel? This then visually shifts them on the screen, which is driving my OCD nuts.
Here is how the cell looks when I load this screen:
This is the cell after scrolling down by 1 cell:
By looking at the shape of the pixels of the rounded rect at the bottom corners, you can see the size is changing somewhere.
Is this a bug, or expected because of how I have it coded?
In the update loop I use the needsDisplay property and have it call the Screen code again so it just redraws the screen so we see the updated gridview element.
I honestly prefer the shape and look in the second picture. So what am I doing wrong?
Thank you for your time and consideration,
Gridview Coding
-- VARIABLES FOR POSITION SELECTOR GRIDVIEW
local positionSelectorGridview = pd.ui.gridview.new(0, 26)
local positionCount = #selectedSpread.PositionCoordinates -- Count of positions in the selected spread
-- Set up the position selector gridview
positionSelectorGridview:setNumberOfRows(positionCount)
positionSelectorGridview:setCellPadding(2, 2, 2, 2)
positionSelectorGridview.scrollCellsToCenter = true
-- Function to draw each row of the gridview
function positionSelectorGridview:drawCell(section, row, column, selected, x, y, width, height)
gfx.setFont(garnet_16)
local fontHeight = garnet_16:getHeight()
-- Set up the position label, e.g., "Pos. 1", "Pos. 2", etc.
local positionText = "Pos. " .. row
-- Fill the background with white
gfx.setColor(gfx.kColorWhite)
gfx.fillRect(x, y, width, height)
-- Handle drawing the selected state
if selected then
gfx.setColor(gfx.kColorBlack)
gfx.fillRoundRect(x, y, width, height, 4)
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
else
gfx.setImageDrawMode(gfx.kDrawModeCopy)
end
-- Draw the position text in the center of the cell
gfx.setColor(gfx.kColorBlack)
gfx.drawTextInRect(positionText, x, y + (height / 2 - fontHeight / 2), width, fontHeight, nil, nil, kTextAlignment.center)
end
Screen Coding
-- FUNCTIONS FOR READING REVIEWS
local function reviewReadingScreen()
local combinedImage = gfx.image.new(400, 240)
local backgroundImage = gfx.image.new(SelectedBackground)
if backgroundImage then
local bgOffsetX, bgOffsetY = calculateOffsets(backgroundImage, 400, 240)
gfx.pushContext(combinedImage)
backgroundImage:draw(bgOffsetX, bgOffsetY)
gfx.popContext()
else
print("Error: Background image not found.")
end
local reviewImage = gfx.image.new("images/Misc/Reading_Review")
if reviewImage then
local reviewOffsetX, reviewOffsetY = calculateOffsets(reviewImage, 400, 240)
gfx.pushContext(combinedImage)
reviewImage:draw(reviewOffsetX, reviewOffsetY)
positionSelectorGridview:drawInRect(156, 12, 88, 26)
gfx.popContext()
else
print("Error: Review image not found.")
end
-- If Sprite already exists, remove it to replace with updated one
if ReviewReadingSprite then
ReviewReadingSprite:remove()
end
ReviewReadingSprite = gfx.sprite.new(combinedImage)
ReviewReadingSprite:setZIndex(2)
ReviewReadingSprite:moveTo(200, 120)
ReviewReadingSprite:add()
gfx.sprite.update()
end