Changed naming of gui functions set2Top and set2Back to setToTop and setToBack.

This commit is contained in:
jussi
2024-06-26 22:28:13 +03:00
parent c96306bcc3
commit e45564ea3f
15 changed files with 94 additions and 77 deletions

6
API.md
View File

@@ -6858,13 +6858,15 @@ Draw multiple character (codepoint)
---
> RL.DrawTextBoxed(Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint )
> mouseCharId, textOffset = RL.DrawTextBoxed(Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight )
Draw text using font inside rectangle limits.
- Success return int, Vector2
---
> mouseCharId, textOffset = RL.DrawTextBoxedEx( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, Vector2 textOffset )
> mouseCharId, textOffset = RL.DrawTextBoxedEx( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2 textOffset )
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

View File

@@ -4045,6 +4045,7 @@ function RL.DrawTextCodepoint( font, codepoint, position, fontSize, tint ) end
function RL.DrawTextCodepoints( font, codepoints, position, fontSize, spacing, tint ) end
---Draw text using font inside rectangle limits.
---- Success return int, Vector2
---@param font any
---@param text string
---@param rec table
@@ -4052,8 +4053,10 @@ function RL.DrawTextCodepoints( font, codepoints, position, fontSize, spacing,
---@param spacing number
---@param wordWrap boolean
---@param tint table
---@return any RL.DrawTextBoxed
function RL.DrawTextBoxed( font, text, rec, fontSize, spacing, wordWrap, tint ) end
---@param limitHeight boolean
---@return any mouseCharId
---@return any textOffset
function RL.DrawTextBoxed( font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight ) 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
@@ -4066,10 +4069,11 @@ function RL.DrawTextBoxed( font, text, rec, fontSize, spacing, wordWrap, tint )
---@param spacing number
---@param wordWrap boolean
---@param tint table
---@param limitHeight boolean
---@param textOffset table
---@return any mouseCharId
---@return any textOffset
function RL.DrawTextBoxedEx( font, text, rec, fontSize, spacing, wordWrap, tint, textOffset ) end
function RL.DrawTextBoxedEx( font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, textOffset ) end
-- Text - Text font info functions

View File

@@ -57,6 +57,7 @@ DETAILED CHANGES:
- ADDED: GetTextLineSpacing.
- REMOVED: DrawTextBoxedTinted. DrawTextBoxedEx can do same much more efficiently.
- ADDED: DrawTextBoxedEx.
- CHANGE: Naming of gui functions set2Top and set2Back to setToTop and setToBack.
------------------------------------------------------------------------
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0

View File

@@ -19,7 +19,7 @@ function Calculator:new( pos )
bounds = Rect:new( 0, 0, object.windowRect.width, object.HANDLE_HIGHT ),
padding = 10,
onClicked = function()
object:set2Top()
object:setToTop()
object.dragPos = Vec2:newT( RL.GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y )
Gui.heldCallback = function() object:drag() end
end,
@@ -186,16 +186,16 @@ function Calculator:setVisible( visible )
end
end
function Calculator:set2Top()
self.panel:set2Top()
function Calculator:setToTop()
self.panel:setToTop()
for _, button in ipairs( self.buttons ) do
button:set2Top()
button:setToTop()
end
self.handle:set2Top()
self.closeButton:set2Top()
self.display:set2Top()
self.handle:setToTop()
self.closeButton:setToTop()
self.display:setToTop()
end
function Calculator:addValue( value )

View File

@@ -19,7 +19,7 @@ function FileExplorer:new( pos )
bounds = Rect:new( 0, 0, object.windowRect.width, object.HANDLE_HIGHT ),
padding = 10,
onClicked = function()
object:set2Top()
object:setToTop()
object.dragPos = Vec2:newT( RL.GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y )
Gui.heldCallback = function() object:drag() end
end,
@@ -305,15 +305,15 @@ function FileExplorer:setVisible( visible )
self.files:update()
end
function FileExplorer:set2Top()
self.panel:set2Top()
self.handle:set2Top()
self.closeButton:set2Top()
self.pathBox:set2Top()
self.backButton:set2Top()
self.files:set2Top()
self.fileName:set2Top()
self.openButton:set2Top()
function FileExplorer:setToTop()
self.panel:setToTop()
self.handle:setToTop()
self.closeButton:setToTop()
self.pathBox:setToTop()
self.backButton:setToTop()
self.files:setToTop()
self.fileName:setToTop()
self.openButton:setToTop()
end
return FileExplorer

View File

@@ -21,6 +21,8 @@ local guiTabBarActive = 0
local colorPickerHSV = { 0, 0, 0 }
local colorPanelHSV = { 0, 0, 0 }
local value = 0
function RL.init()
local monitor = 0
local mPos = RL.GetMonitorPosition( monitor )
@@ -121,4 +123,6 @@ function RL.draw()
_, colorPickerHSV = RL.GuiColorPickerHSV( { 1024, 20, 150, 150 }, "GuiColorPuckerHSV", colorPickerHSV )
_, colorPanelHSV = RL.GuiColorPanelHSV( { 1230, 20, 150, 150 }, "GuiColorPuckerHSV", colorPanelHSV )
value = RL.GuiScrollBar( { 0, 0, 10, 200 }, value, 0, 100 )
end

View File

@@ -18,7 +18,7 @@ function Calculator:new( pos )
"Calculator",
{ -- Callbacks.
close = function() object:setVisible( false ) end,
grab = function() object:set2Top() end,
grab = function() object:setToTop() end,
drag = function( this ) object:setPosition( Vec2:new( this.bounds.x, this.bounds.y ) ) end
}
)
@@ -137,12 +137,12 @@ function Calculator:setPosition( pos )
end
end
function Calculator:set2Top()
Gui:set2Top( self.window )
Gui:set2Top( self.display )
function Calculator:setToTop()
Gui:setToTop( self.window )
Gui:setToTop( self.display )
for _, button in ipairs( self.buttons ) do
Gui:set2Top( button )
Gui:setToTop( button )
end
end

