Textfeld
Was dieses Beispiel zeigt
Schreiben Sie mit drawTextBox() einen Absatz in ein Rechteck. Der Text wird in die nächste Zeile umgebrochen, wenn ein Wort nicht mehr passt, und endet mit drei Punkten, sobald er den unteren Rand des Textfelds erreicht, wie es der Text des Sketches selbst sagt. Der Sketch zeichnet zwei Textfelder mit demselben Text: eines nur mit den erforderlichen Parametern und eines mit allen Parametern, mit der benutzerdefinierten Schrift Roboto_Light_36 aus der Datei Roboto_Light_36.h im Beispielordner.
Beispielcode
#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...
}
Der Kommentar neben Inkplate display; erwähnt einen 1-Bit-Modus; Inkplate 7SPECTRA hat nur seinen Sechs-Farben-Modus, und der Konstruktor nimmt keinen Modus entgegen.
Verwendete Funktionen
Inkplate()returns NoneErstellt das Inkplate-Objekt. Inkplate 7SPECTRA hat einen einzigen Sechs-Farben-Modus, daher nimmt der Konstruktor kein Modus-Argument entgegen.
ReturnsKonstruktor; kein Rückgabewert.
display.begin()returns voidInitialisiert die Bibliothek, die Peripherie und den Framebuffer. Rufen Sie sie einmal in setup() auf.
ReturnsNichts.
display.clearDisplay()returns voidFüllt den Framebuffer mit Weiß. Das Panel wird dadurch nicht verändert.
ReturnsNichts.
display.setTextColor(uint16_t c)returns voidLegt die Textfarbe fest, hier INKPLATE_BLACK.
ReturnsNichts.
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 voidZeichnet den Text innerhalb des Rechtecks in den Framebuffer und bricht ihn am Rand des Textfelds um. Die Bibliothek deklariert die Parameter mit diesen Namen; der vierte, x2, ist die y-Koordinate der unteren rechten Ecke, wie die Kommentare des Sketches sagen.
ReturnsNichts.
Parameter
| Typ | Name | Beschreibung |
|---|---|---|
int16_t | x0, y0 | Obere linke Ecke des Textfelds. |
int16_t | x1, x2 | x1 ist die x-Koordinate und x2 die y-Koordinate der unteren rechten Ecke. |
const char * | text | Der anzuzeigende Text. |
uint16_t | textSize | Faktor, um den die Schrift vergrößert wird. Standardwert ist 1. |
const GFXfont * | font | Adresse einer benutzerdefinierten Schrift. Standardwert ist NULL, die integrierte Schrift. |
uint16_t | vericalSpacing | Pixel zwischen den Textzeilen. Standardwert ist 0. |
bool | showBorder | Zeichnet ein sichtbares Rechteck um das Textfeld. Standardwert ist false. |
uint16_t | fontSize | Größe der verwendeten Schrift in pt. Standardwert ist 8. |
display.display(bool _leaveOn = 0)returns voidSendet den gesamten Framebuffer an das Panel und aktualisiert es. Beide Textfelder erscheinen gleichzeitig.
ReturnsNichts.
Was Sie erwarten können
Auf dem Bildschirm erscheinen zwei Textfelder, die beide „This is an example of a text written in a textbox..." anzeigen. Das linke, in der integrierten Schrift, füllt den Bereich von (50, 50) bis (400, 430). Das rechte ist in Roboto Light mit 36 pt von (450, 82) bis (750, 250) gezeichnet, ohne Rahmen. Der Sketch gibt nichts im Serial Monitor aus.
🔗Vollständiges Beispiel öffnen
examples/Inkplate7SPECTRA/Advanced/Other/Inkplate7SPECTRA_TextBox