summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md28
-rw-r--r--ReiLua_API.lua37
-rw-r--r--changelog4
-rw-r--r--examples/raygui_custom/main.lua89
-rw-r--r--examples/raygui_extensions/main.lua229
-rw-r--r--examples/raygui_extensions/property_list.lua100
-rw-r--r--examples/raygui_extensions/sprite_button.lua (renamed from examples/raygui_custom/spriteButton.lua)10
-rw-r--r--examples/raygui_lib/main.lua7
-rw-r--r--examples/resources/lib/raygui.lua371
-rw-r--r--include/raygui.h126
-rw-r--r--src/rgui.c66
-rw-r--r--src/text.c2
12 files changed, 731 insertions, 338 deletions
diff --git a/API.md b/API.md
index 049a202..63a5e07 100644
--- a/API.md
+++ b/API.md
@@ -6325,7 +6325,7 @@ Load font from Image (XNA style)
> font = RL.LoadFontFromMemory( string fileType, Buffer fileData, int fontSize, int{} codepoints )
-Load font from memory buffer, fileType refers to extension: i.e. '.ttf'. NOTE: FileData type should be unsigned char
+Load font from memory buffer, fileType refers to extension: i.e. '.ttf'. NOTE: fileData type should be unsigned char
- Success return Font
@@ -6349,7 +6349,7 @@ Check if a font is ready
> glyphs = RL.LoadFontData( Buffer fileData, int fontSize, int{} codepoints, int type )
-Load font data for further use. NOTE: FileData type should be unsigned char
+Load font data for further use. NOTE: fileData type should be unsigned char
- Success return GlyphInfo{}
@@ -8886,11 +8886,11 @@ Toggle Slider control, returns true when clicked
---
-> result, checked = RL.GuiCheckBox( Rectangle bounds, string text, bool checked )
+> result, checked, textBounds = RL.GuiCheckBox( Rectangle bounds, string text, bool checked )
Check Box control, returns true when active
-- Success return bool
+- Success return bool, Rectangle
---
@@ -8910,19 +8910,19 @@ Dropdown Box control, returns selected item
---
-> result, value = RL.GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
+> result, value, textBounds = RL.GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
Spinner control, returns selected value
-- Success return int, int
+- Success return int, int, Rectangle
---
-> result, value = RL.GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
+> result, value, textBounds = RL.GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
Value Box control, updates input text with numbers
-- Success return int, int
+- Success return int, int, Rectangle
---
@@ -8934,27 +8934,27 @@ Text Box control, updates input text
---
-> result, value = RL.GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
+> result, value, textLeftBounds, textRightBounds = RL.GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Slider control, returns selected value
-- Success return int, float
+- Success return int, float, Rectangle, Rectangle
---
-> result, value = RL.GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
+> result, value, textLeftBounds, textRightBounds = RL.GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Slider Bar control, returns selected value
-- Success return int, float
+- Success return int, float, Rectangle, Rectangle
---
-> result, value = RL.GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
+> result, value, textLeftBounds, textRightBounds = RL.GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Progress Bar control, shows current progress value
-- Success return int, float
+- Success return int, float, Rectangle, Rectangle
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 04de577..9cb2d50 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -3673,7 +3673,7 @@ function RL.LoadFontEx( fileName, fontSize, codepoints ) end
---@return any font
function RL.LoadFontFromImage( image, key, firstChar ) end
----Load font from memory buffer, fileType refers to extension: i.e. '.ttf'. NOTE: FileData type should be unsigned char
+---Load font from memory buffer, fileType refers to extension: i.e. '.ttf'. NOTE: fileData type should be unsigned char
---- Success return Font
---@param fileType string
---@param fileData any
@@ -3694,7 +3694,7 @@ function RL.LoadFontFromData( fontData ) end
---@return any isReady
function RL.IsFontReady( font ) end
----Load font data for further use. NOTE: FileData type should be unsigned char
+---Load font data for further use. NOTE: fileData type should be unsigned char
---- Success return GlyphInfo{}
---@param fileData any
---@param fontSize integer
@@ -6001,12 +6001,13 @@ function RL.GuiToggleGroup( bounds, text, active ) end
function RL.GuiToggleSlider( bounds, text, active ) end
---Check Box control, returns true when active
----- Success return bool
+---- Success return bool, Rectangle
---@param bounds table
---@param text string
---@param checked boolean
---@return any result
----@return any checked
+---@return any checked
+---@return any textBounds
function RL.GuiCheckBox( bounds, text, checked ) end
---Combo Box control, returns selected item index
@@ -6029,7 +6030,7 @@ function RL.GuiComboBox( bounds, text, active ) end
function RL.GuiDropdownBox( bounds, text, active, editMode ) end
---Spinner control, returns selected value
----- Success return int, int
+---- Success return int, int, Rectangle
---@param bounds table
---@param text string
---@param value integer
@@ -6037,11 +6038,12 @@ function RL.GuiDropdownBox( bounds, text, active, editMode ) end
---@param maxValue integer
---@param editMode boolean
---@return any result
----@return any value
+---@return any value
+---@return any textBounds
function RL.GuiSpinner( bounds, text, value, minValue, maxValue, editMode ) end
---Value Box control, updates input text with numbers
----- Success return int, int
+---- Success return int, int, Rectangle
---@param bounds table
---@param text string
---@param value integer
@@ -6049,7 +6051,8 @@ function RL.GuiSpinner( bounds, text, value, minValue, maxValue, editMode ) end
---@param maxValue integer
---@param editMode boolean
---@return any result
----@return any value
+---@return any value
+---@return any textBounds
function RL.GuiValueBox( bounds, text, value, minValue, maxValue, editMode ) end
---Text Box control, updates input text
@@ -6063,7 +6066,7 @@ function RL.GuiValueBox( bounds, text, value, minValue, maxValue, editMode ) end
function RL.GuiTextBox( bounds, text, textSize, editMode ) end
---Slider control, returns selected value
----- Success return int, float
+---- Success return int, float, Rectangle, Rectangle
---@param bounds table
---@param textLeft string
---@param textRight string
@@ -6071,11 +6074,13 @@ function RL.GuiTextBox( bounds, text, textSize, editMode ) end
---@param minValue number
---@param maxValue number
---@return any result
----@return any value
+---@return any value
+---@return any textLeftBounds
+---@return any textRightBounds
function RL.GuiSlider( bounds, textLeft, textRight, value, minValue, maxValue ) end
---Slider Bar control, returns selected value
----- Success return int, float
+---- Success return int, float, Rectangle, Rectangle
---@param bounds table
---@param textLeft string
---@param textRight string
@@ -6083,11 +6088,13 @@ function RL.GuiSlider( bounds, textLeft, textRight, value, minValue, maxValue )
---@param minValue number
---@param maxValue number
---@return any result
----@return any value
+---@return any value
+---@return any textLeftBounds
+---@return any textRightBounds
function RL.GuiSliderBar( bounds, textLeft, textRight, value, minValue, maxValue ) end
---Progress Bar control, shows current progress value
----- Success return int, float
+---- Success return int, float, Rectangle, Rectangle
---@param bounds table
---@param textLeft string
---@param textRight string
@@ -6095,7 +6102,9 @@ function RL.GuiSliderBar( bounds, textLeft, textRight, value, minValue, maxValue
---@param minValue number
---@param maxValue number
---@return any result
----@return any value
+---@return any value
+---@return any textLeftBounds
+---@return any textRightBounds
function RL.GuiProgressBar( bounds, textLeft, textRight, value, minValue, maxValue ) end
---Status Bar control, shows info text
diff --git a/changelog b/changelog
index 1b9410a..d4d73de 100644
--- a/changelog
+++ b/changelog
@@ -30,6 +30,8 @@ KEY CHANGES:
- ADDED: Rest of font loading/unloading functions.
- CHANGE: GlyphInfo type to userdata.
- ADDED: GlyphInfo management functions.
+ - CHANGE: GuiTabBar works differently to raygui implementation.
+ - UPDATED: Raygui lib enhancements.
DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
@@ -56,6 +58,8 @@ DETAILED CHANGES:
- ADDED: GetImageData.
- FIXED: CameraLib. Slow lateral movement.
- ADDED: GetGlyphInfoByIndex and GetGlyphAtlasRecByIndex.
+ - ADDED: Raygui lib extensions example.
+ - ADDED: Raygui.h returns textBounds for some controls.
------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5
diff --git a/examples/raygui_custom/main.lua b/examples/raygui_custom/main.lua
deleted file mode 100644
index c11d321..0000000
--- a/examples/raygui_custom/main.lua
+++ /dev/null
@@ -1,89 +0,0 @@
-package.path = package.path..";"..RL.GetBasePath().."?.lua"
-package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
-
-Util = require( "utillib" )
-Rect = require( "rectangle" )
-Vec2 = require( "vector2" )
-Color = require( "color" )
-Rect = require( "rectangle" )
-Raygui = require( "raygui" )
-
-Gui = Raygui:new()
-SpriteButton = require( "spriteButton" )
-SpriteButton:register( Gui )
-local buttonTexture = nil
-
-local resolution = Vec2:new( 640, 480 )
-local winSize = Vec2:new()
-local framebuffer = nil
-
-local function addButton( bounds, text, callback )
- local button = Gui:SpriteButton(
- bounds,
- text,
- buttonTexture,
- { source = { 0, 0, 48, 48 }, left = 16, top = 16, right = 16, bottom = 16, layout = RL.NPATCH_NINE_PATCH },
- { source = { 48, 0, 48, 48 }, left = 16, top = 16, right = 16, bottom = 16, layout = RL.NPATCH_NINE_PATCH },
- callback
- )
- button.styles = {
- { RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
- { RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) },
- { RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) },
- { RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) },
- }
-end
-
-function RL.init()
- local monitor = 0
- local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) )
- local mSize = Vec2:new( RL.GetMonitorSize( monitor ) )
- local winScale = 2
- winSize = resolution:scale( winScale )
-
- framebuffer = RL.LoadRenderTexture( resolution )
-
- RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
- RL.SetWindowState( RL.FLAG_VSYNC_HINT )
- RL.SetWindowSize( resolution:scale( winScale ) )
- RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )
-
- RL.SetMouseScale( { 1/winScale, 1/winScale } )
-
- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 )
-
- buttonTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/button.png" )
-
- local buttonSize = Vec2:new( 216, 32 )
- local bounds = Rect:new( resolution.x / 2 - buttonSize.x / 2, 200, buttonSize.x, buttonSize.y )
- local gap = buttonSize.y + 2
- addButton( bounds, "Start New Game", function() print( "New Game!" ) end )
- bounds.y = bounds.y + gap
- addButton( bounds, "Load Game", function() print( "Load Game!" ) end )
- bounds.y = bounds.y + gap
- addButton( bounds, "Options", function() print( "Options!" ) end )
- bounds.y = bounds.y + gap
- addButton( bounds, "Quit", function() RL.CloseWindow() end )
-end
-
-function RL.process( delta )
- Gui:process()
-end
-
-function RL.draw()
- RL.ClearBackground( RL.BLACK )
- RL.BeginTextureMode( framebuffer )
- RL.ClearBackground( { 50, 20, 75 } )
- Gui:draw()
- RL.EndTextureMode()
-
- RL.DrawTexturePro(
- RL.GetRenderTextureTexture( framebuffer ),
- { 0, 0, resolution.x, -resolution.y },
- { 0, 0, winSize.x, winSize.y },
- { 0, 0 },
- 0.0,
- RL.WHITE
- )
-end
diff --git a/examples/raygui_extensions/main.lua b/examples/raygui_extensions/main.lua
new file mode 100644
index 0000000..6b87ce3
--- /dev/null
+++ b/examples/raygui_extensions/main.lua
@@ -0,0 +1,229 @@
+package.path = package.path..";"..RL.GetBasePath().."?.lua"
+package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
+
+Util = require( "utillib" )
+Rect = require( "rectangle" )
+Vec2 = require( "vector2" )
+Color = require( "color" )
+Rect = require( "rectangle" )
+Raygui = require( "raygui" )
+
+require( "sprite_button" ):register( Raygui )
+require( "property_list" ):register( Raygui )
+
+Gui = Raygui:new()
+
+local buttonTexture = nil
+local winSize = Vec2:new( 1024, 720 )
+
+local function addButton( bounds, text, callback )
+ local button = Gui:SpriteButton(
+ bounds,
+ text,
+ buttonTexture,
+ { source = { 0, 0, 48, 48 }, left = 16, top = 16, right = 16, bottom = 16, layout = RL.NPATCH_NINE_PATCH },
+ { source = { 48, 0, 48, 48 }, left = 16, top = 16, right = 16, bottom = 16, layout = RL.NPATCH_NINE_PATCH },
+ callback
+ )
+ button.styles = {
+ { RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
+ { RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) },
+ { RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) },
+ { RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) },
+ }
+end
+
+local function addSpriteButtons()
+ buttonTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/button.png" )
+
+ local buttonSize = Vec2:new( 216, 32 )
+ local bounds = Rect:new( winSize.x / 2 - buttonSize.x / 2, 200, 216, 32 )
+ local gap = buttonSize.y + 2
+ addButton( bounds, "Start New Game", function() print( "New Game!" ) end )
+ bounds.y = bounds.y + gap
+ addButton( bounds, "Load Game", function() print( "Load Game!" ) end )
+ bounds.y = bounds.y + gap
+ addButton( bounds, "Options", function() print( "Options!" ) end )
+ bounds.y = bounds.y + gap
+ addButton( bounds, "Quit", function() RL.CloseWindow() end )
+end
+
+local function addPropertyList()
+ local propertyList = Gui:PropertyList(
+ Rect:new( 20, 20, 214, 256 ),
+ "Property List",
+ Rect:new( 0, 0, 200, 400 ),
+ -- Rect:new( 0, 0, 400, 400 ),
+ Vec2:new( 0, 0 ),
+ -- Callback.
+ nil,
+ -- Grab callback.
+ function( self ) Gui:set2Top( self ) end
+ )
+ local bounds = Rect:new( 2, 2, 200 - 4, 22 )
+ local gap = bounds.height + 2
+
+ propertyList.gui:Button(
+ bounds,
+ "Button",
+ function() print( "Button clicked" ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:CheckBox(
+ Rect:new( bounds.x, bounds.y, 20, 20 ),
+ "Visible",
+ false,
+ function() print( "Checked!" ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:Toggle(
+ bounds,
+ "Toggle",
+ false,
+ function( self ) print( "Toggled" ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ local dropdown = propertyList.gui:DropdownBox(
+ bounds,
+ "Dog\nGiraffe\nLion\nHorse",
+ 0,
+ false,
+ function( self ) print( self:getItem( self.active ) ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:Spinner(
+ Rect:new( bounds.x, bounds.y, 96, 20 ),
+ "Health",
+ 0,
+ 0,
+ 100,
+ false,
+ function( self ) print( "Spinner value changed to "..self.value ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:TextBox(
+ bounds,
+ "Name",
+ 32,
+ false,
+ function( self ) print( "Set text "..self.text ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:ColorBarAlpha(
+ bounds,
+ "",
+ 1.0
+ )
+ -----
+ bounds.y = bounds.y + gap
+ local valueBox = propertyList.gui:ValueBox(
+ Rect:new( bounds.x, bounds.y, 96, 20 ),
+ "Mana",
+ 0,
+ 0,
+ 100,
+ false,
+ function( self ) print( "ValueBox value changed to "..self.value ) end
+ )
+ valueBox.styles = {
+ { RL.VALUEBOX, RL.TEXT_PADDING, 2 },
+ { RL.VALUEBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT },
+ }
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:Label(
+ bounds,
+ "Label"
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:Line(
+ bounds,
+ "Divider"
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:Slider(
+ Rect:new( bounds.x + 38, bounds.y, bounds.width - 80, bounds.height ),
+ "min",
+ "max",
+ 0,
+ 0,
+ 100,
+ function( self ) print( "Changed value "..self.value ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:SliderBar(
+ Rect:new( bounds.x + 38, bounds.y, bounds.width - 80, bounds.height ),
+ "min",
+ "max",
+ 0,
+ 0,
+ 100,
+ function( self ) print( "Changed value "..self.value ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:ProgressBar(
+ Rect:new( bounds.x + 38, bounds.y, bounds.width - 80, bounds.height ),
+ "min",
+ "max",
+ 0,
+ 0,
+ 100,
+ function( self ) print( "Changed value "..self.value ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:ToggleGroup(
+ Rect:new( bounds.x, bounds.y, 64, bounds.height ),
+ "Cat;Dog;Car",
+ 0,
+ function( self ) print( self:getItem( self.active ) ) end
+ )
+ -----
+ bounds.y = bounds.y + gap
+ propertyList.gui:ColorPicker(
+ Rect:new( bounds.x, bounds.y, 128, 128 ),
+ "",
+ Color:new()
+ )
+
+ propertyList.content.height = bounds.y + 130
+ propertyList.gui:set2Top( dropdown )
+end
+
+function RL.init()
+ local monitor = 0
+ local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) )
+ local mSize = Vec2:new( RL.GetMonitorSize( monitor ) )
+
+ RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
+ RL.SetWindowState( RL.FLAG_VSYNC_HINT )
+ RL.SetWindowSize( winSize )
+ RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )
+
+ RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
+ RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 )
+ RL.GuiSetStyle( RL.SPINNER, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT )
+ RL.GuiSetStyle( RL.SPINNER, RL.TEXT_PADDING, 2 )
+
+ addSpriteButtons()
+ addPropertyList()
+end
+
+function RL.process( delta )
+ Gui:process()
+end
+
+function RL.draw()
+ RL.ClearBackground( { 50, 20, 75 } )
+ Gui:draw()
+end
diff --git a/examples/raygui_extensions/property_list.lua b/examples/raygui_extensions/property_list.lua
new file mode 100644
index 0000000..e05c84c
--- /dev/null
+++ b/examples/raygui_extensions/property_list.lua
@@ -0,0 +1,100 @@
+local PropertyList = {}
+PropertyList.__index = PropertyList
+
+function PropertyList:new( bounds, text, content, scroll, callback, grabCallback, dragCallback )
+ local object = setmetatable( {}, self )
+ object._parent = nil
+
+ object.bounds = bounds:clone()
+ object.text = text
+ object.content = content:clone()
+ object.scroll = scroll:clone()
+ object.view = Rect:new()
+ object.callback = callback
+ object.grabCallback = grabCallback
+ object.dragCallback = dragCallback
+
+ object.gui = Raygui:new() -- Contains full independent gui system.
+
+ -- Set initial view and scroll.
+ local _, scrollP, view = RL.GuiScrollPanel( object.bounds, object.text, object.content, object.scroll, object.view )
+ object.scroll = Vec2:new( scrollP )
+ object.view = Rect:new( view )
+
+ object.gui.view = Rect:new( 0, 0, object.view.width, object.view.height )
+ object.framebuffer = RL.LoadRenderTexture( { object.view.width, object.view.height } )
+
+ object.visible = true
+ object.disabled = false
+ object.draggable = true
+ object.mouseScale = 1
+
+ object:updateMouseOffset()
+
+ return object
+end
+
+function PropertyList:process()
+ if not RL.CheckCollisionRecs( self.view, RL.GetMousePosition() ) then
+ self.gui.locked = true
+ else
+ self.gui.locked = false
+ end
+
+ self.gui:process()
+
+ RL.BeginTextureMode( self.framebuffer )
+ RL.ClearBackground( RL.BLANK )
+ RL.rlTranslatef( { self.scroll.x, self.scroll.y, 0 } )
+ self.gui:draw()
+ RL.EndTextureMode()
+
+ return self._parent:drag( self )
+end
+
+function PropertyList:draw()
+ local oldScroll = self.scroll:clone()
+ local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
+
+ self.view = Rect:new( view )
+ self.scroll = Vec2:new( scroll )
+
+ if self.scroll ~= oldScroll then
+ self._parent:checkScrolling()
+
+ self.gui.view:set( -self.scroll.x, -self.scroll.y, self.view.width, self.view.height )
+ self:updateMouseOffset()
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
+ end
+
+ RL.DrawTexturePro(
+ RL.GetRenderTextureTexture( self.framebuffer ),
+ { 0, 0, self.view.width, -self.view.height },
+ { math.floor( self.view.x ), math.floor( self.view.y ), self.view.width, self.view.height },
+ { 0, 0 },
+ 0.0,
+ RL.WHITE
+ )
+end
+
+function PropertyList:updateMouseOffset()
+ self.gui.mouseOffset = Vec2:new( -self.view.x - self.scroll.x, -self.view.y - self.scroll.y ):scale( self.mouseScale )
+end
+
+function PropertyList:setPosition( pos )
+ self.bounds.x = pos.x
+ self.bounds.y = pos.y
+
+ self:updateMouseOffset()
+end
+
+function PropertyList:register( gui )
+ function gui:PropertyList( bounds, text, texture, nPatchNormal, nPatchPressed, callback )
+ return self:addElement( PropertyList:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback ) )
+ end
+end
+
+return PropertyList
diff --git a/examples/raygui_custom/spriteButton.lua b/examples/raygui_extensions/sprite_button.lua
index b37b208..57adc88 100644
--- a/examples/raygui_custom/spriteButton.lua
+++ b/examples/raygui_extensions/sprite_button.lua
@@ -1,4 +1,3 @@
---- Button control
local SpriteButton = {}
SpriteButton.__index = SpriteButton
@@ -24,7 +23,7 @@ function SpriteButton:process()
end
function SpriteButton:draw()
- if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self:process() then
+ if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self:process() and not RL.GuiIsLocked() and not self._parent.scrolling then
RL.DrawTextureNPatchRepeat( self.buttonTexture, self.nPatchPressed, self.bounds, { 0, 0 }, 0.0, RL.WHITE )
else
RL.DrawTextureNPatchRepeat( self.buttonTexture, self.nPatchNormal, self.bounds, { 0, 0 }, 0.0, RL.WHITE )
@@ -32,12 +31,9 @@ function SpriteButton:draw()
local result = RL.GuiLabelButton( self.bounds, self.text )
- if result == 1 then
- if self.callback ~= nil then
- self.callback( self )
- end
+ if result == 1 and self.callback ~= nil and self._parent:clickedInBounds( self.bounds ) then
+ self.callback( self )
end
-
end
function SpriteButton:setPosition( pos )
diff --git a/examples/raygui_lib/main.lua b/examples/raygui_lib/main.lua
index 0c3b559..1f20d7b 100644
--- a/examples/raygui_lib/main.lua
+++ b/examples/raygui_lib/main.lua
@@ -190,6 +190,7 @@ function RL.init()
}
windowbox.texture = texture
windowbox.textureRect = textureRect
+
local groupbox = Gui:GroupBox(
Rect:new( 400, 700, 256, 256 ),
"GroupBox"
@@ -211,7 +212,7 @@ function RL.init()
}
tabBar = Gui:GuiTabBar(
Rect:new( 700, 520, 700, 32 ),
- "Cat;Dog;Horse;Cow",
+ "Cat;Dog;Horse;Cow;Dog;Horse;Cow",
0,
nil,
closeTab
@@ -219,10 +220,10 @@ function RL.init()
local scrollpanel = Gui:ScrollPanel(
Rect:new( 800, 64, 256, 256 ),
"ScrollPanel",
- Rect:new( 0, 0, 256, 600 ),
+ Rect:new( 0, 0, 300, 600 ),
Vec2:new( 0, 0 ),
-- Callback.
- nil,
+ function( self ) print( self.scroll ) end,
-- Grab callback.
function( self ) Gui:set2Top( self ) end
)
diff --git a/examples/resources/lib/raygui.lua b/examples/resources/lib/raygui.lua
index d28e9d9..90c9bc7 100644
--- a/examples/resources/lib/raygui.lua
+++ b/examples/resources/lib/raygui.lua
@@ -76,8 +76,11 @@ end
function WindowBox:draw()
local result = RL.GuiWindowBox( self.bounds, self.text )
- if result == 1 and self.callback ~= nil then
- self.callback( self )
+ if result == 1 then
+ -- //TODO Could add self._parent:clickedInBounds( closeButtonBounds )
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
end
@@ -216,10 +219,17 @@ function GuiTabBar:draw()
result, self.active = RL.GuiTabBar( self.bounds, self.text, self.active )
- if self.active ~= oldActive and self.callback ~= nil then
- self.callback( self )
+ if self.active ~= oldActive then
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.active = oldActive
+ return
+ end
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
- if 0 <= result and self.closeCallback ~= nil then
+ if 0 <= result and self.closeCallback ~= nil and self._parent:clickedInBounds( self.bounds ) then
self.closeCallback( self, result )
end
end
@@ -268,7 +278,7 @@ function ScrollPanel:draw()
self.scroll = Vec2:new( scroll )
if self.scroll ~= oldScroll then
- self._parent.scrolling = true
+ self._parent:checkScrolling()
if self.callback ~= nil then
self.callback( self )
@@ -344,7 +354,7 @@ end
function Button:draw()
local result = RL.GuiButton( self.bounds, self.text )
- if result == 1 and self.callback ~= nil then
+ if result == 1 and self.callback ~= nil and self._parent:clickedInBounds( self.bounds ) then
self.callback( self )
end
end
@@ -381,7 +391,7 @@ end
function LabelButton:draw()
local result = RL.GuiLabelButton( self.bounds, self.text )
- if result == 1 and self.callback ~= nil then
+ if result == 1 and self.callback ~= nil and self._parent:clickedInBounds( self.bounds ) then
self.callback( self )
end
end
@@ -421,8 +431,15 @@ function Toggle:draw()
_, self.active = RL.GuiToggle( self.bounds, self.text, self.active )
- if self.active ~= oldActive and self.callback ~= nil then
- self.callback( self )
+ if self.active ~= oldActive then
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.active = oldActive
+ return
+ end
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
end
@@ -449,6 +466,7 @@ function ToggleGroup:new( bounds, text, active, callback )
object.visible = true
object.disabled = false
object.focusBounds = {}
+ object.viewBounds = bounds:clone()
object:updateFocusBounds()
return object
@@ -472,17 +490,20 @@ function ToggleGroup:updateFocusBounds()
local _, rowItemCounts = getItemCount( self.text )
self.focusBounds = {}
+ self.viewBounds = self.bounds:clone()
for y, rowItemCount in ipairs( rowItemCounts ) do
for x = 1, rowItemCount do
local pos = Vec2:new( x - 1, y - 1 )
-
- table.insert( self.focusBounds, Rect:new(
+ local focusBound = Rect:new(
self.bounds.x + pos.x * ( self.bounds.width + RL.GuiGetStyle( RL.TOGGLE, RL.GROUP_PADDING ) ),
self.bounds.y + pos.y * ( self.bounds.height + RL.GuiGetStyle( RL.TOGGLE, RL.GROUP_PADDING ) ),
self.bounds.width,
self.bounds.height
- ) )
+ )
+
+ table.insert( self.focusBounds, focusBound )
+ self.viewBounds = self.viewBounds:fit( focusBound )
end
end
end
@@ -502,8 +523,24 @@ function ToggleGroup:draw()
_, self.active = RL.GuiToggleGroup( self.bounds, self.text, self.active )
- if self.active ~= oldActive and self.callback ~= nil then
- self.callback( self )
+ if self.active ~= oldActive then
+ local inBounds = false
+
+ for _, bounds in ipairs( self.focusBounds ) do
+ if self._parent:clickedInBounds( bounds ) then
+ inBounds = true
+ break
+ end
+ end
+
+ if not inBounds then
+ self.active = oldActive
+ return
+ end
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
end
@@ -531,69 +568,42 @@ function CheckBox:new( bounds, text, checked, callback )
object.visible = true
object.disabled = false
+ object.textBounds = Rect:new()
object.focusBounds = bounds:clone()
- object:updateFocusBounds()
return object
end
function CheckBox:setText( text )
self.text = text
-
- self:updateFocusBounds()
-end
-
-function CheckBox:updateFocusBounds()
- if self.text == "" then
- return
- end
-
- local textSize = Vec2:new( RL.MeasureText(
- RL.GuiGetFont(),
- self.text,
- RL.GuiGetStyle( RL.DEFAULT, RL.TEXT_SIZE ),
- RL.GuiGetStyle( RL.DEFAULT, RL.TEXT_SPACING )
- ) )
-
- local textBounds = Rect:new()
-
- textBounds.width = textSize.x
- textBounds.height = textSize.y
- textBounds.x = self.bounds.x + self.bounds.width + RL.GuiGetStyle( RL.CHECKBOX, RL.TEXT_PADDING )
- textBounds.x = self.bounds.y + self.bounds.height / 2 - RL.GuiGetStyle( RL.CHECKBOX, RL.TEXT_SIZE ) / 2
-
- if RL.GuiGetStyle( RL.CHECKBOX, RL.TEXT_ALIGNMENT ) == RL.TEXT_ALIGN_LEFT then
- textBounds.x = self.bounds.x - textBounds.width - RL.GuiGetStyle( RL.CHECKBOX, RL.TEXT_PADDING )
- self.focusBounds.x = textBounds.x
- else
- self.focusBounds.x = self.bounds.x
- end
-
- self.focusBounds.y = self.bounds.y
- self.focusBounds.width = self.bounds.width + textBounds.width + RL.GuiGetStyle( RL.CHECKBOX, RL.TEXT_PADDING )
- self.focusBounds.height = self.bounds.height
end
function CheckBox:process()
+ self.focusBounds = self.bounds:fit( self.textBounds )
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.focusBounds )
end
function CheckBox:draw()
local oldChecked = self.checked
+ local textBounds = nil
- _, self.checked = RL.GuiCheckBox( self.bounds, self.text, self.checked )
+ _, self.checked, textBounds = RL.GuiCheckBox( self.bounds, self.text, self.checked )
+ self.textBounds:set( textBounds )
- if self.checked ~= oldChecked and self.callback ~= nil then
- self.callback( self )
+ if self.checked ~= oldChecked then
+ if not self._parent:clickedInBounds( self.focusBounds ) then
+ self.checked = oldChecked
+ end
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
- -- RL.DrawRectangleLines( self.focusBounds, RL.RED )
end
function CheckBox:setPosition( pos )
self.bounds.x = pos.x
self.bounds.y = pos.y
-
- self:updateFocusBounds()
end
-- ComboBox.
@@ -626,8 +636,15 @@ function ComboBox:draw()
_, self.active = RL.GuiComboBox( self.bounds, self.text, self.active )
- if self.active ~= oldActive and self.callback ~= nil then
- self.callback( self )
+ if self.active ~= oldActive then
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.active = oldActive
+ return
+ end
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
end
@@ -655,7 +672,7 @@ function DropdownBox:new( bounds, text, active, editMode, callback )
object.visible = true
object.disabled = false
object.editModeBounds = bounds:clone()
- object:updateFocusBounds()
+ object:updateEditModeBounds()
return object
end
@@ -663,14 +680,14 @@ end
function DropdownBox:setText( text )
self.text = text
- self:updateFocusBounds()
+ self:updateEditModeBounds()
end
function DropdownBox:getItem( id )
return getItems( self.text )[ id + 1 ]
end
-function DropdownBox:updateFocusBounds()
+function DropdownBox:updateEditModeBounds()
if self.text == "" then
return
end
@@ -715,39 +732,55 @@ local Spinner = {}
Spinner.__index = Spinner
function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callback )
- local object = setmetatable( {}, self )
+ local object = setmetatable( {}, self )
object._parent = nil
-
- object.bounds = bounds:clone()
- object.text = text
- object.value = value
- object.minValue = minValue
- object.maxValue = maxValue
- object.editMode = editMode
- object.callback = callback
-
+
+ object.bounds = bounds:clone()
+ object.text = text
+ object.value = value
+ object.minValue = minValue
+ object.maxValue = maxValue
+ object.editMode = editMode
+ object.callback = callback
+
object.visible = true
object.disabled = false
+ object.textBounds = Rect:new()
+ object.viewBounds = bounds:clone()
return object
end
+function Spinner:setText( text )
+ self.text = text
+end
+
function Spinner:process()
+ self.viewBounds = self.bounds:fit( self.textBounds )
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
end
function Spinner:draw()
local result = 0
local oldValue = self.value
+ local textBounds
- result, self.value = RL.GuiSpinner( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
+ result, self.value, textBounds = RL.GuiSpinner( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
+ self.textBounds:set( textBounds )
if result == 1 then
self._parent:editMode( self.editMode )
self.editMode = not self.editMode
end
- if self.value ~= oldValue and self.callback ~= nil then
- self.callback( self )
+ if self.value ~= oldValue then
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.value = oldValue
+ return
+ end
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
end
@@ -765,30 +798,39 @@ ValueBox.__index = ValueBox
function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callback )
local object = setmetatable( {}, self )
object._parent = nil
-
- object.bounds = bounds:clone()
- object.text = text
- object.value = value
- object.minValue = minValue
- object.maxValue = maxValue
- object.editMode = editMode
- object.callback = callback
-
+
+ object.bounds = bounds:clone()
+ object.text = text
+ object.value = value
+ object.minValue = minValue
+ object.maxValue = maxValue
+ object.editMode = editMode
+ object.callback = callback
+
object.visible = true
object.disabled = false
+ object.textBounds = Rect:new()
+ object.viewBounds = bounds:clone()
return object
end
+function ValueBox:setText( text )
+ self.text = text
+end
+
function ValueBox:process()
+ self.viewBounds = self.bounds:fit( self.textBounds )
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
end
function ValueBox:draw()
local result = 0
local oldValue = self.value
+ local textBounds
- result, self.value = RL.GuiValueBox( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
+ result, self.value, textBounds = RL.GuiValueBox( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
+ self.textBounds:set( textBounds )
if result == 1 then
self._parent:editMode( self.editMode )
@@ -867,32 +909,42 @@ Slider.__index = Slider
function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, callback )
local object = setmetatable( {}, self )
object._parent = nil
-
- object.bounds = bounds:clone()
- object.textLeft = textLeft
- object.textRight = textRight
- object.value = value
- object.minValue = minValue
- object.maxValue = maxValue
- object.callback = callback
-
+
+ object.bounds = bounds:clone()
+ object.textLeft = textLeft
+ object.textRight = textRight
+ object.value = value
+ object.minValue = minValue
+ object.maxValue = maxValue
+ object.callback = callback
+
object.visible = true
object.disabled = false
+ object.textLeftBounds = Rect:new()
+ object.textRightBounds = Rect:new()
+ object.viewBounds = bounds:clone()
return object
end
function Slider:process()
+ self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
end
function Slider:draw()
- local oldValue = self.value
+ local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil
- _, self.value = RL.GuiSlider( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
+ _, self.value, textLeftBounds, textRightBounds = RL.GuiSlider( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
+ self.textLeftBounds:set( textLeftBounds )
+ self.textRightBounds:set( textRightBounds )
if self.value ~= oldValue then
- self._parent.scrolling = true
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.value = oldValue
+ return
+ end
+ self._parent:checkScrolling()
if self.callback ~= nil then
self.callback( self )
@@ -925,26 +977,36 @@ function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue,
object.visible = true
object.disabled = false
+ object.textLeftBounds = Rect:new()
+ object.textRightBounds = Rect:new()
+ object.viewBounds = bounds:clone()
return object
end
function SliderBar:process()
+ self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
end
function SliderBar:draw()
- local oldValue = self.value
+ local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil
- _, self.value = RL.GuiSliderBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
+ _, self.value, textLeftBounds, textRightBounds = RL.GuiSliderBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
+ self.textLeftBounds:set( textLeftBounds )
+ self.textRightBounds:set( textRightBounds )
- if self.value ~= oldValue then
- self._parent.scrolling = true
+ if self.value ~= oldValue then
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.value = oldValue
+ return
+ end
+ self._parent:checkScrolling()
if self.callback ~= nil then
self.callback( self )
end
- end
+ end
end
function SliderBar:setPosition( pos )
@@ -972,21 +1034,34 @@ function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue
object.visible = true
object.disabled = false
+ object.textLeftBounds = Rect:new()
+ object.textRightBounds = Rect:new()
+ object.viewBounds = bounds:clone()
return object
end
function ProgressBar:process()
+ self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
end
function ProgressBar:draw()
- local oldValue = self.value
-
- _, self.value = RL.GuiProgressBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
+ local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil
+ _, self.value, textLeftBounds, textRightBounds = RL.GuiProgressBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
+ self.textLeftBounds:set( textLeftBounds )
+ self.textRightBounds:set( textRightBounds )
+
if self.value ~= oldValue then
- self.callback( self )
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.value = oldValue
+ return
+ end
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
end
@@ -1002,11 +1077,11 @@ local StatusBar = {}
StatusBar.__index = StatusBar
function StatusBar:new( bounds, text )
- local object = setmetatable( {}, self )
+ local object = setmetatable( {}, self )
object._parent = nil
- object.bounds = bounds:clone()
- object.text = text
+ object.bounds = bounds:clone()
+ object.text = text
object.visible = true
object.disabled = false
@@ -1034,7 +1109,7 @@ local DummyRec = {}
DummyRec.__index = DummyRec
function DummyRec:new( bounds, text )
- local object = setmetatable( {}, self )
+ local object = setmetatable( {}, self )
object._parent = nil
object.bounds = bounds:clone()
@@ -1144,7 +1219,7 @@ function ListView:draw()
_, self.scrollIndex, self.active = RL.GuiListView( self.bounds, self.text, self.scrollIndex, self.active )
if self.scrollIndex ~= oldScrollIndex then
- self._parent.scrolling = true
+ self._parent:checkScrolling()
end
if oldActive ~= self.active and self.callback ~= nil then
self.callback( self )
@@ -1194,7 +1269,7 @@ function ListViewEx:draw()
_, self.scrollIndex, self.active, self.focus = RL.GuiListViewEx( self.bounds, self.text, self.scrollIndex, self.active, self.focus )
if self.scrollIndex ~= oldScrollIndex then
- self._parent.scrolling = true
+ self._parent:checkScrolling()
end
if oldActive ~= self.active and self.callback ~= nil then
self.callback( self )
@@ -1243,7 +1318,7 @@ end
function MessageBox:draw()
self.buttonIndex = RL.GuiMessageBox( self.bounds, self.title, self.message, self.buttons )
- if 0 <= self.buttonIndex and self.callback ~= nil then
+ if 0 <= self.buttonIndex and self.callback ~= nil and self._parent:clickedInBounds( self.bounds ) then
self.callback( self )
end
end
@@ -1293,7 +1368,7 @@ end
function TextInputBox:draw()
self.buttonIndex, self.text, self.secretViewActive = RL.GuiTextInputBox( self.bounds, self.title, self.message, self.buttons, self.text, self.textMaxSize, self.secretViewActive )
- if 0 <= self.buttonIndex and self.callback ~= nil then
+ if 0 <= self.buttonIndex and self.callback ~= nil and self._parent:clickedInBounds( self.bounds ) then
self.callback( self )
end
end
@@ -1349,7 +1424,11 @@ function ColorPicker:draw()
self.color = Color:new( color )
if self.color ~= oldColor then
- self._parent.scrolling = true
+ if not self._parent:clickedInBounds( self.focusBounds ) then
+ self.color = oldColor
+ return
+ end
+ self._parent:checkScrolling()
if self.callback ~= nil then
self.callback( self )
@@ -1393,8 +1472,15 @@ function ColorPanel:draw()
self.color = Color:new( color )
- if oldColor ~= self.color and self.callback ~= nil then
- self.callback( self )
+ if oldColor ~= self.color then
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.color = oldColor
+ return
+ end
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
end
end
@@ -1433,7 +1519,11 @@ function ColorBarAlpha:draw()
_, self.alpha = RL.GuiColorBarAlpha( self.bounds, self.text, self.alpha )
if self.alpha ~= oldAlpha then
- self._parent.scrolling = true
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.alpha = oldAlpha
+ return
+ end
+ self._parent:checkScrolling()
if self.callback ~= nil then
self.callback( self )
@@ -1476,7 +1566,11 @@ function ColorBarHue:draw()
_, self.value = RL.GuiColorBarHue( self.bounds, self.text, self.value )
if self.value ~= oldValue then
- self._parent.scrolling = true
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.value = oldValue
+ return
+ end
+ self._parent:checkScrolling()
if self.callback ~= nil then
self.callback( self )
@@ -1521,7 +1615,11 @@ function GuiScrollBar:draw()
self.value = RL.GuiScrollBar( self.bounds, self.value, self.minValue, self.maxValue )
if self.value ~= oldValue then
- self._parent.scrolling = true
+ if not self._parent:clickedInBounds( self.bounds ) then
+ self.value = oldValue
+ return
+ end
+ self._parent:checkScrolling()
if self.callback ~= nil then
self.callback( self )
@@ -1553,14 +1651,22 @@ function Raygui:new()
object.scrolling = false
object.textEdit = false
object.defaultTexture = RL.GetTextureDefault()
- object.defaultRect = Rect:new( 0, 0, 1, 1 )
+ object.defaultRect = Rect:new( 0, 0, 1, 1 ) -- For texture.
+ object.mouseOffset = Vec2:new()
+ object.view = Rect:new() -- Active if larger than 0. Then only elements in view will be processed and drawn.
object._lastDisabled = false -- Last element disabled state in draw.
object._lastStyles = {}
+ object._mousePressPos = Vec2:new( -1, -1 ) -- Use to check if release and check are inside bounds.
return object
end
+function Raygui:inView( element )
+ -- CheckBox for example uses focusBounds and sliders viewBounds.
+ return self.view.width == 0 or self.view.height == 0 or self.view:checkCollisionRec( element.viewBounds or element.focusBounds or element.bounds )
+end
+
function Raygui:process()
if self.disabled or self.locked then
return
@@ -1568,24 +1674,28 @@ function Raygui:process()
-- If dragging, don't process element masking.
if self.dragging ~= nil then
self:drag( self.dragging )
-
return
end
+ -- Set mouse ofset if gui is for example embedded to some element.
+ RL.SetMouseOffset( self.mouseOffset )
+ if RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then
+ self._mousePressPos:set( RL.GetMousePosition() )
+ end
-- Focused is 0 if not over any element.
self.focused = 0
for i = #self.elements, 1, -1 do
local element = self.elements[i]
- if element.visible and element.process ~= nil then
+ if element.visible and element.process ~= nil and self:inView( element ) then
if element:process() then
self.focused = i
-
return
end
end
end
+ RL.SetMouseOffset( { 0, 0 } )
end
function Raygui:drag( element )
@@ -1644,12 +1754,15 @@ function Raygui:draw()
self.scrolling = false
end
end
+
+ RL.SetMouseOffset( self.mouseOffset )
+
for i, element in ipairs( self.elements ) do
if not self.locked and not self.disabled and i == self.focused then
RL.GuiUnlock()
end
- if element.visible and element.draw ~= nil then
+ if element.visible and element.draw ~= nil and self:inView( element ) then
if self._lastDisabled ~= element.disabled then
if element.disabled then
RL.GuiDisable()
@@ -1686,6 +1799,18 @@ function Raygui:draw()
end
RL.GuiUnlock()
RL.GuiEnable()
+ RL.SetMouseOffset( { 0, 0 } )
+end
+
+function Raygui:checkScrolling()
+ -- Don't set if scrolling with mouse wheel.
+ if RL.GetMouseWheelMove() == 0.0 then
+ self.scrolling = true
+ end
+end
+
+function Raygui:clickedInBounds( bounds )
+ return RL.CheckCollisionPointRec( self._mousePressPos, bounds )
end
function Raygui:set2Top( element )
diff --git a/include/raygui.h b/include/raygui.h
index 816cd94..f85bc58 100644
--- a/include/raygui.h
+++ b/include/raygui.h
@@ -716,17 +716,17 @@ RAYGUIAPI int GuiLabelButton(Rectangle bounds, const char *text);
RAYGUIAPI int GuiToggle(Rectangle bounds, const char *text, bool *active); // Toggle Button control, returns true when active
RAYGUIAPI int GuiToggleGroup(Rectangle bounds, const char *text, int *active); // Toggle Group control, returns active toggle index
RAYGUIAPI int GuiToggleSlider(Rectangle bounds, const char *text, int *active); // Toggle Slider control, returns true when clicked
-RAYGUIAPI int GuiCheckBox(Rectangle bounds, const char *text, bool *checked); // Check Box control, returns true when active
+RAYGUIAPI int GuiCheckBox(Rectangle bounds, const char *text, bool *checked, Rectangle *textBoundsReturn); // Check Box control, returns true when active
RAYGUIAPI int GuiComboBox(Rectangle bounds, const char *text, int *active); // Combo Box control, returns selected item index
RAYGUIAPI int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control, returns selected item
-RAYGUIAPI int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Spinner control, returns selected value
-RAYGUIAPI int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers
+RAYGUIAPI int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode, Rectangle *textBoundsReturn); // Spinner control, returns selected value
+RAYGUIAPI int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode, Rectangle *textBoundsReturn); // Value Box control, updates input text with numbers
RAYGUIAPI int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text
-RAYGUIAPI int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Slider control, returns selected value
-RAYGUIAPI int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Slider Bar control, returns selected value
-RAYGUIAPI int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Progress Bar control, shows current progress value
+RAYGUIAPI int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, Rectangle *textLeftBoundsPointer, Rectangle *textRightBoundsPointer); // Slider control, returns selected value
+RAYGUIAPI int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, Rectangle *textLeftBoundsPointer, Rectangle *textRightBoundsPointer); // Slider Bar control, returns selected value
+RAYGUIAPI int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, Rectangle *textLeftBoundsPointer, Rectangle *textRightBoundsPointer); // Progress Bar control, shows current progress value
RAYGUIAPI int GuiStatusBar(Rectangle bounds, const char *text); // Status Bar control, shows info text
RAYGUIAPI int GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders
RAYGUIAPI int GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs, Vector2 *mouseCell); // Grid control, returns mouse cell position
@@ -1702,19 +1702,14 @@ int GuiPanel(Rectangle bounds, const char *text)
// NOTE: Using GuiToggle() for the TABS
int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
{
- #define RAYGUI_TABBAR_ITEM_WIDTH 160
-
int result = -1;
//GuiState state = guiState;
- Rectangle tabBounds = { bounds.x, bounds.y, RAYGUI_TABBAR_ITEM_WIDTH, bounds.height };
-
if (*active < 0) *active = 0;
else if (*active > count - 1) *active = count - 1;
- int offsetX = 0; // Required in case tabs go out of screen
- offsetX = (*active + 2)*RAYGUI_TABBAR_ITEM_WIDTH - GetScreenWidth();
- if (offsetX < 0) offsetX = 0;
+ int padding = GuiGetStyle(TOGGLE, GROUP_PADDING);
+ Rectangle tabBounds = { bounds.x, bounds.y, ( bounds.width - padding * ( count - 1 ) ) / count, bounds.height };
bool toggle = false; // Required for individual toggles
@@ -1722,51 +1717,46 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
//--------------------------------------------------------------------
for (int i = 0; i < count; i++)
{
- tabBounds.x = bounds.x + (RAYGUI_TABBAR_ITEM_WIDTH + 4)*i - offsetX;
-
- if (tabBounds.x < GetScreenWidth())
- {
- // Draw tabs as toggle controls
- int textAlignment = GuiGetStyle(TOGGLE, TEXT_ALIGNMENT);
- int textPadding = GuiGetStyle(TOGGLE, TEXT_PADDING);
- GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
- GuiSetStyle(TOGGLE, TEXT_PADDING, 8);
-
- if (i == (*active))
- {
- toggle = true;
- // GuiToggle(tabBounds, GuiIconText(12, text[i]), &toggle);
- GuiToggle(tabBounds, text[i], &toggle);
- }
- else
- {
- toggle = false;
- // GuiToggle(tabBounds, GuiIconText(12, text[i]), &toggle);
- GuiToggle(tabBounds, text[i], &toggle);
- if (toggle) *active = i;
- }
-
- GuiSetStyle(TOGGLE, TEXT_PADDING, textPadding);
- GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, textAlignment);
-
- // Draw tab close button
- // NOTE: Only draw close button for current tab: if (CheckCollisionPointRec(mousePosition, tabBounds))
- int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
- int tempTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
- GuiSetStyle(BUTTON, BORDER_WIDTH, 1);
- GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
+ tabBounds.x = bounds.x + (tabBounds.width + padding)*i;
+
+ // Draw tabs as toggle controls
+ int textAlignment = GuiGetStyle(TOGGLE, TEXT_ALIGNMENT);
+ int textPadding = GuiGetStyle(TOGGLE, TEXT_PADDING);
+ GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
+ GuiSetStyle(TOGGLE, TEXT_PADDING, 8);
+
+ if (i == (*active))
+ {
+ toggle = true;
+ GuiToggle(tabBounds, text[i], &toggle);
+ }
+ else
+ {
+ toggle = false;
+ GuiToggle(tabBounds, text[i], &toggle);
+ if (toggle) *active = i;
+ }
+
+ GuiSetStyle(TOGGLE, TEXT_PADDING, textPadding);
+ GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, textAlignment);
+
+ // Draw tab close button
+ // NOTE: Only draw close button for current tab: if (CheckCollisionPointRec(mousePosition, tabBounds))
+ int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
+ int tempTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
+ GuiSetStyle(BUTTON, BORDER_WIDTH, 1);
+ GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
#if defined(RAYGUI_NO_ICONS)
- if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, "x")) result = i;
+ if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, "x")) result = i;
#else
- if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, GuiIconText(ICON_CROSS_SMALL, NULL))) result = i;
+ if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, GuiIconText(ICON_CROSS_SMALL, NULL))) result = i;
#endif
- GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
- GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
- }
+ GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
+ GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
}
// Draw tab-bar bottom line
- GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, bounds.width, 1 }, 0, BLANK, GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_NORMAL)));
+ GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, bounds.width - 1, 1 }, 0, BLANK, GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_NORMAL)));
//--------------------------------------------------------------------
return result; // Return as result the current TAB closing requested
@@ -2192,7 +2182,8 @@ int GuiToggleSlider(Rectangle bounds, const char *text, int *active)
}
// Check Box control, returns true when active
-int GuiCheckBox(Rectangle bounds, const char *text, bool *checked)
+// int GuiCheckBox(Rectangle bounds, const char *text, bool *checked)
+int GuiCheckBox(Rectangle bounds, const char *text, bool *checked, Rectangle *textBoundsReturn)
{
int result = 0;
GuiState state = guiState;
@@ -2251,6 +2242,7 @@ int GuiCheckBox(Rectangle bounds, const char *text, bool *checked)
GuiDrawText(text, textBounds, (GuiGetStyle(CHECKBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
//--------------------------------------------------------------------
+ *textBoundsReturn = textBounds;
return result;
}
@@ -2747,7 +2739,7 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int bufferSize, bool editMode
*/
// Spinner control, returns selected value
-int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode)
+int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode, Rectangle *textBoundsReturn)
{
int result = 1;
GuiState state = guiState;
@@ -2800,7 +2792,7 @@ int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int
// Draw control
//--------------------------------------------------------------------
- result = GuiValueBox(spinner, NULL, &tempValue, minValue, maxValue, editMode);
+ result = GuiValueBox(spinner, NULL, &tempValue, minValue, maxValue, editMode, NULL);
// Draw value selector custom buttons
// NOTE: BORDER_WIDTH and TEXT_ALIGNMENT forced values
@@ -2817,12 +2809,13 @@ int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int
//--------------------------------------------------------------------
*value = tempValue;
+ *textBoundsReturn = textBounds;
return result;
}
// Value Box control, updates input text with numbers
// NOTE: Requires static variables: frameCounter
-int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode)
+int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode, Rectangle *textBoundsReturn)
{
#if !defined(RAYGUI_VALUEBOX_MAX_CHARS)
#define RAYGUI_VALUEBOX_MAX_CHARS 32
@@ -2927,12 +2920,15 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
GuiDrawText(text, textBounds, (GuiGetStyle(VALUEBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
//--------------------------------------------------------------------
+ if ( textBoundsReturn != NULL ) {
+ *textBoundsReturn = textBounds;
+ }
return result;
}
// Slider control with pro parameters
// NOTE: Other GuiSlider*() controls use this one
-int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, int sliderWidth)
+int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, int sliderWidth, Rectangle *textLeftBoundsPointer, Rectangle *textRightBoundsPointer)
{
int result = 0;
GuiState state = guiState;
@@ -3035,6 +3031,7 @@ int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight,
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
+ *textLeftBoundsPointer = textBounds;
}
if (textRight != NULL)
@@ -3046,26 +3043,27 @@ int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight,
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
+ *textRightBoundsPointer = textBounds;
}
//--------------------------------------------------------------------
-
+
return result;
}
// Slider control extended, returns selected value and has text
-int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
+int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, Rectangle *textLeftBoundsPointer, Rectangle *textRightBoundsPointer)
{
- return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, GuiGetStyle(SLIDER, SLIDER_WIDTH));
+ return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, GuiGetStyle(SLIDER, SLIDER_WIDTH), textLeftBoundsPointer, textRightBoundsPointer);
}
// Slider Bar control extended, returns selected value
-int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
+int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, Rectangle *textLeftBoundsPointer, Rectangle *textRightBoundsPointer)
{
- return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, 0);
+ return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, 0, textLeftBoundsPointer, textRightBoundsPointer);
}
// Progress Bar control extended, shows current progress value
-int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
+int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, Rectangle *textLeftBoundsPointer, Rectangle *textRightBoundsPointer)
{
int result = 0;
GuiState state = guiState;
@@ -3126,6 +3124,7 @@ int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
+ *textLeftBoundsPointer = textBounds;
}
if (textRight != NULL)
@@ -3137,6 +3136,7 @@ int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
+ *textRightBoundsPointer = textBounds;
}
//--------------------------------------------------------------------
diff --git a/src/rgui.c b/src/rgui.c
index 46dfa49..87c7e02 100644
--- a/src/rgui.c
+++ b/src/rgui.c
@@ -547,20 +547,22 @@ int lguiGuiToggleSlider( lua_State *L ) {
}
/*
-> result, checked = RL.GuiCheckBox( Rectangle bounds, string text, bool checked )
+> result, checked, textBounds = RL.GuiCheckBox( Rectangle bounds, string text, bool checked )
Check Box control, returns true when active
-- Success return bool
+- Success return bool, Rectangle
*/
int lguiGuiCheckBox( lua_State *L ) {
Rectangle bounds = uluaGetRectangle( L, 1 );
bool checked = uluaGetBoolean( L, 3 );
- lua_pushinteger( L, GuiCheckBox( bounds, luaL_checkstring( L, 2 ), &checked ) );
+ Rectangle textBounds = {};
+ lua_pushinteger( L, GuiCheckBox( bounds, luaL_checkstring( L, 2 ), &checked, &textBounds ) );
lua_pushboolean( L, checked );
+ uluaPushRectangle( L, textBounds );
- return 2;
+ return 3;
}
/*
@@ -599,11 +601,11 @@ int lguiGuiDropdownBox( lua_State *L ) {
}
/*
-> result, value = RL.GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
+> result, value, textBounds = RL.GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
Spinner control, returns selected value
-- Success return int, int
+- Success return int, int, Rectangle
*/
int lguiGuiSpinner( lua_State *L ) {
Rectangle bounds = uluaGetRectangle( L, 1 );
@@ -612,18 +614,20 @@ int lguiGuiSpinner( lua_State *L ) {
int maxValue = luaL_checkinteger( L, 5 );
bool editMode = uluaGetBoolean( L, 6 );
- lua_pushinteger( L, GuiSpinner( bounds, luaL_checkstring( L, 2 ), &value, minValue, maxValue, editMode ) );
+ Rectangle textBounds = { 0 };
+ lua_pushinteger( L, GuiSpinner( bounds, luaL_checkstring( L, 2 ), &value, minValue, maxValue, editMode, &textBounds ) );
lua_pushinteger( L, value );
+ uluaPushRectangle( L, textBounds );
- return 2;
+ return 3;
}
/*
-> result, value = RL.GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
+> result, value, textBounds = RL.GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
Value Box control, updates input text with numbers
-- Success return int, int
+- Success return int, int, Rectangle
*/
int lguiGuiValueBox( lua_State *L ) {
Rectangle bounds = uluaGetRectangle( L, 1 );
@@ -632,10 +636,12 @@ int lguiGuiValueBox( lua_State *L ) {
int maxValue = luaL_checkinteger( L, 5 );
bool editMode = uluaGetBoolean( L, 6 );
- lua_pushinteger( L, GuiValueBox( bounds, luaL_checkstring( L, 2 ), &value, minValue, maxValue, editMode ) );
+ Rectangle textBounds = { 0 };
+ lua_pushinteger( L, GuiValueBox( bounds, luaL_checkstring( L, 2 ), &value, minValue, maxValue, editMode, &textBounds ) );
lua_pushinteger( L, value );
+ uluaPushRectangle( L, textBounds );
- return 2;
+ return 3;
}
/*
@@ -659,11 +665,11 @@ int lguiGuiTextBox( lua_State *L ) {
}
/*
-> result, value = RL.GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
+> result, value, textLeftBounds, textRightBounds = RL.GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Slider control, returns selected value
-- Success return int, float
+- Success return int, float, Rectangle, Rectangle
*/
int lguiGuiSlider( lua_State *L ) {
Rectangle bounds = uluaGetRectangle( L, 1 );
@@ -671,18 +677,22 @@ int lguiGuiSlider( lua_State *L ) {
float minValue = luaL_checknumber( L, 5 );
float maxValue = luaL_checknumber( L, 6 );
- lua_pushinteger( L, GuiSlider( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), &value, minValue, maxValue ) );
+ Rectangle textLeftBounds = { 0 };
+ Rectangle textRightBounds = { 0 };
+ lua_pushinteger( L, GuiSlider( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), &value, minValue, maxValue, &textLeftBounds, &textRightBounds ) );
lua_pushnumber( L, value );
+ uluaPushRectangle( L, textLeftBounds );
+ uluaPushRectangle( L, textRightBounds );
- return 2;
+ return 4;
}
/*
-> result, value = RL.GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
+> result, value, textLeftBounds, textRightBounds = RL.GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Slider Bar control, returns selected value
-- Success return int, float
+- Success return int, float, Rectangle, Rectangle
*/
int lguiGuiSliderBar( lua_State *L ) {
Rectangle bounds = uluaGetRectangle( L, 1 );
@@ -690,18 +700,22 @@ int lguiGuiSliderBar( lua_State *L ) {
float minValue = luaL_checknumber( L, 5 );
float maxValue = luaL_checknumber( L, 6 );
- lua_pushinteger( L, GuiSliderBar( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), &value, minValue, maxValue ) );
+ Rectangle textLeftBounds = { 0 };
+ Rectangle textRightBounds = { 0 };
+ lua_pushinteger( L, GuiSliderBar( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), &value, minValue, maxValue, &textLeftBounds, &textRightBounds ) );
lua_pushnumber( L, value );
+ uluaPushRectangle( L, textLeftBounds );
+ uluaPushRectangle( L, textRightBounds );
- return 2;
+ return 4;
}
/*
-> result, value = RL.GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
+> result, value, textLeftBounds, textRightBounds = RL.GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Progress Bar control, shows current progress value
-- Success return int, float
+- Success return int, float, Rectangle, Rectangle
*/
int lguiGuiProgressBar( lua_State *L ) {
Rectangle bounds = uluaGetRectangle( L, 1 );
@@ -709,10 +723,14 @@ int lguiGuiProgressBar( lua_State *L ) {
float minValue = luaL_checknumber( L, 5 );
float maxValue = luaL_checknumber( L, 6 );
- lua_pushinteger( L, GuiProgressBar( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), &value, minValue, maxValue ) );
+ Rectangle textLeftBounds = { 0 };
+ Rectangle textRightBounds = { 0 };
+ lua_pushinteger( L, GuiProgressBar( bounds, luaL_checkstring( L, 2 ), luaL_checkstring( L, 3 ), &value, minValue, maxValue, &textLeftBounds, &textRightBounds ) );
lua_pushnumber( L, value );
+ uluaPushRectangle( L, textLeftBounds );
+ uluaPushRectangle( L, textRightBounds );
- return 2;
+ return 4;
}
/*
diff --git a/src/text.c b/src/text.c
index d44e8c1..d93f240 100644
--- a/src/text.c
+++ b/src/text.c
@@ -416,7 +416,7 @@ int ltextGenImageFontAtlas( lua_State *L ) {
int packMethod = luaL_checkinteger( L, 4 );
int glyphCount = uluaGetTableLen( L, 1 );
- GlyphInfo glyphs[ glyphCount ];
+ GlyphInfo glyphs[ glyphCount ];
Rectangle *glyphRecs;
int t = 1;