Skip to content

Commit

Permalink
added stopLine for Rfont_text_width
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Apr 2, 2024
1 parent 93e8576 commit 8b5475c
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions RFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ inline void RFont_font_add_string_len(RFont_font* font, const char* string, size
*/
inline size_t RFont_text_width(RFont_font* font, const char* text, u32 size);

/**
* @brief Get the width of a specific line of the text based on the size using the font, using a given length.
* @param font The font stucture to use for drawing
* @param text The string to draw
* @param size The size of the text
* @param spacing The spacing of the text
* @param stopLine The line to stop at (starting at 1, 0 = don't stop until the last line)
* @return The width of the text based on the size
*/
size_t RFont_text_line_width(RFont_font* font, const char* text, u32 size, size_t stopLine);

/**
* @brief Get the width of the text based on the size using the font, using a given length.
* @param font The font stucture to use for drawing
Expand All @@ -252,10 +263,11 @@ inline size_t RFont_text_width_spacing(RFont_font* font, const char* text, float
* @param text The string to draw
* @param len The length of the string
* @param size The size of the text
* @param stopLine The line to stop at (starting at 1, 0 = don't stop until the last line)
* @param spacing The spacing of the text
* @return The width of the text based on the size
*/
inline size_t RFont_text_width_len(RFont_font* font, const char* text, size_t len, u32 size, float spacing);
inline size_t RFont_text_width_len(RFont_font* font, const char* text, size_t len, u32 size, size_t stopLine, float spacing);

/**
* @brief Draw a text string using the font.
Expand Down Expand Up @@ -624,21 +636,30 @@ RFont_glyph RFont_font_add_char(RFont_font* font, char ch, size_t size) {
}

size_t RFont_text_width(RFont_font* font, const char* text, u32 size) {
return RFont_text_width_len(font, text, 0, size, 0.0f);
return RFont_text_width_len(font, text, 0, size, 0, 0.0f);
}

size_t RFont_text_line_width(RFont_font* font, const char* text, u32 size, size_t stopLine) {
return RFont_text_width_len(font, text, 0, size, stopLine, 0.0f);
}

size_t RFont_text_width_spacing(RFont_font* font, const char* text, float spacing, u32 size) {
return RFont_text_width_len(font, text, 0, size, spacing);
return RFont_text_width_len(font, text, 0, size, 0, spacing);
}

size_t RFont_text_width_len(RFont_font* font, const char* text, size_t len, u32 size, float spacing) {
size_t RFont_text_width_len(RFont_font* font, const char* text, size_t len, u32 size, size_t stopLine, float spacing) {
float x = 0;

char* str;

size_t y = 1;

for (str = (char*)text; (len == 0 || (size_t)(str - text) < len) && *str; str++) {
if (*str == '\n') {
if (y == stopLine)
break;

x = 0;
y++;
continue;
}

Expand Down

0 comments on commit 8b5475c

Please sign in to comment.