DrawTextBoxed fix.
This commit is contained in:
4
API.md
4
API.md
@@ -8023,7 +8023,7 @@ Draw multiple character (codepoint)
|
||||
|
||||
---
|
||||
|
||||
> mouseCharId, textOffset = RL.DrawTextBoxed(Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight )
|
||||
> mouseCharId, textOffset = RL.DrawTextBoxed(Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight, int|nil tabSize )
|
||||
|
||||
Draw text using font inside rectangle limits.
|
||||
|
||||
@@ -8031,7 +8031,7 @@ Draw text using font inside rectangle limits.
|
||||
|
||||
---
|
||||
|
||||
> mouseCharId, textOffset = RL.DrawTextBoxedEx( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2 textOffset )
|
||||
> mouseCharId, textOffset = RL.DrawTextBoxedEx( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2 textOffset, int|nil tabSize )
|
||||
|
||||
Draw text using font inside rectangle limits. Return character id from mouse position (default 0).
|
||||
textOffset can be used to set start position inside rectangle. Usefull to pass from previous
|
||||
|
||||
@@ -4538,9 +4538,10 @@ function RL.DrawTextCodepoints( font, codepoints, position, fontSize, spacing,
|
||||
---@param wordWrap boolean
|
||||
---@param tint table
|
||||
---@param limitHeight boolean
|
||||
---@param tabSize integer|nil
|
||||
---@return any mouseCharId
|
||||
---@return any textOffset
|
||||
function RL.DrawTextBoxed( font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight ) end
|
||||
function RL.DrawTextBoxed( font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, tabSize ) end
|
||||
|
||||
---Draw text using font inside rectangle limits. Return character id from mouse position (default 0).
|
||||
---textOffset can be used to set start position inside rectangle. Usefull to pass from previous
|
||||
@@ -4555,9 +4556,10 @@ function RL.DrawTextBoxed( font, text, rec, fontSize, spacing, wordWrap, tint, l
|
||||
---@param tint table
|
||||
---@param limitHeight boolean
|
||||
---@param textOffset table
|
||||
---@param tabSize integer|nil
|
||||
---@return any mouseCharId
|
||||
---@return any textOffset
|
||||
function RL.DrawTextBoxedEx( font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, textOffset ) end
|
||||
function RL.DrawTextBoxedEx( font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, textOffset, tabSize ) end
|
||||
|
||||
-- Text - Text font info functions
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ DETAILED CHANGES:
|
||||
- ADDED: Fast tilemap example.
|
||||
- ADDED: RectPack using stbrp_pack_rects. Atlas packer tutorial.
|
||||
- ADDED: SetImageData.
|
||||
- FIXED: DrawTextBoxed Could draw text outside rect when using special characters.
|
||||
Also accepts optional tabSize argument.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
|
||||
|
||||
1
devnotes
1
devnotes
@@ -1,5 +1,4 @@
|
||||
Current {
|
||||
* Check if DrawTextBoxedEx works correctly.
|
||||
}
|
||||
|
||||
Backlog {
|
||||
|
||||
28
src/text.c
28
src/text.c
@@ -25,14 +25,12 @@ static float measureWord( Font font, char* text, float fontSize, float spacing )
|
||||
}
|
||||
|
||||
static int DrawTextBoxed( Font font, char* text, Rectangle rec, float fontSize,
|
||||
float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset ) {
|
||||
const int tabSize = 4; /* How many spaces. */
|
||||
float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset, int tabSize ) {
|
||||
int lineSpacing = state->lineSpacing;
|
||||
|
||||
if ( rec.width <= 0 || ( rec.height <= limitHeight ? ( textOffset->y + lineSpacing ) : 0 ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int len = TextLength( text );
|
||||
float scaleFactor = fontSize / font.baseSize;
|
||||
float wordWidth = 0.0;
|
||||
@@ -52,6 +50,10 @@ float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset
|
||||
if ( codepoint == '\n' ) {
|
||||
textOffset->x = 0;
|
||||
textOffset->y += lineSpacing;
|
||||
measure = true;
|
||||
}
|
||||
else if ( codepoint == '\t' ) {
|
||||
measure = true;
|
||||
}
|
||||
else if ( wordWrap && ( wordWidth < rec.width ) ) {
|
||||
if ( measure && codepoint != ' ' ) {
|
||||
@@ -63,7 +65,7 @@ float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset
|
||||
textOffset->y += lineSpacing;
|
||||
}
|
||||
}
|
||||
else if ( codepoint == ' ' || codepoint == '\n' || codepoint == '\t' ) {
|
||||
else if ( codepoint == ' ' ) {
|
||||
measure = true;
|
||||
}
|
||||
}
|
||||
@@ -533,7 +535,7 @@ int ltextDrawTextCodepoints( lua_State* L ) {
|
||||
}
|
||||
|
||||
/*
|
||||
> mouseCharId, textOffset = RL.DrawTextBoxed(Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight )
|
||||
> mouseCharId, textOffset = RL.DrawTextBoxed(Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight, int|nil tabSize )
|
||||
|
||||
Draw text using font inside rectangle limits.
|
||||
|
||||
@@ -549,15 +551,19 @@ int ltextDrawTextBoxed( lua_State* L ) {
|
||||
Color tint = uluaGetColor( L, 7 );
|
||||
bool limitHeight = uluaGetBoolean( L, 8 );
|
||||
Vector2 textOffset = { 0, 0 };
|
||||
|
||||
lua_pushinteger( L, DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, &textOffset ) );
|
||||
int tabSize = 4;
|
||||
|
||||
if ( !lua_isnil( L, 9 ) && !lua_isnone( L, 9 ) ) {
|
||||
tabSize = luaL_checkinteger( L, 9 );
|
||||
}
|
||||
lua_pushinteger( L, DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, &textOffset, tabSize ) );
|
||||
uluaPushVector2( L, textOffset );
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
> mouseCharId, textOffset = RL.DrawTextBoxedEx( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2 textOffset )
|
||||
> mouseCharId, textOffset = RL.DrawTextBoxedEx( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2 textOffset, int|nil tabSize )
|
||||
|
||||
Draw text using font inside rectangle limits. Return character id from mouse position (default 0).
|
||||
textOffset can be used to set start position inside rectangle. Usefull to pass from previous
|
||||
@@ -575,8 +581,12 @@ int ltextDrawTextBoxedEx( lua_State* L ) {
|
||||
Color tint = uluaGetColor( L, 7 );
|
||||
bool limitHeight = uluaGetBoolean( L, 8 );
|
||||
Vector2 textOffset = uluaGetVector2( L, 9 );
|
||||
int tabSize = 4;
|
||||
|
||||
lua_pushinteger( L, DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, &textOffset ) );
|
||||
if ( !lua_isnil( L, 10 ) && !lua_isnone( L, 10 ) ) {
|
||||
tabSize = luaL_checkinteger( L, 10 );
|
||||
}
|
||||
lua_pushinteger( L, DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, &textOffset, tabSize ) );
|
||||
uluaPushVector2( L, textOffset );
|
||||
|
||||
return 2;
|
||||
|
||||
Reference in New Issue
Block a user