Raygui lib enhancements and Raygui lib extensions example.
This commit is contained in:
28
API.md
28
API.md
@@ -6325,7 +6325,7 @@ Load font from Image (XNA style)
|
|||||||
|
|
||||||
> font = RL.LoadFontFromMemory( string fileType, Buffer fileData, int fontSize, int{} codepoints )
|
> 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
|
- Success return Font
|
||||||
|
|
||||||
@@ -6349,7 +6349,7 @@ Check if a font is ready
|
|||||||
|
|
||||||
> glyphs = RL.LoadFontData( Buffer fileData, int fontSize, int{} codepoints, int type )
|
> 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{}
|
- 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
|
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
|
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
|
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
|
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
|
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
|
Progress Bar control, shows current progress value
|
||||||
|
|
||||||
- Success return int, float
|
- Success return int, float, Rectangle, Rectangle
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -3673,7 +3673,7 @@ function RL.LoadFontEx( fileName, fontSize, codepoints ) end
|
|||||||
---@return any font
|
---@return any font
|
||||||
function RL.LoadFontFromImage( image, key, firstChar ) end
|
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
|
---- Success return Font
|
||||||
---@param fileType string
|
---@param fileType string
|
||||||
---@param fileData any
|
---@param fileData any
|
||||||
@@ -3694,7 +3694,7 @@ function RL.LoadFontFromData( fontData ) end
|
|||||||
---@return any isReady
|
---@return any isReady
|
||||||
function RL.IsFontReady( font ) end
|
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{}
|
---- Success return GlyphInfo{}
|
||||||
---@param fileData any
|
---@param fileData any
|
||||||
---@param fontSize integer
|
---@param fontSize integer
|
||||||
@@ -6001,12 +6001,13 @@ function RL.GuiToggleGroup( bounds, text, active ) end
|
|||||||
function RL.GuiToggleSlider( bounds, text, active ) end
|
function RL.GuiToggleSlider( bounds, text, active ) end
|
||||||
|
|
||||||
---Check Box control, returns true when active
|
---Check Box control, returns true when active
|
||||||
---- Success return bool
|
---- Success return bool, Rectangle
|
||||||
---@param bounds table
|
---@param bounds table
|
||||||
---@param text string
|
---@param text string
|
||||||
---@param checked boolean
|
---@param checked boolean
|
||||||
---@return any result
|
---@return any result
|
||||||
---@return any checked
|
---@return any checked
|
||||||
|
---@return any textBounds
|
||||||
function RL.GuiCheckBox( bounds, text, checked ) end
|
function RL.GuiCheckBox( bounds, text, checked ) end
|
||||||
|
|
||||||
---Combo Box control, returns selected item index
|
---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
|
function RL.GuiDropdownBox( bounds, text, active, editMode ) end
|
||||||
|
|
||||||
---Spinner control, returns selected value
|
---Spinner control, returns selected value
|
||||||
---- Success return int, int
|
---- Success return int, int, Rectangle
|
||||||
---@param bounds table
|
---@param bounds table
|
||||||
---@param text string
|
---@param text string
|
||||||
---@param value integer
|
---@param value integer
|
||||||
@@ -6038,10 +6039,11 @@ function RL.GuiDropdownBox( bounds, text, active, editMode ) end
|
|||||||
---@param editMode boolean
|
---@param editMode boolean
|
||||||
---@return any result
|
---@return any result
|
||||||
---@return any value
|
---@return any value
|
||||||
|
---@return any textBounds
|
||||||
function RL.GuiSpinner( bounds, text, value, minValue, maxValue, editMode ) end
|
function RL.GuiSpinner( bounds, text, value, minValue, maxValue, editMode ) end
|
||||||
|
|
||||||
---Value Box control, updates input text with numbers
|
---Value Box control, updates input text with numbers
|
||||||
---- Success return int, int
|
---- Success return int, int, Rectangle
|
||||||
---@param bounds table
|
---@param bounds table
|
||||||
---@param text string
|
---@param text string
|
||||||
---@param value integer
|
---@param value integer
|
||||||
@@ -6050,6 +6052,7 @@ function RL.GuiSpinner( bounds, text, value, minValue, maxValue, editMode ) end
|
|||||||
---@param editMode boolean
|
---@param editMode boolean
|
||||||
---@return any result
|
---@return any result
|
||||||
---@return any value
|
---@return any value
|
||||||
|
---@return any textBounds
|
||||||
function RL.GuiValueBox( bounds, text, value, minValue, maxValue, editMode ) end
|
function RL.GuiValueBox( bounds, text, value, minValue, maxValue, editMode ) end
|
||||||
|
|
||||||
---Text Box control, updates input text
|
---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
|
function RL.GuiTextBox( bounds, text, textSize, editMode ) end
|
||||||
|
|
||||||
---Slider control, returns selected value
|
---Slider control, returns selected value
|
||||||
---- Success return int, float
|
---- Success return int, float, Rectangle, Rectangle
|
||||||
---@param bounds table
|
---@param bounds table
|
||||||
---@param textLeft string
|
---@param textLeft string
|
||||||
---@param textRight string
|
---@param textRight string
|
||||||
@@ -6072,10 +6075,12 @@ function RL.GuiTextBox( bounds, text, textSize, editMode ) end
|
|||||||
---@param maxValue number
|
---@param maxValue number
|
||||||
---@return any result
|
---@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
|
function RL.GuiSlider( bounds, textLeft, textRight, value, minValue, maxValue ) end
|
||||||
|
|
||||||
---Slider Bar control, returns selected value
|
---Slider Bar control, returns selected value
|
||||||
---- Success return int, float
|
---- Success return int, float, Rectangle, Rectangle
|
||||||
---@param bounds table
|
---@param bounds table
|
||||||
---@param textLeft string
|
---@param textLeft string
|
||||||
---@param textRight string
|
---@param textRight string
|
||||||
@@ -6084,10 +6089,12 @@ function RL.GuiSlider( bounds, textLeft, textRight, value, minValue, maxValue )
|
|||||||
---@param maxValue number
|
---@param maxValue number
|
||||||
---@return any result
|
---@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
|
function RL.GuiSliderBar( bounds, textLeft, textRight, value, minValue, maxValue ) end
|
||||||
|
|
||||||
---Progress Bar control, shows current progress value
|
---Progress Bar control, shows current progress value
|
||||||
---- Success return int, float
|
---- Success return int, float, Rectangle, Rectangle
|
||||||
---@param bounds table
|
---@param bounds table
|
||||||
---@param textLeft string
|
---@param textLeft string
|
||||||
---@param textRight string
|
---@param textRight string
|
||||||
@@ -6096,6 +6103,8 @@ function RL.GuiSliderBar( bounds, textLeft, textRight, value, minValue, maxValue
|
|||||||
---@param maxValue number
|
---@param maxValue number
|
||||||
---@return any result
|
---@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
|
function RL.GuiProgressBar( bounds, textLeft, textRight, value, minValue, maxValue ) end
|
||||||
|
|
||||||
---Status Bar control, shows info text
|
---Status Bar control, shows info text
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ KEY CHANGES:
|
|||||||
- ADDED: Rest of font loading/unloading functions.
|
- ADDED: Rest of font loading/unloading functions.
|
||||||
- CHANGE: GlyphInfo type to userdata.
|
- CHANGE: GlyphInfo type to userdata.
|
||||||
- ADDED: GlyphInfo management functions.
|
- ADDED: GlyphInfo management functions.
|
||||||
|
- CHANGE: GuiTabBar works differently to raygui implementation.
|
||||||
|
- UPDATED: Raygui lib enhancements.
|
||||||
|
|
||||||
DETAILED CHANGES:
|
DETAILED CHANGES:
|
||||||
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
|
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
|
||||||
@@ -56,6 +58,8 @@ DETAILED CHANGES:
|
|||||||
- ADDED: GetImageData.
|
- ADDED: GetImageData.
|
||||||
- FIXED: CameraLib. Slow lateral movement.
|
- FIXED: CameraLib. Slow lateral movement.
|
||||||
- ADDED: GetGlyphInfoByIndex and GetGlyphAtlasRecByIndex.
|
- 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
|
Release: ReiLua version 0.6.0 Using Raylib 4.5
|
||||||
|
|||||||
@@ -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
|
|
||||||
229
examples/raygui_extensions/main.lua
Normal file
229
examples/raygui_extensions/main.lua
Normal file
@@ -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
|
||||||
100
examples/raygui_extensions/property_list.lua
Normal file
100
examples/raygui_extensions/property_list.lua
Normal file
@@ -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
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
--- Button control
|
|
||||||
local SpriteButton = {}
|
local SpriteButton = {}
|
||||||
SpriteButton.__index = SpriteButton
|
SpriteButton.__index = SpriteButton
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ function SpriteButton:process()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function SpriteButton:draw()
|
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 )
|
RL.DrawTextureNPatchRepeat( self.buttonTexture, self.nPatchPressed, self.bounds, { 0, 0 }, 0.0, RL.WHITE )
|
||||||
else
|
else
|
||||||
RL.DrawTextureNPatchRepeat( self.buttonTexture, self.nPatchNormal, self.bounds, { 0, 0 }, 0.0, RL.WHITE )
|
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 )
|
local result = RL.GuiLabelButton( self.bounds, self.text )
|
||||||
|
|
||||||
if result == 1 then
|
if result == 1 and self.callback ~= nil and self._parent:clickedInBounds( self.bounds ) then
|
||||||
if self.callback ~= nil then
|
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function SpriteButton:setPosition( pos )
|
function SpriteButton:setPosition( pos )
|
||||||
@@ -190,6 +190,7 @@ function RL.init()
|
|||||||
}
|
}
|
||||||
windowbox.texture = texture
|
windowbox.texture = texture
|
||||||
windowbox.textureRect = textureRect
|
windowbox.textureRect = textureRect
|
||||||
|
|
||||||
local groupbox = Gui:GroupBox(
|
local groupbox = Gui:GroupBox(
|
||||||
Rect:new( 400, 700, 256, 256 ),
|
Rect:new( 400, 700, 256, 256 ),
|
||||||
"GroupBox"
|
"GroupBox"
|
||||||
@@ -211,7 +212,7 @@ function RL.init()
|
|||||||
}
|
}
|
||||||
tabBar = Gui:GuiTabBar(
|
tabBar = Gui:GuiTabBar(
|
||||||
Rect:new( 700, 520, 700, 32 ),
|
Rect:new( 700, 520, 700, 32 ),
|
||||||
"Cat;Dog;Horse;Cow",
|
"Cat;Dog;Horse;Cow;Dog;Horse;Cow",
|
||||||
0,
|
0,
|
||||||
nil,
|
nil,
|
||||||
closeTab
|
closeTab
|
||||||
@@ -219,10 +220,10 @@ function RL.init()
|
|||||||
local scrollpanel = Gui:ScrollPanel(
|
local scrollpanel = Gui:ScrollPanel(
|
||||||
Rect:new( 800, 64, 256, 256 ),
|
Rect:new( 800, 64, 256, 256 ),
|
||||||
"ScrollPanel",
|
"ScrollPanel",
|
||||||
Rect:new( 0, 0, 256, 600 ),
|
Rect:new( 0, 0, 300, 600 ),
|
||||||
Vec2:new( 0, 0 ),
|
Vec2:new( 0, 0 ),
|
||||||
-- Callback.
|
-- Callback.
|
||||||
nil,
|
function( self ) print( self.scroll ) end,
|
||||||
-- Grab callback.
|
-- Grab callback.
|
||||||
function( self ) Gui:set2Top( self ) end
|
function( self ) Gui:set2Top( self ) end
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -76,9 +76,12 @@ end
|
|||||||
function WindowBox:draw()
|
function WindowBox:draw()
|
||||||
local result = RL.GuiWindowBox( self.bounds, self.text )
|
local result = RL.GuiWindowBox( self.bounds, self.text )
|
||||||
|
|
||||||
if result == 1 and self.callback ~= nil then
|
if result == 1 then
|
||||||
|
-- //TODO Could add self._parent:clickedInBounds( closeButtonBounds )
|
||||||
|
if self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function WindowBox:setPosition( pos )
|
function WindowBox:setPosition( pos )
|
||||||
@@ -216,10 +219,17 @@ function GuiTabBar:draw()
|
|||||||
|
|
||||||
result, self.active = RL.GuiTabBar( self.bounds, self.text, self.active )
|
result, self.active = RL.GuiTabBar( self.bounds, self.text, self.active )
|
||||||
|
|
||||||
if self.active ~= oldActive and self.callback ~= nil then
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
if 0 <= result and self.closeCallback ~= nil then
|
end
|
||||||
|
if 0 <= result and self.closeCallback ~= nil and self._parent:clickedInBounds( self.bounds ) then
|
||||||
self.closeCallback( self, result )
|
self.closeCallback( self, result )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -268,7 +278,7 @@ function ScrollPanel:draw()
|
|||||||
self.scroll = Vec2:new( scroll )
|
self.scroll = Vec2:new( scroll )
|
||||||
|
|
||||||
if self.scroll ~= oldScroll then
|
if self.scroll ~= oldScroll then
|
||||||
self._parent.scrolling = true
|
self._parent:checkScrolling()
|
||||||
|
|
||||||
if self.callback ~= nil then
|
if self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
@@ -344,7 +354,7 @@ end
|
|||||||
function Button:draw()
|
function Button:draw()
|
||||||
local result = RL.GuiButton( self.bounds, self.text )
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -381,7 +391,7 @@ end
|
|||||||
function LabelButton:draw()
|
function LabelButton:draw()
|
||||||
local result = RL.GuiLabelButton( self.bounds, self.text )
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -421,9 +431,16 @@ function Toggle:draw()
|
|||||||
|
|
||||||
_, self.active = RL.GuiToggle( self.bounds, self.text, self.active )
|
_, self.active = RL.GuiToggle( self.bounds, self.text, self.active )
|
||||||
|
|
||||||
if self.active ~= oldActive and self.callback ~= nil then
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Toggle:setPosition( pos )
|
function Toggle:setPosition( pos )
|
||||||
@@ -449,6 +466,7 @@ function ToggleGroup:new( bounds, text, active, callback )
|
|||||||
object.visible = true
|
object.visible = true
|
||||||
object.disabled = false
|
object.disabled = false
|
||||||
object.focusBounds = {}
|
object.focusBounds = {}
|
||||||
|
object.viewBounds = bounds:clone()
|
||||||
object:updateFocusBounds()
|
object:updateFocusBounds()
|
||||||
|
|
||||||
return object
|
return object
|
||||||
@@ -472,17 +490,20 @@ function ToggleGroup:updateFocusBounds()
|
|||||||
local _, rowItemCounts = getItemCount( self.text )
|
local _, rowItemCounts = getItemCount( self.text )
|
||||||
|
|
||||||
self.focusBounds = {}
|
self.focusBounds = {}
|
||||||
|
self.viewBounds = self.bounds:clone()
|
||||||
|
|
||||||
for y, rowItemCount in ipairs( rowItemCounts ) do
|
for y, rowItemCount in ipairs( rowItemCounts ) do
|
||||||
for x = 1, rowItemCount do
|
for x = 1, rowItemCount do
|
||||||
local pos = Vec2:new( x - 1, y - 1 )
|
local pos = Vec2:new( x - 1, y - 1 )
|
||||||
|
local focusBound = Rect:new(
|
||||||
table.insert( self.focusBounds, Rect:new(
|
|
||||||
self.bounds.x + pos.x * ( self.bounds.width + RL.GuiGetStyle( RL.TOGGLE, RL.GROUP_PADDING ) ),
|
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.y + pos.y * ( self.bounds.height + RL.GuiGetStyle( RL.TOGGLE, RL.GROUP_PADDING ) ),
|
||||||
self.bounds.width,
|
self.bounds.width,
|
||||||
self.bounds.height
|
self.bounds.height
|
||||||
) )
|
)
|
||||||
|
|
||||||
|
table.insert( self.focusBounds, focusBound )
|
||||||
|
self.viewBounds = self.viewBounds:fit( focusBound )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -502,9 +523,25 @@ function ToggleGroup:draw()
|
|||||||
|
|
||||||
_, self.active = RL.GuiToggleGroup( self.bounds, self.text, self.active )
|
_, self.active = RL.GuiToggleGroup( self.bounds, self.text, self.active )
|
||||||
|
|
||||||
if self.active ~= oldActive and self.callback ~= nil then
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ToggleGroup:setPosition( pos )
|
function ToggleGroup:setPosition( pos )
|
||||||
@@ -531,69 +568,42 @@ function CheckBox:new( bounds, text, checked, callback )
|
|||||||
|
|
||||||
object.visible = true
|
object.visible = true
|
||||||
object.disabled = false
|
object.disabled = false
|
||||||
|
object.textBounds = Rect:new()
|
||||||
object.focusBounds = bounds:clone()
|
object.focusBounds = bounds:clone()
|
||||||
object:updateFocusBounds()
|
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|
||||||
function CheckBox:setText( text )
|
function CheckBox:setText( text )
|
||||||
self.text = 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
|
end
|
||||||
|
|
||||||
function CheckBox:process()
|
function CheckBox:process()
|
||||||
|
self.focusBounds = self.bounds:fit( self.textBounds )
|
||||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.focusBounds )
|
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.focusBounds )
|
||||||
end
|
end
|
||||||
|
|
||||||
function CheckBox:draw()
|
function CheckBox:draw()
|
||||||
local oldChecked = self.checked
|
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
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
-- RL.DrawRectangleLines( self.focusBounds, RL.RED )
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function CheckBox:setPosition( pos )
|
function CheckBox:setPosition( pos )
|
||||||
self.bounds.x = pos.x
|
self.bounds.x = pos.x
|
||||||
self.bounds.y = pos.y
|
self.bounds.y = pos.y
|
||||||
|
|
||||||
self:updateFocusBounds()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ComboBox.
|
-- ComboBox.
|
||||||
@@ -626,9 +636,16 @@ function ComboBox:draw()
|
|||||||
|
|
||||||
_, self.active = RL.GuiComboBox( self.bounds, self.text, self.active )
|
_, self.active = RL.GuiComboBox( self.bounds, self.text, self.active )
|
||||||
|
|
||||||
if self.active ~= oldActive and self.callback ~= nil then
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ComboBox:setPosition( pos )
|
function ComboBox:setPosition( pos )
|
||||||
@@ -655,7 +672,7 @@ function DropdownBox:new( bounds, text, active, editMode, callback )
|
|||||||
object.visible = true
|
object.visible = true
|
||||||
object.disabled = false
|
object.disabled = false
|
||||||
object.editModeBounds = bounds:clone()
|
object.editModeBounds = bounds:clone()
|
||||||
object:updateFocusBounds()
|
object:updateEditModeBounds()
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
@@ -663,14 +680,14 @@ end
|
|||||||
function DropdownBox:setText( text )
|
function DropdownBox:setText( text )
|
||||||
self.text = text
|
self.text = text
|
||||||
|
|
||||||
self:updateFocusBounds()
|
self:updateEditModeBounds()
|
||||||
end
|
end
|
||||||
|
|
||||||
function DropdownBox:getItem( id )
|
function DropdownBox:getItem( id )
|
||||||
return getItems( self.text )[ id + 1 ]
|
return getItems( self.text )[ id + 1 ]
|
||||||
end
|
end
|
||||||
|
|
||||||
function DropdownBox:updateFocusBounds()
|
function DropdownBox:updateEditModeBounds()
|
||||||
if self.text == "" then
|
if self.text == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -728,27 +745,43 @@ function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callbac
|
|||||||
|
|
||||||
object.visible = true
|
object.visible = true
|
||||||
object.disabled = false
|
object.disabled = false
|
||||||
|
object.textBounds = Rect:new()
|
||||||
|
object.viewBounds = bounds:clone()
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Spinner:setText( text )
|
||||||
|
self.text = text
|
||||||
|
end
|
||||||
|
|
||||||
function Spinner:process()
|
function Spinner:process()
|
||||||
|
self.viewBounds = self.bounds:fit( self.textBounds )
|
||||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||||
end
|
end
|
||||||
|
|
||||||
function Spinner:draw()
|
function Spinner:draw()
|
||||||
local result = 0
|
local result = 0
|
||||||
local oldValue = self.value
|
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
|
if result == 1 then
|
||||||
self._parent:editMode( self.editMode )
|
self._parent:editMode( self.editMode )
|
||||||
self.editMode = not self.editMode
|
self.editMode = not self.editMode
|
||||||
end
|
end
|
||||||
if self.value ~= oldValue and self.callback ~= nil then
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Spinner:setPosition( pos )
|
function Spinner:setPosition( pos )
|
||||||
@@ -776,19 +809,28 @@ function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callba
|
|||||||
|
|
||||||
object.visible = true
|
object.visible = true
|
||||||
object.disabled = false
|
object.disabled = false
|
||||||
|
object.textBounds = Rect:new()
|
||||||
|
object.viewBounds = bounds:clone()
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ValueBox:setText( text )
|
||||||
|
self.text = text
|
||||||
|
end
|
||||||
|
|
||||||
function ValueBox:process()
|
function ValueBox:process()
|
||||||
|
self.viewBounds = self.bounds:fit( self.textBounds )
|
||||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||||
end
|
end
|
||||||
|
|
||||||
function ValueBox:draw()
|
function ValueBox:draw()
|
||||||
local result = 0
|
local result = 0
|
||||||
local oldValue = self.value
|
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
|
if result == 1 then
|
||||||
self._parent:editMode( self.editMode )
|
self._parent:editMode( self.editMode )
|
||||||
@@ -878,21 +920,31 @@ function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, cal
|
|||||||
|
|
||||||
object.visible = true
|
object.visible = true
|
||||||
object.disabled = false
|
object.disabled = false
|
||||||
|
object.textLeftBounds = Rect:new()
|
||||||
|
object.textRightBounds = Rect:new()
|
||||||
|
object.viewBounds = bounds:clone()
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|
||||||
function Slider:process()
|
function Slider:process()
|
||||||
|
self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
|
||||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||||
end
|
end
|
||||||
|
|
||||||
function Slider:draw()
|
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
|
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
|
if self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
@@ -925,21 +977,31 @@ function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue,
|
|||||||
|
|
||||||
object.visible = true
|
object.visible = true
|
||||||
object.disabled = false
|
object.disabled = false
|
||||||
|
object.textLeftBounds = Rect:new()
|
||||||
|
object.textRightBounds = Rect:new()
|
||||||
|
object.viewBounds = bounds:clone()
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|
||||||
function SliderBar:process()
|
function SliderBar:process()
|
||||||
|
self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
|
||||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||||
end
|
end
|
||||||
|
|
||||||
function SliderBar:draw()
|
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
|
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
|
if self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
@@ -972,22 +1034,35 @@ function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue
|
|||||||
|
|
||||||
object.visible = true
|
object.visible = true
|
||||||
object.disabled = false
|
object.disabled = false
|
||||||
|
object.textLeftBounds = Rect:new()
|
||||||
|
object.textRightBounds = Rect:new()
|
||||||
|
object.viewBounds = bounds:clone()
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|
||||||
function ProgressBar:process()
|
function ProgressBar:process()
|
||||||
|
self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
|
||||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||||
end
|
end
|
||||||
|
|
||||||
function ProgressBar:draw()
|
function ProgressBar:draw()
|
||||||
local oldValue = self.value
|
local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil
|
||||||
|
|
||||||
_, self.value = RL.GuiProgressBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
|
_, 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
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ProgressBar:setPosition( pos )
|
function ProgressBar:setPosition( pos )
|
||||||
@@ -1144,7 +1219,7 @@ function ListView:draw()
|
|||||||
_, self.scrollIndex, self.active = RL.GuiListView( self.bounds, self.text, self.scrollIndex, self.active )
|
_, self.scrollIndex, self.active = RL.GuiListView( self.bounds, self.text, self.scrollIndex, self.active )
|
||||||
|
|
||||||
if self.scrollIndex ~= oldScrollIndex then
|
if self.scrollIndex ~= oldScrollIndex then
|
||||||
self._parent.scrolling = true
|
self._parent:checkScrolling()
|
||||||
end
|
end
|
||||||
if oldActive ~= self.active and self.callback ~= nil then
|
if oldActive ~= self.active and self.callback ~= nil then
|
||||||
self.callback( self )
|
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 )
|
_, self.scrollIndex, self.active, self.focus = RL.GuiListViewEx( self.bounds, self.text, self.scrollIndex, self.active, self.focus )
|
||||||
|
|
||||||
if self.scrollIndex ~= oldScrollIndex then
|
if self.scrollIndex ~= oldScrollIndex then
|
||||||
self._parent.scrolling = true
|
self._parent:checkScrolling()
|
||||||
end
|
end
|
||||||
if oldActive ~= self.active and self.callback ~= nil then
|
if oldActive ~= self.active and self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
@@ -1243,7 +1318,7 @@ end
|
|||||||
function MessageBox:draw()
|
function MessageBox:draw()
|
||||||
self.buttonIndex = RL.GuiMessageBox( self.bounds, self.title, self.message, self.buttons )
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1293,7 +1368,7 @@ end
|
|||||||
function TextInputBox:draw()
|
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 )
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1349,7 +1424,11 @@ function ColorPicker:draw()
|
|||||||
self.color = Color:new( color )
|
self.color = Color:new( color )
|
||||||
|
|
||||||
if self.color ~= oldColor then
|
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
|
if self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
@@ -1393,9 +1472,16 @@ function ColorPanel:draw()
|
|||||||
|
|
||||||
self.color = Color:new( color )
|
self.color = Color:new( color )
|
||||||
|
|
||||||
if oldColor ~= self.color and self.callback ~= nil then
|
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 )
|
self.callback( self )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ColorPanel:setPosition( pos )
|
function ColorPanel:setPosition( pos )
|
||||||
@@ -1433,7 +1519,11 @@ function ColorBarAlpha:draw()
|
|||||||
_, self.alpha = RL.GuiColorBarAlpha( self.bounds, self.text, self.alpha )
|
_, self.alpha = RL.GuiColorBarAlpha( self.bounds, self.text, self.alpha )
|
||||||
|
|
||||||
if self.alpha ~= oldAlpha then
|
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
|
if self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
@@ -1476,7 +1566,11 @@ function ColorBarHue:draw()
|
|||||||
_, self.value = RL.GuiColorBarHue( self.bounds, self.text, self.value )
|
_, self.value = RL.GuiColorBarHue( self.bounds, self.text, self.value )
|
||||||
|
|
||||||
if self.value ~= oldValue then
|
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
|
if self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
@@ -1521,7 +1615,11 @@ function GuiScrollBar:draw()
|
|||||||
self.value = RL.GuiScrollBar( self.bounds, self.value, self.minValue, self.maxValue )
|
self.value = RL.GuiScrollBar( self.bounds, self.value, self.minValue, self.maxValue )
|
||||||
|
|
||||||
if self.value ~= oldValue then
|
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
|
if self.callback ~= nil then
|
||||||
self.callback( self )
|
self.callback( self )
|
||||||
@@ -1553,14 +1651,22 @@ function Raygui:new()
|
|||||||
object.scrolling = false
|
object.scrolling = false
|
||||||
object.textEdit = false
|
object.textEdit = false
|
||||||
object.defaultTexture = RL.GetTextureDefault()
|
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._lastDisabled = false -- Last element disabled state in draw.
|
||||||
object._lastStyles = {}
|
object._lastStyles = {}
|
||||||
|
object._mousePressPos = Vec2:new( -1, -1 ) -- Use to check if release and check are inside bounds.
|
||||||
|
|
||||||
return object
|
return object
|
||||||
end
|
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()
|
function Raygui:process()
|
||||||
if self.disabled or self.locked then
|
if self.disabled or self.locked then
|
||||||
return
|
return
|
||||||
@@ -1568,24 +1674,28 @@ function Raygui:process()
|
|||||||
-- If dragging, don't process element masking.
|
-- If dragging, don't process element masking.
|
||||||
if self.dragging ~= nil then
|
if self.dragging ~= nil then
|
||||||
self:drag( self.dragging )
|
self:drag( self.dragging )
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
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.
|
-- Focused is 0 if not over any element.
|
||||||
self.focused = 0
|
self.focused = 0
|
||||||
|
|
||||||
for i = #self.elements, 1, -1 do
|
for i = #self.elements, 1, -1 do
|
||||||
local element = self.elements[i]
|
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
|
if element:process() then
|
||||||
self.focused = i
|
self.focused = i
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
RL.SetMouseOffset( { 0, 0 } )
|
||||||
end
|
end
|
||||||
|
|
||||||
function Raygui:drag( element )
|
function Raygui:drag( element )
|
||||||
@@ -1644,12 +1754,15 @@ function Raygui:draw()
|
|||||||
self.scrolling = false
|
self.scrolling = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
RL.SetMouseOffset( self.mouseOffset )
|
||||||
|
|
||||||
for i, element in ipairs( self.elements ) do
|
for i, element in ipairs( self.elements ) do
|
||||||
if not self.locked and not self.disabled and i == self.focused then
|
if not self.locked and not self.disabled and i == self.focused then
|
||||||
RL.GuiUnlock()
|
RL.GuiUnlock()
|
||||||
end
|
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 self._lastDisabled ~= element.disabled then
|
||||||
if element.disabled then
|
if element.disabled then
|
||||||
RL.GuiDisable()
|
RL.GuiDisable()
|
||||||
@@ -1686,6 +1799,18 @@ function Raygui:draw()
|
|||||||
end
|
end
|
||||||
RL.GuiUnlock()
|
RL.GuiUnlock()
|
||||||
RL.GuiEnable()
|
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
|
end
|
||||||
|
|
||||||
function Raygui:set2Top( element )
|
function Raygui:set2Top( element )
|
||||||
|
|||||||
@@ -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 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 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 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 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 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 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); // Value Box control, updates input text with numbers
|
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 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 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); // Slider Bar 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); // Progress Bar control, shows current progress 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 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 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
|
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
|
// NOTE: Using GuiToggle() for the TABS
|
||||||
int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
|
int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
|
||||||
{
|
{
|
||||||
#define RAYGUI_TABBAR_ITEM_WIDTH 160
|
|
||||||
|
|
||||||
int result = -1;
|
int result = -1;
|
||||||
//GuiState state = guiState;
|
//GuiState state = guiState;
|
||||||
|
|
||||||
Rectangle tabBounds = { bounds.x, bounds.y, RAYGUI_TABBAR_ITEM_WIDTH, bounds.height };
|
|
||||||
|
|
||||||
if (*active < 0) *active = 0;
|
if (*active < 0) *active = 0;
|
||||||
else if (*active > count - 1) *active = count - 1;
|
else if (*active > count - 1) *active = count - 1;
|
||||||
|
|
||||||
int offsetX = 0; // Required in case tabs go out of screen
|
int padding = GuiGetStyle(TOGGLE, GROUP_PADDING);
|
||||||
offsetX = (*active + 2)*RAYGUI_TABBAR_ITEM_WIDTH - GetScreenWidth();
|
Rectangle tabBounds = { bounds.x, bounds.y, ( bounds.width - padding * ( count - 1 ) ) / count, bounds.height };
|
||||||
if (offsetX < 0) offsetX = 0;
|
|
||||||
|
|
||||||
bool toggle = false; // Required for individual toggles
|
bool toggle = false; // Required for individual toggles
|
||||||
|
|
||||||
@@ -1722,10 +1717,8 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
|
|||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
tabBounds.x = bounds.x + (RAYGUI_TABBAR_ITEM_WIDTH + 4)*i - offsetX;
|
tabBounds.x = bounds.x + (tabBounds.width + padding)*i;
|
||||||
|
|
||||||
if (tabBounds.x < GetScreenWidth())
|
|
||||||
{
|
|
||||||
// Draw tabs as toggle controls
|
// Draw tabs as toggle controls
|
||||||
int textAlignment = GuiGetStyle(TOGGLE, TEXT_ALIGNMENT);
|
int textAlignment = GuiGetStyle(TOGGLE, TEXT_ALIGNMENT);
|
||||||
int textPadding = GuiGetStyle(TOGGLE, TEXT_PADDING);
|
int textPadding = GuiGetStyle(TOGGLE, TEXT_PADDING);
|
||||||
@@ -1735,13 +1728,11 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
|
|||||||
if (i == (*active))
|
if (i == (*active))
|
||||||
{
|
{
|
||||||
toggle = true;
|
toggle = true;
|
||||||
// GuiToggle(tabBounds, GuiIconText(12, text[i]), &toggle);
|
|
||||||
GuiToggle(tabBounds, text[i], &toggle);
|
GuiToggle(tabBounds, text[i], &toggle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
toggle = false;
|
toggle = false;
|
||||||
// GuiToggle(tabBounds, GuiIconText(12, text[i]), &toggle);
|
|
||||||
GuiToggle(tabBounds, text[i], &toggle);
|
GuiToggle(tabBounds, text[i], &toggle);
|
||||||
if (toggle) *active = i;
|
if (toggle) *active = i;
|
||||||
}
|
}
|
||||||
@@ -1763,10 +1754,9 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
|
|||||||
GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
|
GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
|
||||||
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
|
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Draw tab-bar bottom line
|
// 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
|
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
|
// 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;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
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))));
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2747,7 +2739,7 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int bufferSize, bool editMode
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Spinner control, returns selected value
|
// 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;
|
int result = 1;
|
||||||
GuiState state = guiState;
|
GuiState state = guiState;
|
||||||
@@ -2800,7 +2792,7 @@ int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int
|
|||||||
|
|
||||||
// Draw control
|
// Draw control
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
result = GuiValueBox(spinner, NULL, &tempValue, minValue, maxValue, editMode);
|
result = GuiValueBox(spinner, NULL, &tempValue, minValue, maxValue, editMode, NULL);
|
||||||
|
|
||||||
// Draw value selector custom buttons
|
// Draw value selector custom buttons
|
||||||
// NOTE: BORDER_WIDTH and TEXT_ALIGNMENT forced values
|
// 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;
|
*value = tempValue;
|
||||||
|
*textBoundsReturn = textBounds;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value Box control, updates input text with numbers
|
// Value Box control, updates input text with numbers
|
||||||
// NOTE: Requires static variables: frameCounter
|
// 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)
|
#if !defined(RAYGUI_VALUEBOX_MAX_CHARS)
|
||||||
#define RAYGUI_VALUEBOX_MAX_CHARS 32
|
#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))));
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slider control with pro parameters
|
// Slider control with pro parameters
|
||||||
// NOTE: Other GuiSlider*() controls use this one
|
// 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;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
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;
|
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
|
||||||
|
|
||||||
GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
|
GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
|
||||||
|
*textLeftBoundsPointer = textBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textRight != NULL)
|
if (textRight != NULL)
|
||||||
@@ -3046,6 +3043,7 @@ int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight,
|
|||||||
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
|
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
|
||||||
|
|
||||||
GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
|
GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
|
||||||
|
*textRightBoundsPointer = textBounds;
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -3053,19 +3051,19 @@ int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slider control extended, returns selected value and has text
|
// 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
|
// 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
|
// 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;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
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;
|
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
|
||||||
|
|
||||||
GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
|
GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
|
||||||
|
*textLeftBoundsPointer = textBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textRight != NULL)
|
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;
|
textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
|
||||||
|
|
||||||
GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
|
GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
|
||||||
|
*textRightBoundsPointer = textBounds;
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
66
src/rgui.c
66
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
|
Check Box control, returns true when active
|
||||||
|
|
||||||
- Success return bool
|
- Success return bool, Rectangle
|
||||||
*/
|
*/
|
||||||
int lguiGuiCheckBox( lua_State *L ) {
|
int lguiGuiCheckBox( lua_State *L ) {
|
||||||
Rectangle bounds = uluaGetRectangle( L, 1 );
|
Rectangle bounds = uluaGetRectangle( L, 1 );
|
||||||
bool checked = uluaGetBoolean( L, 3 );
|
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 );
|
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
|
Spinner control, returns selected value
|
||||||
|
|
||||||
- Success return int, int
|
- Success return int, int, Rectangle
|
||||||
*/
|
*/
|
||||||
int lguiGuiSpinner( lua_State *L ) {
|
int lguiGuiSpinner( lua_State *L ) {
|
||||||
Rectangle bounds = uluaGetRectangle( L, 1 );
|
Rectangle bounds = uluaGetRectangle( L, 1 );
|
||||||
@@ -612,18 +614,20 @@ int lguiGuiSpinner( lua_State *L ) {
|
|||||||
int maxValue = luaL_checkinteger( L, 5 );
|
int maxValue = luaL_checkinteger( L, 5 );
|
||||||
bool editMode = uluaGetBoolean( L, 6 );
|
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 );
|
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
|
Value Box control, updates input text with numbers
|
||||||
|
|
||||||
- Success return int, int
|
- Success return int, int, Rectangle
|
||||||
*/
|
*/
|
||||||
int lguiGuiValueBox( lua_State *L ) {
|
int lguiGuiValueBox( lua_State *L ) {
|
||||||
Rectangle bounds = uluaGetRectangle( L, 1 );
|
Rectangle bounds = uluaGetRectangle( L, 1 );
|
||||||
@@ -632,10 +636,12 @@ int lguiGuiValueBox( lua_State *L ) {
|
|||||||
int maxValue = luaL_checkinteger( L, 5 );
|
int maxValue = luaL_checkinteger( L, 5 );
|
||||||
bool editMode = uluaGetBoolean( L, 6 );
|
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 );
|
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
|
Slider control, returns selected value
|
||||||
|
|
||||||
- Success return int, float
|
- Success return int, float, Rectangle, Rectangle
|
||||||
*/
|
*/
|
||||||
int lguiGuiSlider( lua_State *L ) {
|
int lguiGuiSlider( lua_State *L ) {
|
||||||
Rectangle bounds = uluaGetRectangle( L, 1 );
|
Rectangle bounds = uluaGetRectangle( L, 1 );
|
||||||
@@ -671,18 +677,22 @@ int lguiGuiSlider( lua_State *L ) {
|
|||||||
float minValue = luaL_checknumber( L, 5 );
|
float minValue = luaL_checknumber( L, 5 );
|
||||||
float maxValue = luaL_checknumber( L, 6 );
|
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 );
|
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
|
Slider Bar control, returns selected value
|
||||||
|
|
||||||
- Success return int, float
|
- Success return int, float, Rectangle, Rectangle
|
||||||
*/
|
*/
|
||||||
int lguiGuiSliderBar( lua_State *L ) {
|
int lguiGuiSliderBar( lua_State *L ) {
|
||||||
Rectangle bounds = uluaGetRectangle( L, 1 );
|
Rectangle bounds = uluaGetRectangle( L, 1 );
|
||||||
@@ -690,18 +700,22 @@ int lguiGuiSliderBar( lua_State *L ) {
|
|||||||
float minValue = luaL_checknumber( L, 5 );
|
float minValue = luaL_checknumber( L, 5 );
|
||||||
float maxValue = luaL_checknumber( L, 6 );
|
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 );
|
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
|
Progress Bar control, shows current progress value
|
||||||
|
|
||||||
- Success return int, float
|
- Success return int, float, Rectangle, Rectangle
|
||||||
*/
|
*/
|
||||||
int lguiGuiProgressBar( lua_State *L ) {
|
int lguiGuiProgressBar( lua_State *L ) {
|
||||||
Rectangle bounds = uluaGetRectangle( L, 1 );
|
Rectangle bounds = uluaGetRectangle( L, 1 );
|
||||||
@@ -709,10 +723,14 @@ int lguiGuiProgressBar( lua_State *L ) {
|
|||||||
float minValue = luaL_checknumber( L, 5 );
|
float minValue = luaL_checknumber( L, 5 );
|
||||||
float maxValue = luaL_checknumber( L, 6 );
|
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 );
|
lua_pushnumber( L, value );
|
||||||
|
uluaPushRectangle( L, textLeftBounds );
|
||||||
|
uluaPushRectangle( L, textRightBounds );
|
||||||
|
|
||||||
return 2;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user