Text box
What this example shows
Write a paragraph inside a rectangle with drawTextBox(). The text wraps to the next row when a word does not fit, and, as the sketch's own text says, if it reaches the lower edge of the box it ends with three dots. The sketch draws two boxes with the same text: one with only the required parameters, and one with all of them, using the custom font Roboto_Light_36 from the Roboto_Light_36.h file in the example folder.
Example code
#include "Inkplate.h" //Include Inkplate library to the sketch
#include "Roboto_Light_36.h"
Inkplate display; // Create an object on Inkplate library and also set library into 1 Bit mode (BW)
// Define the text you will show in the text box
const char* text="This is an example of a text written in a textbox. When a word doesn't fit into the current row, it goes to the next one."\
" If the text reaches the lower bound, it ends with three dots (...) to mark that the text isnt displayed fully";
void setup()
{
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
display.clearDisplay(); // Clear frame buffer of display
display.setTextColor(INKPLATE_BLACK); //Set the text color to black
// Create a text box without any optional parameters
// x0- x coordinate of upper left corner
// y0- y coordinate of upper left corner
// x1- x coordinate of bottom right corner
// y1- y coordinate of bottom right corner
// text - text we want to display
display.drawTextBox(50,50,400,430,text,1);
// Create a text box with all parameters
// x0- x coordinate of upper left corner
// y0- y coordinate of upper left corner
// x1- x coordinate of bottom right corner
// y1- y coordinate of bottom right corner
// text - text we want to display
// textSizeMultiplier - by what factor we want to enlarge the size of a font
// font - address of selected custom font
// verticalSpacing - how many pixels between each row of text
// showBorder - Create a visible rectangle around the box
// fontSize - size of the used font in pt
int offset=32; // Note - some custom fonts are drawn from bottom-to-top which requires an offset, use an offset that best suits the font you use
display.drawTextBox(450,50+offset,750,250,text,1,&Roboto_Light_36,27,false,36);
// Display both text boxes
display.display();
}
void loop()
{
// Nothing...
}
The comment next to Inkplate display; mentions a 1-bit mode; Inkplate 7SPECTRA has only its six-color mode, and the constructor takes no mode.
Functions used
Inkplate()returns NoneCreates the Inkplate object. Inkplate 7SPECTRA has a single six-color mode, so the constructor takes no mode argument.
ReturnsConstructor; no return value.
display.begin()returns voidInitializes the library, the peripherals and the frame buffer. Call it once in setup().
ReturnsNothing.
display.clearDisplay()returns voidFills the frame buffer with white. It does not change the panel.
ReturnsNothing.
display.setTextColor(uint16_t c)returns voidSets the text color, here INKPLATE_BLACK.
ReturnsNothing.
display.drawTextBox(int16_t x0, int16_t y0, int16_t x1, int16_t x2, const char *text, uint16_t textSize = 1, const GFXfont *font = NULL, uint16_t vericalSpacing = 0, bool showBorder = false, uint16_t fontSize = 8)returns voidDraws the text inside the rectangle into the frame buffer, wrapping it at the box edge. The library declares the parameters with these names; the fourth, x2, is the y coordinate of the bottom-right corner, as the sketch's comments say.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int16_t | x0, y0 | Upper-left corner of the box. |
int16_t | x1, x2 | x1 is the x coordinate and x2 the y coordinate of the bottom-right corner. |
const char * | text | The text to show. |
uint16_t | textSize | Factor by which the font is enlarged. Defaults to 1. |
const GFXfont * | font | Address of a custom font. Defaults to NULL, the built-in font. |
uint16_t | vericalSpacing | Pixels between rows of text. Defaults to 0. |
bool | showBorder | Draw a visible rectangle around the box. Defaults to false. |
uint16_t | fontSize | Size of the used font in pt. Defaults to 8. |
display.display(bool _leaveOn = 0)returns voidSends the whole frame buffer to the panel and refreshes it. Both boxes appear at once.
ReturnsNothing.
What to expect
The screen shows two boxes of text, both reading "This is an example of a text written in a textbox...". The left one, in the built-in font, fills the area from (50, 50) to (400, 430). The right one is drawn in Roboto Light at 36 pt from (450, 82) to (750, 250), with no border. The sketch prints nothing to the Serial Monitor.
🔗Open the complete example
examples/Inkplate7SPECTRA/Advanced/Other/Inkplate7SPECTRA_TextBox