Skip to main content

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​

Select Board
Inkplate7SPECTRA_TextBox.ino
#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 None

Creates 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 void

Initializes the library, the peripherals and the frame buffer. Call it once in setup().

ReturnsNothing.

display.clearDisplay()returns void

Fills the frame buffer with white. It does not change the panel.

ReturnsNothing.

display.setTextColor(uint16_t c)returns void

Sets 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 void

Draws 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

TypeNameDescription
int16_tx0, y0Upper-left corner of the box.
int16_tx1, x2x1 is the x coordinate and x2 the y coordinate of the bottom-right corner.
const char *textThe text to show.
uint16_ttextSizeFactor by which the font is enlarged. Defaults to 1.
const GFXfont *fontAddress of a custom font. Defaults to NULL, the built-in font.
uint16_tvericalSpacingPixels between rows of text. Defaults to 0.
boolshowBorderDraw a visible rectangle around the box. Defaults to false.
uint16_tfontSizeSize of the used font in pt. Defaults to 8.
display.display(bool _leaveOn = 0)returns void

Sends 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

→