DrawTextBoxed uses lineSpacing. GetTextLineSpacing.
This commit is contained in:
12
API.md
12
API.md
@@ -6866,7 +6866,7 @@ Draw text using font inside rectangle limits. Return character id from mouse pos
|
||||
|
||||
---
|
||||
|
||||
> mouseCharId = RL.DrawTextBoxedTinted( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tints, Color backTints )
|
||||
> mouseCharId = RL.DrawTextBoxedTinted( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tints{}, Color backTints{} )
|
||||
|
||||
Draw text using font inside rectangle limits with support for tint and background tint for each character. Return character id from mouse position (default -1)
|
||||
|
||||
@@ -6878,12 +6878,20 @@ Draw text using font inside rectangle limits with support for tint and backgroun
|
||||
|
||||
---
|
||||
|
||||
> size = RL.SetTextLineSpacing( int spacing )
|
||||
> RL.SetTextLineSpacing( int spacing )
|
||||
|
||||
Set vertical line spacing when drawing with line-breaks
|
||||
|
||||
---
|
||||
|
||||
> spacing = RL.GetTextLineSpacing()
|
||||
|
||||
Get vertical line spacing when drawing with line-breaks
|
||||
|
||||
- Success return int
|
||||
|
||||
---
|
||||
|
||||
> width = RL.MeasureText( string text, int fontSize )
|
||||
|
||||
Measure string width for default font
|
||||
|
||||
@@ -4064,17 +4064,22 @@ function RL.DrawTextBoxed( font, text, rec, fontSize, spacing, wordWrap, tint )
|
||||
---@param fontSize number
|
||||
---@param spacing number
|
||||
---@param wordWrap boolean
|
||||
---@param tints table
|
||||
---@param backTints table
|
||||
---@param tints{} table
|
||||
---@param backTints{} table
|
||||
---@return any mouseCharId
|
||||
function RL.DrawTextBoxedTinted( font, text, rec, fontSize, spacing, wordWrap, tints, backTints ) end
|
||||
function RL.DrawTextBoxedTinted( font, text, rec, fontSize, spacing, wordWrap, tints{}, backTints{} ) end
|
||||
|
||||
-- Text - Text font info functions
|
||||
|
||||
---Set vertical line spacing when drawing with line-breaks
|
||||
---@param spacing integer
|
||||
---@return any size
|
||||
function RL.SetTextLineSpacing( spacing ) end
|
||||
---@return any RL.SetTextLineSpacing
|
||||
function RL.SetTextLineSpacing( spacing ) end
|
||||
|
||||
---Get vertical line spacing when drawing with line-breaks
|
||||
---- Success return int
|
||||
---@return any spacing
|
||||
function RL.GetTextLineSpacing() end
|
||||
|
||||
---Measure string width for default font
|
||||
---- Success return int
|
||||
|
||||
@@ -53,6 +53,8 @@ DETAILED CHANGES:
|
||||
- ADDED: GetPlatform.
|
||||
- ADDED: Object lib serialization.
|
||||
- ADDED: Unload functions clear object to 0 so they would not be ready in Is*Ready.
|
||||
- CHANGE: DrawTextBoxed uses lineSpacing.
|
||||
- ADDED: GetTextLineSpacing.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0
|
||||
|
||||
@@ -9,6 +9,7 @@ typedef struct {
|
||||
bool hasWindow;
|
||||
bool run;
|
||||
bool gcUnload;
|
||||
int lineSpacing; /* We need to store copy here since raylib has it in static. */
|
||||
lua_State* luaState;
|
||||
Vector2 resolution;
|
||||
int logLevelInvalid;
|
||||
|
||||
@@ -24,6 +24,7 @@ int ltextDrawTextBoxed( lua_State* L );
|
||||
int ltextDrawTextBoxedTinted( lua_State* L );
|
||||
/* Text font info functions. */
|
||||
int ltextSetTextLineSpacing( lua_State* L );
|
||||
int ltextGetTextLineSpacing( lua_State* L );
|
||||
int ltextMeasureText( lua_State* L );
|
||||
int ltextMeasureTextEx( lua_State* L );
|
||||
int ltextGetGlyphIndex( lua_State* L );
|
||||
|
||||
@@ -1841,6 +1841,7 @@ void luaRegister() {
|
||||
assingGlobalFunction( "DrawTextBoxedTinted", ltextDrawTextBoxedTinted );
|
||||
/* Text font info functions. */
|
||||
assingGlobalFunction( "SetTextLineSpacing", ltextSetTextLineSpacing );
|
||||
assingGlobalFunction( "GetTextLineSpacing", ltextGetTextLineSpacing );
|
||||
assingGlobalFunction( "MeasureText", ltextMeasureText );
|
||||
assingGlobalFunction( "MeasureTextEx", ltextMeasureTextEx );
|
||||
assingGlobalFunction( "GetGlyphIndex", ltextGetGlyphIndex );
|
||||
|
||||
@@ -18,6 +18,7 @@ bool stateInit( int argn, const char** argc, const char* basePath ) {
|
||||
state->luaState = NULL;
|
||||
state->logLevelInvalid = LOG_ERROR;
|
||||
state->gcUnload = true;
|
||||
state->lineSpacing = 15;
|
||||
|
||||
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" );
|
||||
|
||||
|
||||
29
src/text.c
29
src/text.c
@@ -12,14 +12,14 @@ void unloadGlyphInfo( GlyphInfo* glyph ) {
|
||||
|
||||
// Draw text using font inside rectangle limits
|
||||
static int DrawTextBoxed( Font font, const char* text, Rectangle rec, float fontSize, float spacing,
|
||||
bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount )
|
||||
{
|
||||
bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount ) {
|
||||
int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
|
||||
|
||||
float textOffsetY = 0; // Offset between lines (on line break '\n')
|
||||
float textOffsetX = 0.0f; // Offset X to next character to draw
|
||||
|
||||
float scaleFactor = fontSize/(float)font.baseSize; // Character rectangle scaling factor
|
||||
int lineSpacing = state->lineSpacing;
|
||||
|
||||
// Word/character wrapping mechanism variables
|
||||
enum { MEASURE_STATE = 0, DRAW_STATE = 1 };
|
||||
@@ -103,7 +103,8 @@ bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount
|
||||
{
|
||||
if (!wordWrap)
|
||||
{
|
||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||
// textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||
textOffsetY += lineSpacing;
|
||||
textOffsetX = 0;
|
||||
}
|
||||
}
|
||||
@@ -111,7 +112,8 @@ bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount
|
||||
{
|
||||
if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width))
|
||||
{
|
||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||
// textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||
textOffsetY += lineSpacing;
|
||||
textOffsetX = 0;
|
||||
}
|
||||
|
||||
@@ -144,7 +146,8 @@ bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount
|
||||
|
||||
if (wordWrap && (i == endLine))
|
||||
{
|
||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||
// textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||
textOffsetY += lineSpacing;
|
||||
textOffsetX = 0;
|
||||
startLine = endLine;
|
||||
endLine = -1;
|
||||
@@ -606,7 +609,7 @@ int ltextDrawTextBoxed( lua_State* L ) {
|
||||
}
|
||||
|
||||
/*
|
||||
> mouseCharId = RL.DrawTextBoxedTinted( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tints, Color backTints )
|
||||
> mouseCharId = RL.DrawTextBoxedTinted( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tints{}, Color backTints{} )
|
||||
|
||||
Draw text using font inside rectangle limits with support for tint and background tint for each character. Return character id from mouse position (default -1)
|
||||
|
||||
@@ -653,16 +656,28 @@ int ltextDrawTextBoxedTinted( lua_State* L ) {
|
||||
*/
|
||||
|
||||
/*
|
||||
> size = RL.SetTextLineSpacing( int spacing )
|
||||
> RL.SetTextLineSpacing( int spacing )
|
||||
|
||||
Set vertical line spacing when drawing with line-breaks
|
||||
*/
|
||||
int ltextSetTextLineSpacing( lua_State* L ) {
|
||||
int spacing = luaL_checkinteger( L, 1 );
|
||||
|
||||
state->lineSpacing = spacing;
|
||||
SetTextLineSpacing( spacing );
|
||||
}
|
||||
|
||||
/*
|
||||
> spacing = RL.GetTextLineSpacing()
|
||||
|
||||
Get vertical line spacing when drawing with line-breaks
|
||||
|
||||
- Success return int
|
||||
*/
|
||||
int ltextGetTextLineSpacing( lua_State* L ) {
|
||||
lua_pushinteger( L, state->lineSpacing );
|
||||
}
|
||||
|
||||
/*
|
||||
> width = RL.MeasureText( string text, int fontSize )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user