Foundation classes for a basic GUI implementing simple widgets and events. (Fork for custom changes.)
Fork of SimpleGUI by
Diff: Widgets/TextWidget.cpp
- Revision:
- 18:d849f3ada858
- Parent:
- 17:5184762fda6c
- Child:
- 20:ef07d42ea062
--- a/Widgets/TextWidget.cpp Sun May 22 16:35:23 2016 +0000 +++ b/Widgets/TextWidget.cpp Sat May 28 14:50:14 2016 +0000 @@ -87,19 +87,24 @@ * VALIGN=MIDDLE : (0, inner.height/2 - numLines * font.height/2) * VALIGN=BOTTOM : (0, inner.height - numLines * font.height) **/ - int t=0; + int offset=0; switch(_valign) { - case TOP: t = 0; break; - case MIDDLE: t = (_inner.height - (numLines * _font->zoomedHeight()))/2; break; - case BOTTOM: t = (_inner.height - (numLines * _font->zoomedHeight())); break; + case TOP: offset = 0; break; + case MIDDLE: offset = (_inner.height - (numLines * _font->zoomedHeight()))/2; break; + case BOTTOM: offset = (_inner.height - (numLines * _font->zoomedHeight())); break; + } + + _renderer->setForeground(_fg); + _renderer->setBackground(_bg); + + // Renderer window is only high enough for the number of lines to draw. + int h = _font->zoomedHeight() * numLines; + // Clip to fit within the TextWidget inner + if((h + offset) > _inner.height) { + h = _inner.height - offset; } - _renderer->window(_inner.x, _inner.y + t, _inner.width, _font->zoomedHeight(), false); - _renderer->setForeground(_fg); - _renderer->setBackground(_bg); - display()->fillrect(_inner.x, _inner.y, _inner.x+_inner.width, _inner.y+_inner.height, _bg); - display()->rect(_inner.x, _inner.y, _inner.x+_inner.width, _inner.y+_inner.height, Red); - + _renderer->window(_inner.x, _inner.y + offset, _inner.width, h, false); _renderer->puts(_text, display(), _font); display()->copy_to_lcd(); } \ No newline at end of file