Skip to content

Commit a107afe

Browse files
committed
add text block class
1 parent 3f486e0 commit a107afe

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

src/AdafruitIO_Dashboard.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ GaugeBlock* AdafruitIO_Dashboard::addGaugeBlock(AdafruitIO_Feed *feed)
7878
{
7979
return new GaugeBlock(this, feed);
8080
}
81+
82+
TextBlock* AdafruitIO_Dashboard::addTextBlock(AdafruitIO_Feed *feed)
83+
{
84+
return new TextBlock(this, feed);
85+
}

src/AdafruitIO_Dashboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "blocks/MomentaryBlock.h"
1919
#include "blocks/SliderBlock.h"
2020
#include "blocks/GaugeBlock.h"
21+
#include "blocks/TextBlock.h"
2122

2223
// forward declaration
2324
class AdafruitIO;
@@ -38,6 +39,7 @@ class AdafruitIO_Dashboard {
3839
MomentaryBlock* addMomentaryBlock(AdafruitIO_Feed *feed);
3940
SliderBlock* addSliderBlock(AdafruitIO_Feed *feed);
4041
GaugeBlock* addGaugeBlock(AdafruitIO_Feed *feed);
42+
TextBlock* addTextBlock(AdafruitIO_Feed *feed);
4143

4244
private:
4345
AdafruitIO *_io;

src/blocks/TextBlock.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Tony DiCola, Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#include "TextBlock.h"
13+
14+
TextBlock::TextBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f)
15+
{
16+
fontSize = "SMALL";
17+
}
18+
19+
TextBlock::~TextBlock(){}
20+
21+
String TextBlock::properties()
22+
{
23+
int s = 0;
24+
25+
if(fontSize == "SMALL") {
26+
s = 12;
27+
} else if(fontSize == "MEDIUM") {
28+
s = 18;
29+
} else {
30+
s = 24;
31+
}
32+
33+
String props = "{\"fontSize\":\"";
34+
props += s;
35+
props += "\"}";
36+
37+
return props;
38+
}

src/blocks/TextBlock.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Tony DiCola, Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#ifndef ADAFRUITIO_TEXTBLOCK_H
13+
#define ADAFRUITIO_TEXTBLOCK_H
14+
15+
#include "AdafruitIO_Block.h"
16+
17+
class TextBlock : public AdafruitIO_Block {
18+
19+
public:
20+
TextBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
21+
~TextBlock();
22+
23+
const char *fontSize;
24+
25+
String properties();
26+
27+
private:
28+
const char *_visual_type = "text";
29+
30+
};
31+
32+
#endif // ADAFRUITIO_TEXTBLOCK_H

0 commit comments

Comments
 (0)