Skip to content

Commit 542513f

Browse files
author
Clang Robot
committed
Committing clang-format changes
1 parent 7f0e95e commit 542513f

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed

src/include/Graphics.cpp

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -277,99 +277,105 @@ int16_t Graphics::height()
277277
/**
278278
* @brief Draws a text box with optional border and word-wrapped content
279279
*
280-
* @param int16_t x0
280+
* @param int16_t x0
281281
* Top-left x-coordinate of the text box
282-
* @param int16_t y0
282+
* @param int16_t y0
283283
* Top-left y-coordinate of the text box
284-
* @param int16_t x1
284+
* @param int16_t x1
285285
* Bottom-right x-coordinate of the text box
286-
* @param int16_t y1
286+
* @param int16_t y1
287287
* Bottom-right y-coordinate of the text box
288-
* @param const char* text
288+
* @param const char* text
289289
* The null-terminated string to be rendered inside the box
290-
* @param uint16_t textSizeMultiplier
290+
* @param uint16_t textSizeMultiplier
291291
* Size multiplier for the text
292-
* @param const GFXfont* font
292+
* @param const GFXfont* font
293293
* Pointer to the font to use for rendering the text
294-
* @param uint16_t verticalSpacing
294+
* @param uint16_t verticalSpacing
295295
* Vertical spacing (in pixels) between lines of text; if 0 or NULL, defaults to text height + padding
296-
* @param bool showBorder
296+
* @param bool showBorder
297297
* Whether to draw a border around the text box
298-
* @param uint16_t fontSize
298+
* @param uint16_t fontSize
299299
* Font size in points (pt)
300300
*
301301
* @details This function renders a block of text inside the defined rectangular area.
302302
* It automatically wraps words to the next line if they exceed the available width.
303303
* If the text does not fit entirely, an ellipsis ("...") is added to the final visible line.
304304
* Text is padded with spaces to keep a consistent line length.
305305
*/
306-
void Graphics::drawTextBox(int16_t x0,int16_t y0,int16_t x1,int16_t y1, const char* text,uint16_t textSizeMultiplier, const GFXfont *font, uint16_t verticalSpacing, bool showBorder, uint16_t fontSize )
306+
void Graphics::drawTextBox(int16_t x0, int16_t y0, int16_t x1, int16_t y1, const char *text,
307+
uint16_t textSizeMultiplier, const GFXfont *font, uint16_t verticalSpacing, bool showBorder,
308+
uint16_t fontSize)
307309
{
308310
int16_t currentX = x0;
309311
int16_t currentY = y0;
310312

311-
int16_t textLenght=strlen(text);
312-
int offset=0;
313-
fontSize=(fontSize*3)/4; //1pt = 4/3 px
314-
int numOfCharactersPerLine=(x1-x0)/(textSizeMultiplier*fontSize);
315-
int16_t currentLineLenght=numOfCharactersPerLine;
313+
int16_t textLenght = strlen(text);
314+
int offset = 0;
315+
fontSize = (fontSize * 3) / 4; // 1pt = 4/3 px
316+
int numOfCharactersPerLine = (x1 - x0) / (textSizeMultiplier * fontSize);
317+
int16_t currentLineLenght = numOfCharactersPerLine;
316318
this->setTextSize(textSizeMultiplier);
317319
this->setFont(font);
318-
if(showBorder)
320+
if (showBorder)
319321
{
320-
this->drawRect(x0,y0,(x1-x0),(y1-y0),1);
322+
this->drawRect(x0, y0, (x1 - x0), (y1 - y0), 1);
321323
}
322-
if(verticalSpacing==NULL)
324+
if (verticalSpacing == NULL)
323325
{
324-
verticalSpacing=textSizeMultiplier*fontSize+6;
326+
verticalSpacing = textSizeMultiplier * fontSize + 6;
325327
}
326328
for (int i = y0; i < (y1 - verticalSpacing); i += verticalSpacing)
327329
{
328330
currentY = i;
329331
this->setCursor(currentX, currentY);
330-
332+
331333
int remainingLength = textLenght - offset;
332334
int lineLength = (remainingLength < currentLineLenght) ? remainingLength : currentLineLenght;
333-
335+
334336
// Temporary buffer to hold potential line
335-
char* buffer = (char*)malloc((lineLength + 1) * sizeof(char));
337+
char *buffer = (char *)malloc((lineLength + 1) * sizeof(char));
336338
memcpy(buffer, text + offset, lineLength);
337339
buffer[lineLength] = '\0';
338-
340+
339341
// Find the last space in buffer to wrap at word boundary
340342
int lastSpaceIndex = -1;
341-
for (int j = 0; j < lineLength; ++j) {
342-
if (buffer[j] == ' ') lastSpaceIndex = j;
343+
for (int j = 0; j < lineLength; ++j)
344+
{
345+
if (buffer[j] == ' ')
346+
lastSpaceIndex = j;
343347
}
344-
348+
345349
// If a word gets cut, wrap to the next line
346-
if ((offset + lineLength < textLenght) && (text[offset + lineLength] != ' ') && (lastSpaceIndex != -1) && ((i + verticalSpacing) < (y1 - verticalSpacing))) {
350+
if ((offset + lineLength < textLenght) && (text[offset + lineLength] != ' ') && (lastSpaceIndex != -1) &&
351+
((i + verticalSpacing) < (y1 - verticalSpacing)))
352+
{
347353
lineLength = lastSpaceIndex + 1; // Include the space
348354
}
349-
355+
350356
// Allocate space for actual line with null-terminator
351-
char* textPart = (char*)malloc((currentLineLenght + 1) * sizeof(char));
352-
memset(textPart, ' ', currentLineLenght); // Fill with spaces
357+
char *textPart = (char *)malloc((currentLineLenght + 1) * sizeof(char));
358+
memset(textPart, ' ', currentLineLenght); // Fill with spaces
353359
memcpy(textPart, text + offset, lineLength); // Copy valid part
354360
textPart[currentLineLenght] = '\0';
355-
361+
356362
// Ellipsis on final visible line
357-
if ((i + verticalSpacing) >= (y1 - verticalSpacing) && (offset + lineLength < textLenght)) {
363+
if ((i + verticalSpacing) >= (y1 - verticalSpacing) && (offset + lineLength < textLenght))
364+
{
358365

359366

360367
textPart[currentLineLenght - 1] = '.';
361368
textPart[currentLineLenght - 2] = '.';
362369
textPart[currentLineLenght - 3] = '.';
363370
}
364-
371+
365372
this->print(textPart);
366-
373+
367374
offset += lineLength;
368375
free(buffer);
369376
free(textPart);
370-
371-
if (offset >= textLenght) return;
372-
}
373-
374377

378+
if (offset >= textLenght)
379+
return;
380+
}
375381
}

src/include/Graphics.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class Graphics : public Shapes, public Image
5555
uint8_t getRotation();
5656

5757
void drawPixel(int16_t x, int16_t y, uint16_t color) override;
58-
void 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=NULL, bool showBorder=false, uint16_t fontSize=8 );
58+
void drawTextBox(int16_t x0, int16_t y0, int16_t x1, int16_t x2, const char *text, uint16_t textSize = 1,
59+
const GFXfont *font = NULL, uint16_t vericalSpacing = NULL, bool showBorder = false,
60+
uint16_t fontSize = 8);
5961

6062
#if !defined(ARDUINO_INKPLATECOLOR) && !defined(ARDUINO_INKPLATE2) && !defined(ARDUINO_INKPLATE4) && \
6163
!defined(ARDUINO_INKPLATE7)

0 commit comments

Comments
 (0)