CheeseBoard
A library for use with the CheeseBoard Cheddar platform
GfxTextBox.cpp
1 #include <MutilaDebug.h>
2 #include "GfxTextBox.h"
3 #include "CbOledDisplay.h"
4 
5 GfxTextBox::GfxTextBox(uint16_t width, String text, bool border) :
6  _width(width),
7  _text(text),
8  _border(border)
9 {
10 }
11 
12 void GfxTextBox::draw(uint16_t xOffset, uint16_t yOffset) {
13  _DBF("GfxText draw@%d,%d : text=%s\n", xOffset, yOffset, _text.c_str());
14  CbOledDisplay.setFont(CBOLED_MESSAGE_FONT);
15  uint16_t strLenPixels;
16  uint16_t useLen = _text.length();
17 
18  do {
19  strLenPixels = CbOledDisplay.getStrWidth(_text.substring(0, useLen).c_str());
20  strLenPixels + 4 > _width && useLen > 0;
21  } while (strLenPixels + 2 > _width && useLen-- > 0);
22  CbOledDisplay.drawStr(xOffset+2,
23  yOffset+CBOLED_MESSAGE_FONT_VSEP+CBOLED_MESSAGE_FONT_HEIGHT,
24  _text.substring(0, useLen).c_str());
25  if (_border) {
26  CbOledDisplay.drawFrame(xOffset,
27  yOffset,
28  width(),
29  height());
30  }
31 }
32 
34 {
35  return _width;
36 }
37 
38 uint16_t GfxTextBox::height() {
39  return CBOLED_MESSAGE_FONT_HEIGHT + (2*CBOLED_MESSAGE_FONT_VSEP);
40 }
41 
uint16_t width()
Definition: GfxTextBox.cpp:33
uint16_t height()
Definition: GfxTextBox.cpp:38
void draw(uint16_t xOffset=0, uint16_t yOffset=0)
Definition: GfxTextBox.cpp:12