Foundation classes for a basic GUI implementing simple widgets and events

Dependents:   TouchScreenGUIDemo

Revision:
17:5184762fda6c
Parent:
16:e9a771ecfdbe
Child:
18:d849f3ada858
--- a/Widgets/TextWidget.cpp	Sun May 22 14:40:29 2016 +0000
+++ b/Widgets/TextWidget.cpp	Sun May 22 16:35:23 2016 +0000
@@ -40,6 +40,10 @@
     dirty();
 }
 
+Font *TextWidget::getFont() {
+    return _font;
+}
+
 void TextWidget::setHAlign(HAlign alignment) {
     _halign = alignment;
     dirty();
@@ -54,6 +58,18 @@
 {
     Widget::_draw();
     
+    /**
+    * Figure out how many lines of text we have
+    **/
+    int numLines = 1;
+    char *c = _text;
+    while(*c != NULL) {
+        if(*c == '\n') {
+            numLines++;
+        }
+        c++;
+    }
+    
     /******************************************************************/
     /*   ---------------------------------            ^               */
     /*   |                               |            |               */
@@ -68,20 +84,21 @@
     /**
     * We need a window as high as the font with it's origin:
     * VALIGN=TOP    : (0, 0)
-    * VALIGN=MIDDLE : (0, inner.height/2 - font.height/2)
-    * VALIGN=BOTTOM : (0, inner.height - font.height)
+    * VALIGN=MIDDLE : (0, inner.height/2 - numLines * font.height/2)
+    * VALIGN=BOTTOM : (0, inner.height   - numLines * font.height)
     **/
     int t=0;
     switch(_valign) {
         case TOP:    t = 0; break;
-        case MIDDLE: t = (_inner.height - _font->zoomedHeight())/2; break;
-        case BOTTOM: t = (_inner.height - _font->zoomedHeight()); break;
+        case MIDDLE: t = (_inner.height - (numLines * _font->zoomedHeight()))/2; break;
+        case BOTTOM: t = (_inner.height - (numLines * _font->zoomedHeight())); break;
     }
     
     _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->puts(_text, display(), _font);
     display()->copy_to_lcd();