diff options
| -rw-r--r-- | API.md | 6 | ||||
| -rw-r--r-- | ReiLua_API.lua | 10 | ||||
| -rw-r--r-- | changelog | 1 | ||||
| -rw-r--r-- | examples/ReiLuaGui_examples/calculator.lua | 14 | ||||
| -rw-r--r-- | examples/ReiLuaGui_examples/file_explorer.lua | 20 | ||||
| -rw-r--r-- | examples/gui/main.lua | 4 | ||||
| -rw-r--r-- | examples/raygui_examples/calculator.lua | 10 | ||||
| -rw-r--r-- | examples/raygui_examples/file_browser.lua | 8 | ||||
| -rw-r--r-- | examples/raygui_extensions/main.lua | 4 | ||||
| -rw-r--r-- | examples/raygui_extensions/property_list.lua | 2 | ||||
| -rw-r--r-- | examples/raygui_lib/main.lua | 10 | ||||
| -rw-r--r-- | examples/resources/lib/gui.lua | 32 | ||||
| -rw-r--r-- | examples/resources/lib/raygui.lua | 5 | ||||
| -rw-r--r-- | examples/textBoxed/main.lua | 10 | ||||
| -rw-r--r-- | src/text.c | 35 |
15 files changed, 94 insertions, 77 deletions
@@ -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 diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 1b74f8b..019138f 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -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 @@ -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 diff --git a/examples/ReiLuaGui_examples/calculator.lua b/examples/ReiLuaGui_examples/calculator.lua index f6fcb7c..5bd2d7b 100644 --- a/examples/ReiLuaGui_examples/calculator.lua +++ b/examples/ReiLuaGui_examples/calculator.lua @@ -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 ) diff --git a/examples/ReiLuaGui_examples/file_explorer.lua b/examples/ReiLuaGui_examples/file_explorer.lua index 398adef..89fc173 100644 --- a/examples/ReiLuaGui_examples/file_explorer.lua +++ b/examples/ReiLuaGui_examples/file_explorer.lua @@ -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 diff --git a/examples/gui/main.lua b/examples/gui/main.lua index 5a178dc..06c98bc 100644 --- a/examples/gui/main.lua +++ b/examples/gui/main.lua @@ -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 diff --git a/examples/raygui_examples/calculator.lua b/examples/raygui_examples/calculator.lua index 6274a0b..6faf11d 100644 --- a/examples/raygui_examples/calculator.lua +++ b/examples/raygui_examples/calculator.lua @@ -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 diff --git a/examples/raygui_examples/file_browser.lua b/examples/raygui_examples/file_browser.lua index df6f244..e4705a6 100644 --- a/examples/raygui_examples/file_browser.lua +++ b/examples/raygui_examples/file_browser.lua @@ -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 diff --git a/examples/raygui_extensions/main.lua b/examples/raygui_extensions/main.lua index a5d9760..3e9d2f1 100644 --- a/examples/raygui_extensions/main.lua +++ b/examples/raygui_extensions/main.lua @@ -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 = { diff --git a/examples/raygui_extensions/property_list.lua b/examples/raygui_extensions/property_list.lua index 1a8c30f..266852e 100644 --- a/examples/raygui_extensions/property_list.lua +++ b/examples/raygui_extensions/property_list.lua @@ -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() diff --git a/examples/raygui_lib/main.lua b/examples/raygui_lib/main.lua index 95a733f..c787d2e 100644 --- a/examples/raygui_lib/main.lua +++ b/examples/raygui_lib/main.lua @@ -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( diff --git a/examples/resources/lib/gui.lua b/examples/resources/lib/gui.lua index 2bae0eb..de40dd0 100644 --- a/examples/resources/lib/gui.lua +++ b/examples/resources/lib/gui.lua @@ -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() diff --git a/examples/resources/lib/raygui.lua b/examples/resources/lib/raygui.lua index 1cd0269..437bc96 100644 --- a/examples/resources/lib/raygui.lua +++ b/examples/resources/lib/raygui.lua @@ -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 ) diff --git a/examples/textBoxed/main.lua b/examples/textBoxed/main.lua index ce570c0..df731c3 100644 --- a/examples/textBoxed/main.lua +++ b/examples/textBoxed/main.lua @@ -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 - @@ -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; |
