Raygui wrapper library is now object based.

This commit is contained in:
jussi
2023-11-30 19:41:22 +02:00
parent aa03fffcb3
commit a5d40f7025
13 changed files with 717 additions and 417 deletions

View File

@@ -17,6 +17,7 @@ KEY CHANGES:
- ADDED: Platform specific API documentation generation. - ADDED: Platform specific API documentation generation.
- ADDED: Platform web. - ADDED: Platform web.
- ADDED: Raygui textures with SetShapesTexture. - ADDED: Raygui textures with SetShapesTexture.
- CHANGE: Raygui wrapper library is now object based. Possible to have multiple separated gui systems.
DETAILED CHANGES: DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic. - REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.

View File

@@ -1,4 +1,5 @@
Current { Current {
* Gui library to object based.
} }
Backlog { Backlog {

View File

@@ -1,4 +1,4 @@
Calculator = {} local Calculator = {}
Calculator.__index = Calculator Calculator.__index = Calculator
Calculator.OPERATIONS = { Calculator.OPERATIONS = {
@@ -13,7 +13,7 @@ Calculator.OPERATIONS = {
function Calculator:new( pos ) function Calculator:new( pos )
local object = setmetatable( {}, Calculator ) local object = setmetatable( {}, Calculator )
object.window = Raygui.WindowBox:new( object.window = Gui:WindowBox(
Rect:new( pos.x, pos.y, 188, 216 ), Rect:new( pos.x, pos.y, 188, 216 ),
"Calculator", "Calculator",
-- Close callback. -- Close callback.
@@ -23,7 +23,7 @@ function Calculator:new( pos )
-- Drag callback. -- Drag callback.
function( self ) object:setPosition( Vec2:new( self.bounds.x, self.bounds.y ) ) end function( self ) object:setPosition( Vec2:new( self.bounds.x, self.bounds.y ) ) end
) )
object.display = Raygui.Label:new( object.display = Gui:Label(
Rect:new( 0, 0, 180, 20 ), Rect:new( 0, 0, 180, 20 ),
"" ""
) )
@@ -54,7 +54,7 @@ function Calculator:new( pos )
local buttonSpacing = 6 local buttonSpacing = 6
for i, button in ipairs( buttons ) do for i, button in ipairs( buttons ) do
table.insert( object.buttons, Raygui.Button:new( table.insert( object.buttons, Gui:Button(
buttonRect:clone(), buttonRect:clone(),
button[1], button[1],
button[2] button[2]
@@ -139,11 +139,11 @@ function Calculator:setPosition( pos )
end end
function Calculator:set2Top() function Calculator:set2Top()
Raygui.set2Top( self.window ) Gui:set2Top( self.window )
Raygui.set2Top( self.display ) Gui:set2Top( self.display )
for _, button in ipairs( self.buttons ) do for _, button in ipairs( self.buttons ) do
Raygui.set2Top( button ) Gui:set2Top( button )
end end
end end
@@ -157,4 +157,4 @@ function Calculator:setVisible( visible )
end end
end end
return Calculator return Calculator

View File

@@ -9,6 +9,8 @@ Color = require( "color" )
Raygui = require( "raygui" ) Raygui = require( "raygui" )
Calculator = require( "calculator" ) Calculator = require( "calculator" )
Gui = Raygui:new()
local calculator = nil local calculator = nil
local calculator2 = nil local calculator2 = nil
@@ -32,11 +34,11 @@ function RL.init()
end end
function RL.process( delta ) function RL.process( delta )
Raygui:process() Gui:process()
end end
function RL.draw() function RL.draw()
RL.ClearBackground( RL.DARKBLUE ) RL.ClearBackground( RL.DARKBLUE )
Raygui:draw() Gui:draw()
end end

View File

@@ -6,6 +6,8 @@ Vec2 = require( "vector2" )
Color = require( "color" ) Color = require( "color" )
Raygui = require( "raygui" ) Raygui = require( "raygui" )
Gui = Raygui:new()
local grid = {} local grid = {}
local windowbox = {} local windowbox = {}
local tabBar = {} local tabBar = {}
@@ -17,7 +19,7 @@ local function closeTab( self, id )
local newText = "" local newText = ""
if #splits == 1 then if #splits == 1 then
Raygui.remove( tabBar ) Gui:remove( tabBar )
end end
table.remove( splits, id + 1 ) table.remove( splits, id + 1 )
@@ -50,24 +52,24 @@ function RL.init()
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) ) RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) )
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) ) RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) )
local label = Raygui.Label:new( local label = Gui:Label(
Rect:new( 16, 16, 64, 32 ), Rect:new( 16, 16, 64, 32 ),
"Cat" "Cat"
) )
local toggleGroup = Raygui.ToggleGroup:new( local toggleGroup = Gui:ToggleGroup(
Rect:new( 68, 16, 64, 32 ), Rect:new( 68, 16, 64, 32 ),
"Cat\nDog", "Cat\nDog",
0, 0,
function( self ) print( self:getItem( self.active ) ) end function( self ) print( self:getItem( self.active ) ) end
) )
local button = Raygui.Button:new( local button = Gui:Button(
Rect:new( 245, 188, 64, 32 ), Rect:new( 245, 188, 64, 32 ),
"Dog", "Dog",
function() toggleGroup:setText( "Dog;Cat\nEagle" ) end, function() toggleGroup:setText( "Dog;Cat\nEagle" ) end,
texture, texture,
textureRect textureRect
) )
local checkbox = Raygui.CheckBox:new( local checkbox = Gui:CheckBox(
Rect:new( 64, 128, 20, 20 ), Rect:new( 64, 128, 20, 20 ),
"Dog", "Dog",
false, false,
@@ -75,19 +77,19 @@ function RL.init()
texture, texture,
textureRect textureRect
) )
local combobox = Raygui.ComboBox:new( local combobox = Gui:ComboBox(
Rect:new( 64, 256, 128, 32 ), Rect:new( 64, 256, 128, 32 ),
"Dog\nCow\nDonkey", "Dog\nCow\nDonkey",
0 0
) )
local dropdownbox = Raygui.DropdownBox:new( local dropdownbox = Gui:DropdownBox(
Rect:new( 256, 128, 128, 32 ), Rect:new( 256, 128, 128, 32 ),
"Dog\nGiraffe\nLion\nHorse", "Dog\nGiraffe\nLion\nHorse",
0, 0,
false, false,
function( self ) print( self:getItem( self.active ) ) end function( self ) print( self:getItem( self.active ) ) end
) )
local spinner = Raygui.Spinner:new( local spinner = Gui:Spinner(
Rect:new( 464, 256, 128, 32 ), Rect:new( 464, 256, 128, 32 ),
"Health", "Health",
0, 0,
@@ -96,7 +98,7 @@ function RL.init()
false, false,
function( self ) print( "Spinner value changed to "..self.value ) end function( self ) print( "Spinner value changed to "..self.value ) end
) )
local valuebox = Raygui.ValueBox:new( local valuebox = Gui:ValueBox(
Rect:new( 464, 316, 128, 32 ), Rect:new( 464, 316, 128, 32 ),
"Health", "Health",
0, 0,
@@ -105,21 +107,21 @@ function RL.init()
false, false,
function( self ) print( "ValueBox value changed to "..self.value ) end function( self ) print( "ValueBox value changed to "..self.value ) end
) )
local textbox = Raygui.TextBox:new( local textbox = Gui:TextBox(
Rect:new( 32, 316, 256, 32 ), Rect:new( 32, 316, 256, 32 ),
"Name", "Name",
32, 32,
false, false,
function( self ) print( "Set text "..self.text ) end function( self ) print( "Set text "..self.text ) end
) )
local textbox2 = Raygui.TextBox:new( local textbox2 = Gui:TextBox(
Rect:new( 32, 380, 256, 32 ), Rect:new( 32, 380, 256, 32 ),
"Name", "Name",
32, 32,
false, false,
function( self ) print( "Set text "..self.text ) end function( self ) print( "Set text "..self.text ) end
) )
local slider = Raygui.Slider:new( local slider = Gui:Slider(
Rect:new( 50, 500, 256, 32 ), Rect:new( 50, 500, 256, 32 ),
"min", "min",
"max", "max",
@@ -130,7 +132,7 @@ function RL.init()
texture, texture,
textureRect textureRect
) )
local sliderbar = Raygui.SliderBar:new( local sliderbar = Gui:SliderBar(
Rect:new( 50, 550, 256, 32 ), Rect:new( 50, 550, 256, 32 ),
"min", "min",
"max", "max",
@@ -138,9 +140,8 @@ function RL.init()
0, 0,
100, 100,
function( self ) print( "Changed value "..self.value ) end function( self ) print( "Changed value "..self.value ) end
) )
local progressbar = Raygui.ProgressBar:new( local progressbar = Gui:ProgressBar(
Rect:new( 50, 600, 256, 32 ), Rect:new( 50, 600, 256, 32 ),
"min", "min",
"max", "max",
@@ -149,56 +150,56 @@ function RL.init()
100, 100,
function( self ) print( "Changed value "..self.value ) end function( self ) print( "Changed value "..self.value ) end
) )
local statusbar = Raygui.StatusBar:new( local statusbar = Gui:StatusBar(
Rect:new( 50, 650, 256, 32 ), Rect:new( 50, 650, 256, 32 ),
"StatusBar" "StatusBar"
) )
local dummyrec = Raygui.DummyRec:new( local dummyrec = Gui:DummyRec(
Rect:new( 50, 700, 256, 32 ), Rect:new( 50, 700, 256, 32 ),
"DummyRec" "DummyRec"
) )
grid = Raygui.Grid:new( grid = Gui:Grid(
Rect:new( 400, 400, 256, 256 ), Rect:new( 400, 400, 256, 256 ),
"Grid", "Grid",
32, 32,
2 2
) )
windowbox = Raygui.WindowBox:new( windowbox = Gui:WindowBox(
Rect:new( 720, 250, 256, 256 ), Rect:new( 720, 250, 256, 256 ),
"WindowBox", "WindowBox",
-- Close callback. -- Close callback.
function( self ) self.visible = false end, function( self ) self.visible = false end,
-- Grab callback. -- Grab callback.
function( self ) Raygui.set2Top( self ) end, function( self ) Gui:set2Top( self ) end,
nil, nil,
texture, texture,
textureRect textureRect
) )
local groupbox = Raygui.GroupBox:new( local groupbox = Gui:GroupBox(
Rect:new( 400, 700, 256, 256 ), Rect:new( 400, 700, 256, 256 ),
"GroupBox" "GroupBox"
) )
local line = Raygui.Line:new( local line = Gui:Line(
Rect:new( 400, 32, 256, 16 ), Rect:new( 400, 32, 256, 16 ),
"Line" "Line"
) )
local panel = Raygui.Panel:new( local panel = Gui:Panel(
Rect:new( 400, 64, 256, 128 ), Rect:new( 400, 64, 256, 128 ),
"Panel", "Panel",
-- Grab callback. -- Grab callback.
function( self ) Raygui.set2Top( self ) end function( self ) Gui:set2Top( self ) end
) )
tabBar = Raygui.GuiTabBar:new( tabBar = Gui:GuiTabBar(
Rect:new( 700, 520, 700, 32 ), Rect:new( 700, 520, 700, 32 ),
"Cat;Dog;Horse;Cow", "Cat;Dog;Horse;Cow",
0, 0,
-- function( self ) Raygui.set2Top( self ) end -- function( self ) Gui:set2Top( self ) end
nil, nil,
closeTab, closeTab,
texture, texture,
textureRect textureRect
) )
local scrollpanel = Raygui.ScrollPanel:new( 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, 256, 600 ),
@@ -206,19 +207,17 @@ function RL.init()
-- Callback. -- Callback.
nil, nil,
-- Grab callback. -- Grab callback.
function( self ) Raygui.set2Top( self ) end function( self ) Gui:set2Top( self ) end
) )
local listview = Raygui.ListView:new( local listview = Gui:ListView(
Rect:new( 1100, 64, 128, 80 ), Rect:new( 1100, 64, 128, 128 ),
"Cat;Dog;Horse;Cow;Pig;Eagle;Lion", "Cat;Dog;Horse;Cow;Pig;Eagle;Lion",
0, 0,
0, 0,
function( self ) print( self:getItem( self.active ) ) end, function( self ) print( self:getItem( self.active ) ) end
texture,
textureRect
) )
local listviewex = Raygui.ListViewEx:new( local listviewex = Gui:ListViewEx(
Rect:new( 1300, 64, 128, 80 ), Rect:new( 1300, 64, 128, 128 ),
"Cat;Dog;Horse;Cow;Pig;Eagle;Lion", "Cat;Dog;Horse;Cow;Pig;Eagle;Lion",
0, 0,
0, 0,
@@ -227,7 +226,7 @@ function RL.init()
texture, texture,
textureRect textureRect
) )
local messagebox = Raygui.MessageBox:new( local messagebox = Gui:MessageBox(
Rect:new( 1100, 150, 300, 128 ), Rect:new( 1100, 150, 300, 128 ),
"Title", "Title",
"Message", "Message",
@@ -237,16 +236,16 @@ function RL.init()
print( "You pressed "..self:getItem( self.buttonIndex ) ) print( "You pressed "..self:getItem( self.buttonIndex ) )
if self.buttonIndex == 1 then if self.buttonIndex == 1 then
Raygui.set2Back( windowbox ) Gui:set2Back( windowbox )
elseif self.buttonIndex == 2 then elseif self.buttonIndex == 2 then
Raygui.set2Top( windowbox ) Gui:set2Top( windowbox )
end end
end end
end, end,
-- Grab callback. -- Grab callback.
function( self ) Raygui.set2Top( self ) end function( self ) Gui:set2Top( self ) end
) )
local textinputbox = Raygui.TextInputBox:new( local textinputbox = Gui:TextInputBox(
Rect:new( 1100, 300, 300, 128 ), Rect:new( 1100, 300, 300, 128 ),
"Title", "Title",
"Message", "Message",
@@ -260,24 +259,24 @@ function RL.init()
end end
end, end,
-- Grab callback. -- Grab callback.
function( self ) Raygui.set2Top( self ) end function( self ) Gui:set2Top( self ) end
) )
local colorpicker = Raygui.ColorPicker:new( local colorpicker = Gui:ColorPicker(
Rect:new( 1500, 32, 128, 128 ), Rect:new( 1500, 32, 128, 128 ),
"Color Picker", "Color Picker",
Color:new() Color:new()
) )
local colorpanel = Raygui.ColorPanel:new( local colorpanel = Gui:ColorPanel(
Rect:new( 1700, 32, 128, 128 ), Rect:new( 1700, 32, 128, 128 ),
"Color Panel", "Color Panel",
Color:new() Color:new()
) )
local colorbaralpha = Raygui.ColorBarAlpha:new( local colorbaralpha = Gui:ColorBarAlpha(
Rect:new( 1700, 180, 128, 20 ), Rect:new( 1700, 180, 128, 20 ),
"Color Panel", "Color Panel",
1.0 1.0
) )
local colorbarhue = Raygui.ColorBarHue:new( local colorbarhue = Gui:ColorBarHue(
Rect:new( 1840, 32, 20, 128 ), Rect:new( 1840, 32, 20, 128 ),
"Color Panel", "Color Panel",
1.0 1.0
@@ -285,7 +284,7 @@ function RL.init()
end end
function RL.process( delta ) function RL.process( delta )
Raygui.process() Gui:process()
end end
function RL.draw() function RL.draw()
@@ -302,6 +301,5 @@ function RL.draw()
RL.GREEN RL.GREEN
) )
end end
Gui:draw()
Raygui.draw()
end end

