mirror of
https://github.com/adafruit/Adafruit-GFX-Library.git
synced 2026-10-26 22:10:52 +00:00
Measure button label at (0,0) and keep charBounds non-virtual
Measuring at the button position predicts a line wrap that print() never does, so a wide label on a button near the right edge moved off its button. Measure at (0,0) and offset by the returned x/y. The charBounds virtual change is unrelated to this fix, so it is dropped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7de7487729
commit
a0f92f1f27
2 files changed
+6
-7
No files matched your search
+4
-4
@@ -1693,10 +1693,10 @@ void Adafruit_GFX_Button::drawButton(bool inverted) {
|
||||
_gfx->setTextColor(text);
|
||||
_gfx->setTextSize(_textsize_x, _textsize_y);
|
||||
// System font is drawn from the upper left, but custom fonts are
|
||||
// drawn from the lower left. Adjust by the Y returned from getTextBounds().
|
||||
_gfx->getTextBounds(_label, _x1, _y1, &x, &y, &w, &h);
|
||||
_gfx->setCursor(_x1 + (_w / 2) - (w / 2),
|
||||
_y1 + (_h / 2) - (h / 2) + (_y1 - y));
|
||||
// drawn from the lower left. Measure at (0,0) so a button near the
|
||||
// right edge doesn't predict a wrap, then offset by the returned x/y.
|
||||
_gfx->getTextBounds(_label, 0, 0, &x, &y, &w, &h);
|
||||
_gfx->setCursor(_x1 + (_w / 2) - (w / 2) - x, _y1 + (_h / 2) - (h / 2) - y);
|
||||
_gfx->print(_label);
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -230,9 +230,8 @@ public:
|
||||
int16_t getCursorY(void) const { return cursor_y; };
|
||||
|
||||
protected:
|
||||
virtual void charBounds(unsigned char c, int16_t *x, int16_t *y,
|
||||
int16_t *minx, int16_t *miny, int16_t *maxx,
|
||||
int16_t *maxy);
|
||||
void charBounds(unsigned char c, int16_t *x, int16_t *y, int16_t *minx,
|
||||
int16_t *miny, int16_t *maxx, int16_t *maxy);
|
||||
int16_t WIDTH; ///< This is the 'raw' display width - never changes
|
||||
int16_t HEIGHT; ///< This is the 'raw' display height - never changes
|
||||
int16_t _width; ///< Display width as modified by current rotation
|
||||
|
||||
Reference in new issue
Block a user