Skip to main content

Okvir za tekst

Što ovaj primjer prikazuje​

Napišite odlomak unutar pravokutnika pomoću drawTextBox(). Tekst se prelama u sljedeći red kada se riječ ne uklapa, a ako, kako stoji u tekstu samog programa, dosegne donji rub okvira, završava s tri točke. Program crta dva okvira s istim tekstom: jedan sa samo obaveznim parametrima i jedan sa svim parametrima, koji koristi prilagođeni font Roboto_Light_36 iz datoteke Roboto_Light_36.h u mapi primjera.

Kod primjera​

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...
}

Komentar pokraj Inkplate display; spominje 1-bitni način rada; Inkplate 7SPECTRA ima samo svoj šesterobojni način rada, a konstruktor ne prima način rada.

Korištene funkcije​

Inkplate()returns None

Stvara objekt Inkplate. Inkplate 7SPECTRA ima jedan šesterobojni način rada, pa konstruktor ne prima argument načina rada.

ReturnsKonstruktor; nema povratne vrijednosti.

display.begin()returns void

Inicijalizira biblioteku, periferne jedinice i međuspremnik slike. Pozovite je jednom u setup().

ReturnsNišta.

display.clearDisplay()returns void

Ispunjava međuspremnik slike bijelom bojom. Ne mijenja zaslon.

ReturnsNišta.

display.setTextColor(uint16_t c)returns void

Postavlja boju teksta, ovdje INKPLATE_BLACK.

ReturnsNišta.

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

Crta tekst unutar pravokutnika u međuspremnik slike i prelama ga na rubu okvira. Biblioteka deklarira parametre s ovim nazivima; četvrti, x2, je y koordinata donjeg desnog kuta, kako stoji u komentarima programa.

ReturnsNišta.

Parametri

TipNazivOpis
int16_tx0, y0Gornji lijevi kut okvira.
int16_tx1, x2x1 je x koordinata, a x2 y koordinata donjeg desnog kuta.
const char *textTekst koji se prikazuje.
uint16_ttextSizeFaktor povećanja fonta. Zadano je 1.
const GFXfont *fontAdresa prilagođenog fonta. Zadano je NULL, ugrađeni font.
uint16_tvericalSpacingBroj piksela između redova teksta. Zadano je 0.
boolshowBorderCrta vidljiv pravokutnik oko okvira. Zadano je false.
uint16_tfontSizeVeličina korištenog fonta u pt. Zadano je 8.
display.display(bool _leaveOn = 0)returns void

Šalje cijeli međuspremnik slike na zaslon i osvježava ga. Oba okvira pojavljuju se odjednom.

ReturnsNišta.

Što očekivati​

Na zaslonu se prikazuju dva okvira s tekstom, oba s natpisom "This is an example of a text written in a textbox...". Lijevi, u ugrađenom fontu, ispunjava područje od (50, 50) do (400, 430). Desni je ispisan fontom Roboto Light veličine 36 pt od (450, 82) do (750, 250), bez obruba. Program ništa ne ispisuje u Serial Monitor.

🔗Otvorite cijeli primjer

examples/Inkplate7SPECTRA/Advanced/Other/Inkplate7SPECTRA_TextBox

→