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.
|
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).
|
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
|
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 wordWrap boolean
|
||||||
---@param tint table
|
---@param tint table
|
||||||
---@param limitHeight boolean
|
---@param limitHeight boolean
|
||||||
|
---@param tabSize integer|nil
|
||||||
---@return any mouseCharId
|
---@return any mouseCharId
|
||||||
---@return any textOffset
|
---@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).
|
---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
|
---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 tint table
|
||||||
---@param limitHeight boolean
|
---@param limitHeight boolean
|
||||||
---@param textOffset table
|
---@param textOffset table
|
||||||
|
---@param tabSize integer|nil
|
||||||
---@return any mouseCharId
|
---@return any mouseCharId
|
||||||
---@return any textOffset
|
---@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
|
-- Text - Text font info functions
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ DETAILED CHANGES:
|
|||||||
- ADDED: Fast tilemap example.
|
- ADDED: Fast tilemap example.
|
||||||
- ADDED: RectPack using stbrp_pack_rects. Atlas packer tutorial.
|
- ADDED: RectPack using stbrp_pack_rects. Atlas packer tutorial.
|
||||||
- ADDED: SetImageData.
|
- 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
|
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
|
||||||
|
|||||||
1
devnotes
1
devnotes
@@ -1,5 +1,4 @@
|
|||||||
Current {
|
Current {
|
||||||
* Check if DrawTextBoxedEx works correctly.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Backlog {
|
Backlog {
|
||||||
|
|||||||
26
src/text.c
26
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,
|
static int DrawTextBoxed( Font font, char* text, Rectangle rec, float fontSize,
|
||||||
float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset ) {
|
float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset, int tabSize ) {
|
||||||
const int tabSize = 4; /* How many spaces. */
|
|
||||||
int lineSpacing = state->lineSpacing;
|
int lineSpacing = state->lineSpacing;
|
||||||
|
|
||||||
if ( rec.width <= 0 || ( rec.height <= limitHeight ? ( textOffset->y + lineSpacing ) : 0 ) ) {
|
if ( rec.width <= 0 || ( rec.height <= limitHeight ? ( textOffset->y + lineSpacing ) : 0 ) ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = TextLength( text );
|
int len = TextLength( text );
|
||||||
float scaleFactor = fontSize / font.baseSize;
|
float scaleFactor = fontSize / font.baseSize;
|
||||||
float wordWidth = 0.0;
|
float wordWidth = 0.0;
|
||||||
@@ -52,6 +50,10 @@ float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset
|
|||||||
if ( codepoint == '\n' ) {
|
if ( codepoint == '\n' ) {
|
||||||
textOffset->x = 0;
|
textOffset->x = 0;
|
||||||
textOffset->y += lineSpacing;
|
textOffset->y += lineSpacing;
|
||||||
|
measure = true;
|
||||||
|
}
|
||||||
|
else if ( codepoint == '\t' ) {
|
||||||
|
measure = true;
|
||||||
}
|
}
|
||||||
else if ( wordWrap && ( wordWidth < rec.width ) ) {
|
else if ( wordWrap && ( wordWidth < rec.width ) ) {
|
||||||
if ( measure && codepoint != ' ' ) {
|
if ( measure && codepoint != ' ' ) {
|
||||||
@@ -63,7 +65,7 @@ float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset
|
|||||||
textOffset->y += lineSpacing;
|
textOffset->y += lineSpacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( codepoint == ' ' || codepoint == '\n' || codepoint == '\t' ) {
|
else if ( codepoint == ' ' ) {
|
||||||
measure = true;
|
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.
|
Draw text using font inside rectangle limits.
|
||||||
|
|
||||||
@@ -549,15 +551,19 @@ int ltextDrawTextBoxed( lua_State* L ) {
|
|||||||
Color tint = uluaGetColor( L, 7 );
|
Color tint = uluaGetColor( L, 7 );
|
||||||
bool limitHeight = uluaGetBoolean( L, 8 );
|
bool limitHeight = uluaGetBoolean( L, 8 );
|
||||||
Vector2 textOffset = { 0, 0 };
|
Vector2 textOffset = { 0, 0 };
|
||||||
|
int tabSize = 4;
|
||||||
|
|
||||||
lua_pushinteger( L, DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, &textOffset ) );
|
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 );
|
uluaPushVector2( L, textOffset );
|
||||||
|
|
||||||
return 2;
|
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).
|
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
|
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 );
|
Color tint = uluaGetColor( L, 7 );
|
||||||
bool limitHeight = uluaGetBoolean( L, 8 );
|
bool limitHeight = uluaGetBoolean( L, 8 );
|
||||||
Vector2 textOffset = uluaGetVector2( L, 9 );
|
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 );
|
uluaPushVector2( L, textOffset );
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user