Text box
What this example shows
Writing a paragraph inside a rectangle with drawTextBox(). The first box uses the default font, and the second uses a custom font, a row spacing and a font size.
Example code
The listing is the .ino file from the library example. The sketch also needs the font header Roboto_Light_36.h from the same folder, so open the source link below and keep both files together in your sketch folder.
#include "Inkplate.h" // Include Inkplate library to the sketch
#include "Roboto_Light_36.h"
Inkplate display(INKPLATE_1BIT); // 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.display(); // Put clear image on display
// Create a text box without any optional parameters
display.drawTextBox(100,100,300,300,text);
// Create a text box with all parameters
// Some custom fonts are drawn from bottom-to-top, which requires an offset
int offset=32;
display.drawTextBox(400,100+offset,600,300,text,1,&Roboto_Light_36,27,false,36);
// Display both text boxes
display.display();
}
void loop()
{
// Nothing...
}
Functions used
Inkplate(uint8_t mode)returns NoneCreates the Inkplate object. The mode decides how many bits describe each pixel: `INKPLATE_1BIT` for black and white, `INKPLATE_3BIT` for grayscale.
ReturnsConstructor; no return value.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | mode | Display mode, INKPLATE_1BIT or INKPLATE_3BIT. |
display.begin()returns voidInitializes the display hardware. Call it once in `setup()` before you draw anything.
ReturnsNothing.
display.clearDisplay()returns voidClears the frame buffer in the ESP32 memory. It does not change what the panel currently shows; call `display()` for that.
ReturnsNothing.
display.display(bool _leaveOn = 0)returns voidSends the frame buffer to the panel with a full refresh.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _leaveOn | Optional. When true, the panel supply stays on after the refresh. Defaults to false. |
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 voidWrites text inside a rectangle. Words that do not fit move to the next row, and text that runs past the bottom ends with three dots.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int16_t | x0 | Upper left corner, x position. |
int16_t | y0 | Upper left corner, y position. |
int16_t | x1 | Bottom right corner, x position. |
int16_t | x2 | Bottom right corner, y position. The parameter is named x2 in the library declaration. |
const char * | text | The text to show. |
uint16_t | textSize | Magnification factor. Defaults to 1. |
const GFXfont * | font | Custom font. Defaults to the built-in font. |
uint16_t | vericalSpacing | Pixels between rows of text. The parameter is spelled this way in the library declaration. Defaults to 0. |
bool | showBorder | Draws a visible rectangle around the box. Defaults to false. |
uint16_t | fontSize | Font size in points. Defaults to 8. |
What to expect
The panel shows two text boxes side by side. The left one, from (100, 100) to (300, 300), uses the default font. The right one, from (400, 132) to (600, 300), uses the Roboto Light 36 font. Where the text does not fit the box, it ends with three dots. The example prints nothing to the Serial Monitor.