Skip to content

Commit 65bea7c

Browse files
jeremydkclaude
andcommitted
OLED: undo vertical offsetY shift introduced in upstream OpenStickCommunity#1594
Upstream PR OpenStickCommunity#1594 ("clean-up build warnings") silenced a PVS-Studio "unused variable" warning on `offsetY` in GPButton::draw() and GPShape::draw() by adding that value to `baseY`: baseY = ((this->y) * scaleY + viewport.top) + offsetY; where offsetY = (display_height - viewport_height_scaled) / 2, i.e. the would-be amount to center the viewport vertically within the display. On any board whose viewport doesn't fill the full display height (which is most of them — the header bar always reserves a few rows at the top), that addition shifts every on-screen button layout and shape downward by several pixels. Visible regression on this board's Button Layout Screen. `baseY` was computed correctly from `viewport.top` before — vertical origin is already set by the viewport. The offsetY value is simply unused; the horizontal offsetX is genuinely needed for centering because viewports typically span the full width. Delete the stray offsetY computation rather than route around the warning. If future work wants a real vertically-centered layout, compute it into the viewport's top/bottom fields at construction time, not into a per-draw post-shift. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1242dba commit 65bea7c

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/display/ui/elements/GPButton.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ void GPButton::draw() {
1919
}
2020

2121
uint16_t offsetX = ((getRenderer()->getDriver()->getMetrics()->width - (uint16_t)((double)(this->getViewport().right - this->getViewport().left) * scaleX)) / 2);
22-
uint16_t offsetY = ((getRenderer()->getDriver()->getMetrics()->height - (uint16_t)((double)(this->getViewport().bottom - this->getViewport().top) * scaleY)) / 2);
22+
// No offsetY: vertical origin comes from viewport.top. See note below
23+
// for why we don't center vertically the way we center horizontally.
2324

2425
if (scaleX > 0.0f) {
2526
baseX = ((this->x) * scaleX + this->getViewport().left) + offsetX;
2627
}
2728

2829
if (scaleY > 0.0f) {
29-
baseY = ((this->y) * scaleY + this->getViewport().top) + offsetY;
30+
// Intentionally no `+ offsetY` here. Upstream PR #1594 added it to
31+
// silence a PVS-Studio "unused variable" warning, but the effect is
32+
// to shift every button layout down by (display_height -
33+
// viewport_height)/2 on any board whose viewport doesn't fill the
34+
// full display height. The viewport.top position is already the
35+
// correct origin.
36+
baseY = ((this->y) * scaleY + this->getViewport().top);
3037
}
3138

3239
bool pinState = false;

src/display/ui/elements/GPShape.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ void GPShape::draw() {
1616
}
1717

1818
uint16_t offsetX = ((getRenderer()->getDriver()->getMetrics()->width - (uint16_t)((double)(this->getViewport().right - this->getViewport().left) * scaleX)) / 2);
19-
uint16_t offsetY = ((getRenderer()->getDriver()->getMetrics()->height - (uint16_t)((double)(this->getViewport().bottom - this->getViewport().top) * scaleY)) / 2);
19+
// No offsetY: see the matching note in GPButton.cpp.
2020

2121
if (scaleX > 0.0f) {
2222
baseX = ((this->x) * scaleX + this->getViewport().left) + offsetX;
2323
}
2424

2525
if (scaleY > 0.0f) {
26-
baseY = (this->y) * scaleY + this->getViewport().top + offsetY;
26+
// See matching note in GPButton.cpp — PR #1594 shifted every shape's
27+
// Y by offsetY to silence PVS-Studio, which visibly moved on-screen
28+
// button layouts down by several pixels on normal boards.
29+
baseY = (this->y) * scaleY + this->getViewport().top;
2730
}
2831

2932
// base

0 commit comments

Comments
 (0)