View File

@@ -39,7 +39,7 @@ function FileBrowser:new( pos )
"File Browser",
{ -- callbacks.
close = function() object:setVisible( false ) end,
grab = function() object:set2Top() end,
grab = function() object:setToTop() end,
drag = function( this ) object:setPosition( Vec2:new( this.bounds.x, this.bounds.y ) ) end
}
)
@@ -363,11 +363,11 @@ function FileBrowser:setPosition( pos )
end
end
function FileBrowser:set2Top()
Gui:set2Top( self.window )
function FileBrowser:setToTop()
Gui:setToTop( self.window )
for _, control in ipairs( self.controls ) do
Gui:set2Top( control )
Gui:setToTop( control )
end
end

View File

@@ -75,7 +75,7 @@ local function addPropertyList()
Rect:new( 20, 20, 256, 328 ),
"Property List",
{ -- Callbacks.
grab = function( self ) Gui:set2Top( self ) end,
grab = function( self ) Gui:setToTop( self ) end,
},
{ -- Styles.
properties = {
@@ -272,7 +272,7 @@ local function addTreeView()
"Tree View",
{ -- Callbacks.
select = function( controls ) selected( controls ) end,
grab = function( self ) Gui:set2Top( self ) end,
grab = function( self ) Gui:setToTop( self ) end,
},
{ -- Styles.
properties = {

View File

@@ -87,7 +87,7 @@ function PropertyList:updateControl( control )
control.text = setGroupText( control.text:sub( 6 ), control.active ) -- Sub skips icon.
end
self.gui:set2Back( control )
self.gui:setToBack( control )
end
function PropertyList:updateContent()

View File

@@ -208,7 +208,7 @@ function RL.init()
"WindowBox",
{ -- Callbacks.
close = function( self ) self.visible = false end,
grab = function( self ) Gui:set2Top( self ) end,
grab = function( self ) Gui:setToTop( self ) end,
},
{ -- Styles.
properties = {
@@ -230,7 +230,7 @@ function RL.init()
Rect:new( 400, 64, 256, 128 ),
"Panel",
{ -- Callbacks.
grab = function( self ) Gui:set2Top( self ) end
grab = function( self ) Gui:setToTop( self ) end
},
{ -- Styles.
properties = {
@@ -255,7 +255,7 @@ function RL.init()
Vec2:new( 0, 0 ),
{ -- Callbacks.
scroll = function( self ) print( self.scroll ) end,
grab = function( self ) Gui:set2Top( self ) end
grab = function( self ) Gui:setToTop( self ) end
}
)
local listview = Gui:ListView(
@@ -300,7 +300,7 @@ function RL.init()
end
end
end,
grab = function( self ) Gui:set2Top( self ) end
grab = function( self ) Gui:setToTop( self ) end
}
)
local textinputbox = Gui:TextInputBox(
@@ -317,7 +317,7 @@ function RL.init()
print( "You pressed "..self:getItem( self.buttonIndex ) )
end
end,
grab = function( self ) Gui:set2Top( self ) end
grab = function( self ) Gui:setToTop( self ) end
}
)
local colorpicker = Gui:ColorPicker(

View File

@@ -95,11 +95,11 @@ function Gui.delete( cell )
end
end
function Gui.set2Top( cell )
function Gui.setToTop( cell )
Util.tableMove( Gui._cells, Gui.getId( cell ), 1, #Gui._cells )
end
function Gui.set2Back( cell )
function Gui.setToBack( cell )
Util.tableMove( Gui._cells, Gui.getId( cell ), 1, 1 )
end
@@ -518,12 +518,12 @@ function Element:delete()
Gui.delete( self )
end
function Element:set2Top()
Gui.set2Top( self )
function Element:setToTop()
Gui.setToTop( self )
end
function Element:set2Back()
Gui.set2Back( self )
function Element:setToBack()
Gui.setToBack( self )
end
-- Container.
@@ -820,34 +820,34 @@ function Container:clear()
self.cells = {}
end
function Container:set2Top()
Gui.set2Top( self )
function Container:setToTop()
Gui.setToTop( self )
for _, cell in ipairs( self.cells ) do
cell:set2Top()
cell:setToTop()
end
if self._VScrollbar ~= nil then
Gui.set2Top( self._VScrollbar )
Gui.setToTop( self._VScrollbar )
end
if self._HScrollbar ~= nil then
Gui.set2Top( self._HScrollbar )
Gui.setToTop( self._HScrollbar )
end
end
function Container:set2Back()
function Container:setToBack()
if self._VScrollbar ~= nil then
Gui.set2Back( self._VScrollbar )
Gui.setToBack( self._VScrollbar )
end
if self._HScrollbar ~= nil then
Gui.set2Back( self._HScrollbar )
Gui.setToBack( self._HScrollbar )
end
for _, cell in ipairs( self.cells ) do
cell:set2Back()
cell:setToBack()
end
Gui.set2Back( self )
Gui.setToBack( self )
end
function Container:draw()

View File

@@ -1922,11 +1922,10 @@ function Raygui:checkScrolling()
end
function Raygui:clickedInBounds( bounds )
print( self._mousePressPos, bounds )
return RL.CheckCollisionPointRec( self._mousePressPos, bounds )
end
function Raygui:set2Top( control )
function Raygui:setToTop( control )
for i, curControl in ipairs( self.controls ) do
if control == curControl then
Util.tableMove( self.controls, i, 1, #self.controls )
@@ -1936,7 +1935,7 @@ function Raygui:set2Top( control )
end
end
function Raygui:set2Back( control )
function Raygui:setToBack( control )
for i, curControl in ipairs( self.controls ) do
if control == curControl then
Util.tableMove( self.controls, i, 1, 1 )

View File

@@ -3,6 +3,7 @@ local spacing = 1
local rect = { 100, 64, 200, 200 }
local wordwrap = true
local linkColor = RL.BLUE
local limitHeight = true
local mouseCharId = 0
local textOffset = { 0, 0 }
@@ -34,21 +35,21 @@ function RL.draw()
mouseCharId, textOffset = RL.DrawTextBoxedEx(
RL.GetFontDefault(),
"You can change the size of the box by pressing right mouse and toggle the wordwrap by pressing space. First we will write some text before the hyperlink to show that it is indeed is as powerful feature as adverticed.",
"\tYou can change the size of the box by pressing right mouse and toggle the wordwrap by pressing space. First we will write some text before the hyperlink to show that it is indeed is as powerful feature as adverticed.",
rect,
textSize, spacing, wordwrap, RL.RED, { 0, 0 }
textSize, spacing, wordwrap, RL.RED, limitHeight, { 0, 0 }
)
mouseCharId, textOffset = RL.DrawTextBoxedEx(
RL.GetFontDefault(),
" Hyperlink.",
rect,
textSize, spacing, wordwrap, linkColor, textOffset
textSize, spacing, wordwrap, linkColor, limitHeight, textOffset
)
RL.DrawTextBoxedEx(
RL.GetFontDefault(),
" Then we demonstrate this further by writin more text after the link. Isn't this just amazing! Don't forget to press left mouse to print text to your console when hovering mouse over the hyperlink.",
rect,
textSize, spacing, wordwrap, RL.RED, textOffset
textSize, spacing, wordwrap, RL.RED, limitHeight, textOffset
)
if 0 < mouseCharId then
@@ -57,4 +58,3 @@ function RL.draw()
linkColor = RL.BLUE
end
end

View File

@@ -25,10 +25,11 @@ 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, Vector2* textOffset, bool getMouseChar ) {
float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2* textOffset ) {
const int tabSize = 4; /* How many spaces. */
int lineSpacing = state->lineSpacing;
if ( rec.width <= 0 || rec.height <= ( textOffset->y + lineSpacing ) ) {
if ( rec.width <= 0 || ( rec.height <= limitHeight ? ( textOffset->y + lineSpacing ) : 0 ) ) {
return 0;
}
@@ -73,20 +74,21 @@ float spacing, bool wordWrap, Color tint, Vector2* textOffset, bool getMouseChar
}
}
if ( rec.height < ( textOffset->y + lineSpacing ) ) {
if ( limitHeight && ( rec.height < ( textOffset->y + lineSpacing ) ) ) {
break;
}
if ( codepoint != '\n' && !( textOffset->x == 0 && codepoint == ' ' ) && codepointWidth < rec.width ) {
DrawTextCodepoint( font, codepoint, (Vector2){ rec.x + textOffset->x, rec.y + textOffset->y }, fontSize, tint );
if ( codepoint != '\n' && codepoint != '\t' && !( textOffset->x == 0 && codepoint == ' ' ) && codepointWidth < rec.width ) {
DrawTextCodepoint( font, codepoint, (Vector2){ round( rec.x + textOffset->x ), round( rec.y + textOffset->y ) }, fontSize, tint );
if ( getMouseChar && CheckCollisionPointRec( mousePos, (Rectangle){ rec.x + textOffset->x - 1, rec.y + textOffset->y, codepointWidth, (float)font.baseSize * scaleFactor } ) ) {
if ( CheckCollisionPointRec( mousePos, (Rectangle){ rec.x + textOffset->x - 1, rec.y + textOffset->y, codepointWidth, (float)font.baseSize * scaleFactor } ) ) {
mouseChar = i + 1;
}
textOffset->x += codepointWidth;
}
else if ( codepoint == '\t' ) {
textOffset->x += (float)font.recs[ GetGlyphIndex( font, ' ' ) ].width * tabSize * scaleFactor + spacing;
}
i += codepointByteCount;
}
return mouseChar;
@@ -516,9 +518,11 @@ int ltextDrawTextCodepoints( lua_State* L ) {
}
/*
> RL.DrawTextBoxed(Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint )
> mouseCharId, textOffset = RL.DrawTextBoxed(Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight )
Draw text using font inside rectangle limits.
- Success return int, Vector2
*/
int ltextDrawTextBoxed( lua_State* L ) {
Font* font = uluaGetFont( L, 1 );
@@ -528,15 +532,17 @@ int ltextDrawTextBoxed( lua_State* L ) {
float spacing = luaL_checknumber( L, 5 );
bool wordWrap = uluaGetBoolean( L, 6 );
Color tint = uluaGetColor( L, 7 );
bool limitHeight = uluaGetBoolean( L, 8 );
Vector2 textOffset = { 0, 0 };
DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, &textOffset, false );
lua_pushinteger( L, DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, &textOffset ) );
uluaPushVector2( L, textOffset );
return 0;
return 2;
}
/*
> mouseCharId, textOffset = RL.DrawTextBoxedEx( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, Vector2 textOffset )
> mouseCharId, textOffset = RL.DrawTextBoxedEx( Font font, string text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, bool limitHeight, Vector2 textOffset )
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
@@ -552,9 +558,10 @@ int ltextDrawTextBoxedEx( lua_State* L ) {
float spacing = luaL_checknumber( L, 5 );
bool wordWrap = uluaGetBoolean( L, 6 );
Color tint = uluaGetColor( L, 7 );
Vector2 textOffset = uluaGetVector2( L, 8 );
bool limitHeight = uluaGetBoolean( L, 8 );
Vector2 textOffset = uluaGetVector2( L, 9 );
lua_pushinteger( L, DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, &textOffset, true ) );
lua_pushinteger( L, DrawTextBoxed( *font, text, rec, fontSize, spacing, wordWrap, tint, limitHeight, &textOffset ) );
uluaPushVector2( L, textOffset );
return 2;