Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Widgets/TextWidget.cpp
- Committer:
- duncanFrance
- Date:
- 2016-03-27
- Revision:
- 3:cb004f59b715
- Parent:
- 2:bb9183379488
- Child:
- 4:27546fb8b670
File content as of revision 3:cb004f59b715:
#include "TextWidget.h" /** * 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) : Widget(display), _renderer(display) {} void TextWidget::setText(char* text) { _text = text; } void TextWidget::setFont(Font* font) { _font = font; } void TextWidget::draw() { _renderer.clip(_x, _y, _width, _height); char c; char *p = _text; while(*p != NULL) { c = *p; p++; _renderer.putc(c, _font, _fg, _bg); } _display->copy_to_lcd(); } /** void TextWidget::draw() { int right = _x + _width; // right side of clipping window int bottom = _y + _height; // bottom edge of clipping window int _cx = _x; // Start drawing characters at top left int _cy = _y; char c; char *p = _text; _display->foreground(_fg); _display->background(_bg); _display->set_font(_font->_font); while(*p != NULL) { c = *p; p++; if(c=='\n') { _cy = _cy + _font->_height; _cx = _x; } else { // Only draw the character if it is not clipped if( (_cx+_font->_width) < right && (_cy +_font->_height) < bottom) { _display->character(_cx, _cy, c); _cx += _font->widthOf(c); } } } } **/ bool TextWidget::isEventTarget(Event e) { return e.screenX < (_x+_width) && _x <= e.screenX && e.screenY < (_y+_height) && _y <= e.screenY; }