View File

@@ -5,7 +5,7 @@ end
local Vector3 = require( "vector3" ) local Vector3 = require( "vector3" )
Color = {} local Color = {}
Color.meta = { Color.meta = {
__index = Color, __index = Color,
__tostring = function( c ) __tostring = function( c )

View File

@@ -1,19 +1,9 @@
Util = require( "utillib" ) local Util = require( "utillib" )
Rect = require( "rectangle" ) local Rect = require( "rectangle" )
Vec2 = require( "vector2" ) local Vec2 = require( "vector2" )
Color = require( "color" ) local Color = require( "color" )
--[[ local Gui = {
To add repeat inputs to the keys pressed buffer, you could add GLFW_REPEAT in railib rcore.c in function "KeyCallback" by changing:
if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && (action == GLFW_PRESS))
To
if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && (action == GLFW_PRESS || action == GLFW_REPEAT))
Now GLFW_REPEAT can be read by "RL.GetKeyPressed".
]]
Gui = {
ALING = { ALING = {
NONE = 0, NONE = 0,
LEFT = 1, LEFT = 1,

View File

@@ -22,7 +22,7 @@ local function deepCopy( orig )
return copy return copy
end end
Matrix = {} local Matrix = {}
Matrix.meta = { Matrix.meta = {
__index = Matrix, __index = Matrix,
__tostring = function( m ) __tostring = function( m )

View File

@@ -6,7 +6,7 @@ end
local Vector3 = require( "vector3" ) local Vector3 = require( "vector3" )
local Matrix = require( "matrix" ) local Matrix = require( "matrix" )
Quaternion = {} local Quaternion = {}
Quaternion.meta = { Quaternion.meta = {
__index = Quaternion, __index = Quaternion,
__tostring = function( q ) __tostring = function( q )

File diff suppressed because it is too large Load Diff

View File

@@ -5,8 +5,7 @@ end
local Vector2 = require( "vector2" ) local Vector2 = require( "vector2" )
Rectangle = {} local Rectangle = {}
Rectangle.meta = { Rectangle.meta = {
__index = Rectangle, __index = Rectangle,
__tostring = function( r ) __tostring = function( r )

View File

@@ -3,7 +3,7 @@ if table.unpack == nil then
table.unpack = unpack table.unpack = unpack
end end
Vector2 = {} local Vector2 = {}
Vector2.meta = { Vector2.meta = {
__index = Vector2, __index = Vector2,
__tostring = function( v ) __tostring = function( v )

View File

@@ -5,7 +5,7 @@ end
local Vector2 = require( "vector2" ) local Vector2 = require( "vector2" )
Vector3 = {} local Vector3 = {}
Vector3.meta = { Vector3.meta = {
__index = Vector3, __index = Vector3,
__tostring = function( v ) __tostring = function( v )