Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Diff: Widgets/TextWidget.cpp
- Revision:
- 8:a460cabc85ac
- Parent:
- 7:303850a4b30c
- Child:
- 9:616a9686d5db
--- a/Widgets/TextWidget.cpp Sun Apr 10 16:48:44 2016 +0000 +++ b/Widgets/TextWidget.cpp Mon Apr 11 16:54:02 2016 +0000 @@ -4,9 +4,24 @@ * A basic widget implementation which just draws some text. * If the text does not fit in the bounding-box it will be clipped **/ -TextWidget::TextWidget(GraphicsDisplay& display, FontRenderer* renderer) : - Widget(display), - _renderer(renderer) +TextWidget::TextWidget(GUI* gui) : + Widget(gui), + _renderer(gui->fontRenderer()), + _font(gui->defaultFont()) +{ +} + +TextWidget::TextWidget(GUI* gui, FontRenderer* renderer) : + Widget(gui), + _renderer(renderer), + _font(gui->defaultFont()) +{ +} + +TextWidget::TextWidget(GUI* gui, FontRenderer* renderer, Font* font) : + Widget(gui), + _renderer(renderer), + _font(font) { } @@ -21,21 +36,24 @@ } -void TextWidget::draw() +void TextWidget::_draw() { _renderer->window(_x, _y, _width, _height, false); _renderer->setForeground(_fg); _renderer->setBackground(_bg); - _renderer->setFont(_font); - + char c; char *p = _text; while(*p != NULL) { c = *p; p++; - _renderer->putc(c, _display); + _renderer->putc(c, _gui->display(), _font); } - _display.copy_to_lcd(); + _gui->display()->copy_to_lcd(); } + +void TextWidget::_clear() { + _gui->display()->fillrect(_x, _y, _x+_width, _y+_height, _bg); +} \ No newline at end of file