Raygui lib callbacks to single table.

This commit is contained in:
jussi
2024-03-21 23:18:35 +02:00
parent a7528da4eb
commit 95f03bae31
10 changed files with 568 additions and 533 deletions

View File

@@ -5,6 +5,7 @@ KEY CHANGES:
- CHANGE: Process renamed to update to be more inline with naming of raylib and common convention. - CHANGE: Process renamed to update to be more inline with naming of raylib and common convention.
- ADDED: apiScanner.lua for searching unimplemented functions from raylib. - ADDED: apiScanner.lua for searching unimplemented functions from raylib.
- ADDED Automation events. - ADDED Automation events.
- CHANGE: Raygui lib callbacks to single table.
DETAILED CHANGES: DETAILED CHANGES:
- ADDED: GetBufferElementSize and GetBufferLength. - ADDED: GetBufferElementSize and GetBufferLength.

View File

@@ -3,7 +3,7 @@ Current {
Backlog { Backlog {
* Raygui * Raygui
* Set callbacks to single table. * File browser.
* Raygui lib * Raygui lib
* Check if could remove flickering from changing draw order by making queue for order * Check if could remove flickering from changing draw order by making queue for order
changing and only change them after everything is drawn. changing and only change them after everything is drawn.

View File

@@ -16,12 +16,11 @@ function Calculator:new( pos )
object.window = Gui:WindowBox( object.window = Gui:WindowBox(
Rect:new( pos.x, pos.y, 188, 216 ), Rect:new( pos.x, pos.y, 188, 216 ),
"Calculator", "Calculator",
-- Close callback. { -- Callbacks.
function() object:setVisible( false ) end, close = function() object:setVisible( false ) end,
-- Grab callback. grab = function() object:set2Top() end,
function() object:set2Top() end, drag = function( self ) object:setPosition( Vec2:new( self.bounds.x, self.bounds.y ) ) end
-- Drag callback. }
function( self ) object:setPosition( Vec2:new( self.bounds.x, self.bounds.y ) ) end
) )
object.display = Gui:Label( object.display = Gui:Label(
Rect:new( 0, 0, 180, 20 ), Rect:new( 0, 0, 180, 20 ),
@@ -31,22 +30,22 @@ function Calculator:new( pos )
object.buttons = {} object.buttons = {}
local buttons = { local buttons = {
{ "7", function() object:addNumber( 7 ) end }, { "7", { pressed = function() object:addNumber( 7 ) end } },
{ "8", function() object:addNumber( 8 ) end }, { "8", { pressed = function() object:addNumber( 8 ) end } },
{ "9", function() object:addNumber( 9 ) end }, { "9", { pressed = function() object:addNumber( 9 ) end } },
{ "/", function() object:addOperation( self.OPERATIONS.DIV ) end }, { "/", { pressed = function() object:addOperation( self.OPERATIONS.DIV ) end } },
{ "4", function() object:addNumber( 4 ) end }, { "4", { pressed = function() object:addNumber( 4 ) end } },
{ "5", function() object:addNumber( 5 ) end }, { "5", { pressed = function() object:addNumber( 5 ) end } },
{ "6", function() object:addNumber( 6 ) end }, { "6", { pressed = function() object:addNumber( 6 ) end } },
{ "*", function() object:addOperation( self.OPERATIONS.MUL ) end }, { "*", { pressed = function() object:addOperation( self.OPERATIONS.MUL ) end } },
{ "1", function() object:addNumber( 1 ) end }, { "1", { pressed = function() object:addNumber( 1 ) end } },
{ "2", function() object:addNumber( 2 ) end }, { "2", { pressed = function() object:addNumber( 2 ) end } },
{ "3", function() object:addNumber( 3 ) end }, { "3", { pressed = function() object:addNumber( 3 ) end } },
{ "-", function() object:addOperation( self.OPERATIONS.SUB ) end }, { "-", { pressed = function() object:addOperation( self.OPERATIONS.SUB ) end } },
{ "0", function() object:addNumber( 0 ) end }, { "0", { pressed = function() object:addNumber( 0 ) end } },
{ "C", function() object:addOperation( self.OPERATIONS.CLEAR ) end }, { "C", { pressed = function() object:addOperation( self.OPERATIONS.CLEAR ) end } },
{ "=", function() object:addOperation( self.OPERATIONS.EQUAL ) end }, { "=", { pressed = function() object:addOperation( self.OPERATIONS.EQUAL ) end } },
{ "+", function() object:addOperation( self.OPERATIONS.ADD ) end }, { "+", { pressed = function() object:addOperation( self.OPERATIONS.ADD ) end } },
} }
local rowCount = 4 local rowCount = 4
local buttonRect = Rect:new( 5, 64, 40, 32 ) local buttonRect = Rect:new( 5, 64, 40, 32 )

View File

@@ -55,13 +55,13 @@ local function addSpriteButtons()
local buttonSize = Vec2:new( 216, 32 ) local buttonSize = Vec2:new( 216, 32 )
local bounds = Rect:new( winSize.x / 2 - buttonSize.x / 2, 200, 216, 32 ) local bounds = Rect:new( winSize.x / 2 - buttonSize.x / 2, 200, 216, 32 )
local gap = buttonSize.y + 2 local gap = buttonSize.y + 2
addButton( bounds, "Start New Game", function() print( "New Game!" ) end ) addButton( bounds, "Start New Game", { pressed = function() print( "New Game!" ) end } )
bounds.y = bounds.y + gap bounds.y = bounds.y + gap
addButton( bounds, "Load Game", function() print( "Load Game!" ) end ) addButton( bounds, "Load Game", { pressed = function() print( "Load Game!" ) end } )
bounds.y = bounds.y + gap bounds.y = bounds.y + gap
addButton( bounds, "Options", function() print( "Options!" ) end ) addButton( bounds, "Options", { pressed = function() print( "Options!" ) end } )
bounds.y = bounds.y + gap bounds.y = bounds.y + gap
addButton( bounds, "Quit", function() RL.CloseWindow() end ) addButton( bounds, "Quit", { pressed = function() RL.CloseWindow() end } )
end end
local function getTextValue( text ) local function getTextValue( text )
@@ -74,10 +74,10 @@ local function addPropertyList()
PropertyList = Gui:PropertyList( PropertyList = Gui:PropertyList(
Rect:new( 20, 20, 256, 328 ), Rect:new( 20, 20, 256, 328 ),
"Property List", "Property List",
nil, -- Callback. { -- Callbacks.
function( self ) Gui:set2Top( self ) end, -- Grab callback. grab = function( self ) Gui:set2Top( self ) end,
nil, -- Drag callback. },
{ { -- Styles.
properties = { properties = {
-- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE }, -- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
{ RL.LISTVIEW, RL.BORDER_COLOR_FOCUSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) }, { RL.LISTVIEW, RL.BORDER_COLOR_FOCUSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) },
@@ -106,11 +106,13 @@ local function addPropertyList()
cat.dest.x, cat.dest.x,
32, 32,
false, false,
function( self ) { -- Callbacks.
self.value = getTextValue( self.text ) edit = function( self )
self.text = tostring( self.value ) self.value = getTextValue( self.text )
cat.dest.x = self.value self.text = tostring( self.value )
end, cat.dest.x = self.value
end
},
nil, nil,
"Position X" "Position X"
), transformGroup, true ) ), transformGroup, true )
@@ -119,11 +121,13 @@ local function addPropertyList()
cat.dest.y, cat.dest.y,
32, 32,
false, false,
function( self ) { -- Callbacks.
self.value = getTextValue( self.text ) edit = function( self )
self.text = tostring( self.value ) self.value = getTextValue( self.text )
cat.dest.y = self.value self.text = tostring( self.value )
end, cat.dest.y = self.value
end
},
nil, nil,
"Position Y" "Position Y"
), transformGroup ) ), transformGroup )
@@ -137,11 +141,13 @@ local function addPropertyList()
cat.dest.x, cat.dest.x,
32, 32,
false, false,
function( self ) { -- Callbacks.
self.value = getTextValue( self.text ) edit = function( self )
self.text = tostring( self.value ) self.value = getTextValue( self.text )
cat.origin.x = self.value self.text = tostring( self.value )
end, cat.origin.x = self.value
end
},
nil, nil,
"Origin X" "Origin X"
), transformGroup, true ) ), transformGroup, true )
@@ -150,11 +156,13 @@ local function addPropertyList()
cat.dest.y, cat.dest.y,
32, 32,
false, false,
function( self ) { -- Callbacks.
self.value = getTextValue( self.text ) edit = function( self )
self.text = tostring( self.value ) self.value = getTextValue( self.text )
cat.origin.y = self.value self.text = tostring( self.value )
end, cat.origin.y = self.value
end
},
nil, nil,
"Origin Y" "Origin Y"
), transformGroup ) ), transformGroup )
@@ -166,11 +174,13 @@ local function addPropertyList()
0, 0,
0, 0,
360, 360,
function( self ) { -- Callbacks.
self.value = Util.round( self.value ) edit = function( self )
cat.rotation = self.value self.value = Util.round( self.value )
self.textRight = self.value cat.rotation = self.value
end, self.textRight = self.value
end
},
nil, nil,
"Rotation angle" "Rotation angle"
), transformGroup ) ), transformGroup )
@@ -179,7 +189,9 @@ local function addPropertyList()
Rect:new( 0, 0, 20, 20 ), Rect:new( 0, 0, 20, 20 ),
"Flipped", "Flipped",
cat.flipped, cat.flipped,
function( self ) cat.flipped = self.checked end, { -- Callbacks.
pressed = function( self ) cat.flipped = self.checked end
},
nil, nil,
"Flips the image" "Flips the image"
), transformGroup ) ), transformGroup )
@@ -192,7 +204,9 @@ local function addPropertyList()
Rect:new( 0, 0, 20, 20 ), Rect:new( 0, 0, 20, 20 ),
"Visible", "Visible",
cat.visible, cat.visible,
function( self ) cat.visible = self.checked end, { -- Callbacks.
pressed = function( self ) cat.visible = self.checked end
},
{ {
properties = { properties = {
{ RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT }, { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT },
@@ -206,7 +220,9 @@ local function addPropertyList()
Rect:new( 0, 0, 128, 128 ), Rect:new( 0, 0, 128, 128 ),
"Color Picker", "Color Picker",
Color:new(), Color:new(),
function( self ) cat.tint = self.color end { -- Callbacks.
edit = function( self ) cat.tint = self.color end
}
), tintGroup ) ), tintGroup )
PropertyList:addControl( PropertyList.gui:Line( PropertyList:addControl( PropertyList.gui:Line(
@@ -219,7 +235,9 @@ local function addPropertyList()
"Dog\nGiraffe\nLion\nHorse", "Dog\nGiraffe\nLion\nHorse",
0, 0,
false, false,
function( self ) print( self:getItem( self.active ) ) end { -- Callbacks.
select = function( self ) print( self:getItem( self.active ) ) end
}
) ) ) )
local test = PropertyList:addGroup( "Test", false ) local test = PropertyList:addGroup( "Test", false )
@@ -229,7 +247,9 @@ local function addPropertyList()
Rect:new( 128, 0, 20, 20 ), Rect:new( 128, 0, 20, 20 ),
i.."_Visible", i.."_Visible",
false, false,
function( self ) print( "Checked" ) end, { -- Callbacks.
pressed = function( self ) print( "Checked" ) end
},
{ {
properties = { properties = {
-- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT }, -- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT },
@@ -250,10 +270,11 @@ local function addTreeView()
TreeView = Gui:TreeView( TreeView = Gui:TreeView(
Rect:new( 600, 20, 256, 328 ), Rect:new( 600, 20, 256, 328 ),
"Tree View", "Tree View",
function( controls ) selected( controls ) end, -- Callback. { -- Callbacks.
function( self ) Gui:set2Top( self ) end, -- Grab callback. select = function( controls ) selected( controls ) end,
nil, -- Drag callback. grab = function( self ) Gui:set2Top( self ) end,
{ },
{ -- Styles.
properties = { properties = {
-- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE }, -- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
{ RL.LISTVIEW, RL.BORDER_COLOR_FOCUSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) }, { RL.LISTVIEW, RL.BORDER_COLOR_FOCUSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) },

View File

@@ -1,7 +1,7 @@
local PropertyList = {} local PropertyList = {}
PropertyList.__index = PropertyList PropertyList.__index = PropertyList
function PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) function PropertyList:new( bounds, text, callbacks, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._gui = nil object._gui = nil
@@ -12,9 +12,7 @@ function PropertyList:new( bounds, text, callback, grabCallback, dragCallback, s
object.text = text object.text = text
object.scroll = Vec2:new() object.scroll = Vec2:new()
object.view = Rect:new() object.view = Rect:new()
object.callback = callback object.callbacks = callbacks -- scroll, grab, drag.
object.grabCallback = grabCallback
object.dragCallback = dragCallback
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -140,8 +138,10 @@ function PropertyList:addGroup( name, active, group )
self:getDefaultBounds(), self:getDefaultBounds(),
setGroupText( name, active ), setGroupText( name, active ),
active, active,
function( this ) this.text = setGroupText( name, this.active ) self:updateContent() end, { -- Callbacks.
{ pressed = function( this ) this.text = setGroupText( name, this.active ) self:updateContent() end,
},
{ -- Styles.
properties = { properties = {
{ RL.TOGGLE, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT } { RL.TOGGLE, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT }
} }
@@ -194,8 +194,8 @@ function PropertyList:draw()
self:updateMouseOffset() self:updateMouseOffset()
self.gui.view:set( -self.scroll.x, -self.scroll.y, self.view.width, self.view.height ) self.gui.view:set( -self.scroll.x, -self.scroll.y, self.view.width, self.view.height )
if self.callback ~= nil then if self.callbacks.scroll ~= nil then
self.callback( self ) self.callbacks.scroll( self )
end end
end end
@@ -250,8 +250,8 @@ function PropertyList:setSize( size )
end end
function PropertyList:register( gui ) function PropertyList:register( gui )
function gui:PropertyList( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) function gui:PropertyList( bounds, text, callbacks, styles, tooltip )
return self:addControl( PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) ) return self:addControl( PropertyList:new( bounds, text, callbacks, styles, tooltip ) )
end end
end end

View File

@@ -1,7 +1,7 @@
local SpriteButton = {} local SpriteButton = {}
SpriteButton.__index = SpriteButton SpriteButton.__index = SpriteButton
function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles, tooltip ) function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callbacks, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._gui = nil object._gui = nil
@@ -10,7 +10,7 @@ function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, c
object.buttonTexture = texture object.buttonTexture = texture
object.nPatchNormal = nPatchNormal object.nPatchNormal = nPatchNormal
object.nPatchPressed = nPatchPressed object.nPatchPressed = nPatchPressed
object.callback = callback object.callbacks = callbacks -- pressed.
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -33,8 +33,8 @@ function SpriteButton:draw()
local result = RL.GuiLabelButton( self.bounds, self.text ) local result = RL.GuiLabelButton( self.bounds, self.text )
if result == 1 and self.callback ~= nil and self._gui:clickedInBounds( self.bounds ) then if result == 1 and self.callbacks.pressed ~= nil and self._gui:clickedInBounds( self.bounds ) then
self.callback( self ) self.callbacks.pressed( self )
end end
end end
@@ -44,8 +44,8 @@ function SpriteButton:setPosition( pos )
end end
function SpriteButton:register( gui ) function SpriteButton:register( gui )
function gui:SpriteButton( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles, tooltip ) function gui:SpriteButton( bounds, text, texture, nPatchNormal, nPatchPressed, callbacks, styles, tooltip )
return self:addControl( SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles, tooltip ) ) return self:addControl( SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callbacks, styles, tooltip ) )
end end
end end

View File

@@ -9,7 +9,7 @@ function TreeItem:new( bounds, text, callbacks, styles, tooltip )
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
object.callbacks = callbacks -- toggle, open. object.callbacks = callbacks -- select, open.
object.controls = {} object.controls = {}
@@ -68,8 +68,8 @@ function TreeItem:draw()
local oldActive = self.active local oldActive = self.active
_, self.active = RL.GuiToggle( toggleRect, self.text, self.active ) _, self.active = RL.GuiToggle( toggleRect, self.text, self.active )
if self.callbacks.toggle and oldActive ~= self.active then if self.callbacks.select and oldActive ~= self.active then
self.callbacks.toggle( self ) self.callbacks.select( self )
end end
if hasContainer then if hasContainer then

View File

@@ -10,7 +10,7 @@ TreeView.MOVE_ITEM_IN = 1
TreeView.MOVE_ITEM_UP = 2 TreeView.MOVE_ITEM_UP = 2
TreeView.MOVE_ITEM_DOWN = 3 TreeView.MOVE_ITEM_DOWN = 3
function TreeView:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) function TreeView:new( bounds, text, callbacks, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._gui = nil object._gui = nil
@@ -22,9 +22,7 @@ function TreeView:new( bounds, text, callback, grabCallback, dragCallback, style
object.text = text object.text = text
object.scroll = Vec2:new() object.scroll = Vec2:new()
object.view = Rect:new() object.view = Rect:new()
object.callback = callback object.callbacks = callbacks -- select, grab, drag.
object.grabCallback = grabCallback
object.dragCallback = dragCallback
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -132,7 +130,7 @@ function TreeView:addItem( name, group )
name, name,
{ -- Callbacks. { -- Callbacks.
open = function( this ) self:updateContent() end, open = function( this ) self:updateContent() end,
toggle = function( this ) self:itemSelect( this ) end, select = function( this ) self:itemSelect( this ) end,
}, },
{ -- Styles. { -- Styles.
properties = { properties = {
@@ -262,8 +260,8 @@ function TreeView:itemSelect( item )
self._lastActiveItem = item -- Old clicked. self._lastActiveItem = item -- Old clicked.
end end
if self.callback ~= nil then if self.callbacks.select ~= nil then
-- self.callback( self.selectedItems ) self.callbacks.select( self.selectedItems )
end end
end end
@@ -399,8 +397,8 @@ function TreeView:setSize( size )
end end
function TreeView:register( gui ) function TreeView:register( gui )
function gui:TreeView( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) function gui:TreeView( bounds, text, callbacks, styles, tooltip )
return self:addControl( TreeView:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) ) return self:addControl( TreeView:new( bounds, text, callbacks, styles, tooltip ) )
end end
end end

View File

@@ -63,12 +63,16 @@ function RL.init()
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 { -- Callbacks.
select = function( self ) print( self:getItem( self.active ) ) end
}
) )
local button = Gui:Button( 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, { -- Callbacks.
pressed = function() toggleGroup:setText( "Dog;Cat\nEagle" ) end
},
{ {
properties = { properties = {
{ RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) }, { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
@@ -82,25 +86,30 @@ function RL.init()
Rect:new( 116, 128, 20, 20 ), Rect:new( 116, 128, 20, 20 ),
"Visible", "Visible",
toggleGroup.visible, toggleGroup.visible,
function( self ) toggleGroup.visible = self.checked end { -- Callbacks.
pressed = function( self ) toggleGroup.visible = self.checked end
}
) )
local toggle = Gui:Toggle( local toggle = Gui:Toggle(
Rect:new( 32, 160, 100, 32 ), Rect:new( 32, 160, 100, 32 ),
"Toggle", "Toggle",
false, false,
nil {} -- Callbacks.
) )
local combobox = Gui:ComboBox( local combobox = Gui:ComboBox(
Rect:new( 64, 256, 128, 32 ), Rect:new( 64, 256, 128, 32 ),
"Dog\nCow\nDonkey", "Dog\nCow\nDonkey",
0 0,
{} -- Callbacks.
) )
local dropdownbox = Gui:DropdownBox( 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 { -- Callbacks.
select = function( self ) print( self:getItem( self.active ) ) end
}
) )
local spinner = Gui:Spinner( local spinner = Gui:Spinner(
Rect:new( 464, 256, 128, 32 ), Rect:new( 464, 256, 128, 32 ),
@@ -109,7 +118,9 @@ function RL.init()
0, 0,
10, 10,
false, false,
function( self ) print( "Spinner value changed to "..self.value ) end { -- Callbacks.
edit = function( self ) print( "Spinner value changed to "..self.value ) end
}
) )
local valuebox = Gui:ValueBox( local valuebox = Gui:ValueBox(
Rect:new( 464, 316, 128, 32 ), Rect:new( 464, 316, 128, 32 ),
@@ -118,21 +129,28 @@ function RL.init()
0, 0,
100, 100,
false, false,
function( self ) print( "ValueBox value changed to "..self.value ) end { -- Callbacks.
edit = function( self ) print( "ValueBox value changed to "..self.value ) end
}
) )
local textbox = Gui:TextBox( 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 { -- Callbacks.
edit = function( self ) print( "Set text "..self.text ) end,
-- editMode = function( self ) print( "Entered edit mode" ) end
}
) )
local textbox2 = Gui:TextBox( 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 { -- Callbacks.
edit = function( self ) print( "Set text 2 "..self.text ) end
}
) )
local slider = Gui:Slider( local slider = Gui:Slider(
Rect:new( 50, 500, 256, 32 ), Rect:new( 50, 500, 256, 32 ),
@@ -141,8 +159,10 @@ function RL.init()
0, 0,
0, 0,
100, 100,
function( self ) print( "Changed value "..self.value ) end, { -- Callbacks.
{ edit = function( self ) print( "Changed value "..self.value ) end,
},
{ -- Styles.
texture = { texture = texture, rect = textureRect }, texture = { texture = texture, rect = textureRect },
} }
) )
@@ -153,7 +173,9 @@ function RL.init()
0, 0,
0, 0,
100, 100,
function( self ) print( "Changed value "..self.value ) end { -- Callbacks.
edit = function( self ) print( "Changed value "..self.value ) end
}
) )
local progressbar = Gui:ProgressBar( local progressbar = Gui:ProgressBar(
Rect:new( 50, 600, 256, 32 ), Rect:new( 50, 600, 256, 32 ),
@@ -162,7 +184,9 @@ function RL.init()
20, 20,
0, 0,
100, 100,
function( self ) print( "Changed value "..self.value ) end { -- Callbacks.
edit = function( self ) print( "Changed value "..self.value ) end
}
) )
local statusbar = Gui:StatusBar( local statusbar = Gui:StatusBar(
Rect:new( 50, 650, 256, 32 ), Rect:new( 50, 650, 256, 32 ),
@@ -176,17 +200,17 @@ function RL.init()
Rect:new( 400, 400, 256, 256 ), Rect:new( 400, 400, 256, 256 ),
"Grid", "Grid",
32, 32,
2 2,
{} -- Callbacks.
) )
windowbox = Gui:WindowBox( windowbox = Gui:WindowBox(
Rect:new( 720, 250, 256, 256 ), Rect:new( 720, 250, 256, 256 ),
"WindowBox", "WindowBox",
-- Close callback. { -- Callbacks.
function( self ) self.visible = false end, close = function( self ) self.visible = false end,
-- Grab callback. grab = function( self ) Gui:set2Top( self ) end,
function( self ) Gui:set2Top( self ) end, },
nil, { -- Styles.
{
properties = { properties = {
{ RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) }, { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
}, },
@@ -205,10 +229,10 @@ function RL.init()
local panel = Gui:Panel( local panel = Gui:Panel(
Rect:new( 400, 64, 256, 128 ), Rect:new( 400, 64, 256, 128 ),
"Panel", "Panel",
-- Grab callback. { -- Callbacks.
function( self ) Gui:set2Top( self ) end, grab = function( self ) Gui:set2Top( self ) end
nil, },
{ { -- Styles.
properties = { properties = {
{ RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.MAGENTA ) }, { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.MAGENTA ) },
{ RL.DEFAULT, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER }, { RL.DEFAULT, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
@@ -220,25 +244,28 @@ function RL.init()
Rect:new( 700, 520, 700, 32 ), Rect:new( 700, 520, 700, 32 ),
"Cat;Dog;Horse;Cow;Dog;Horse;Cow", "Cat;Dog;Horse;Cow;Dog;Horse;Cow",
0, 0,
nil, { -- Callbacks.
closeTab close = closeTab
}
) )
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, 300, 600 ), Rect:new( 0, 0, 300, 600 ),
Vec2:new( 0, 0 ), Vec2:new( 0, 0 ),
-- Callback. { -- Callbacks.
function( self ) print( self.scroll ) end, scroll = function( self ) print( self.scroll ) end,
-- Grab callback. grab = function( self ) Gui:set2Top( self ) end
function( self ) Gui:set2Top( self ) end }
) )
local listview = Gui:ListView( local listview = Gui:ListView(
Rect:new( 1100, 64, 128, 128 ), 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 { -- Callbacks.
select = function( self ) print( self:getItem( self.active ) ) end
}
) )
local listviewex = Gui:ListViewEx( local listviewex = Gui:ListViewEx(
Rect:new( 1300, 64, 128, 128 ), Rect:new( 1300, 64, 128, 128 ),
@@ -246,8 +273,10 @@ function RL.init()
0, 0,
0, 0,
0, 0,
function( self ) print( self:getItem( self.active ) ) end, { -- Callbacks.
{ select = function( self ) print( self:getItem( self.active ) ) end
},
{ -- Styles.
properties = { properties = {
{ RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) }, { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
{ RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) }, { RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) },
@@ -261,17 +290,18 @@ function RL.init()
"Title", "Title",
"Should we disable\nwindow box?", "Should we disable\nwindow box?",
"No;Yes", "No;Yes",
function( self ) { -- Callbacks.
if 0 < self.buttonIndex then pressed = function( self )
if self.buttonIndex == 1 then if 0 < self.buttonIndex then
windowbox.disabled = false if self.buttonIndex == 1 then
elseif self.buttonIndex == 2 then windowbox.disabled = false
windowbox.disabled = true elseif self.buttonIndex == 2 then
windowbox.disabled = true
end
end end
end end,
end, grab = function( self ) Gui:set2Top( self ) end
-- Grab callback. }
function( self ) Gui:set2Top( self ) end
) )
local textinputbox = Gui:TextInputBox( local textinputbox = Gui:TextInputBox(
Rect:new( 1100, 300, 300, 128 ), Rect:new( 1100, 300, 300, 128 ),
@@ -281,40 +311,47 @@ function RL.init()
"Text", "Text",
8, 8,
false, false,
function( self ) { -- Callbacks.
if 0 < self.buttonIndex then pressed = function( self )
print( "You pressed "..self:getItem( self.buttonIndex ) ) if 0 < self.buttonIndex then
end print( "You pressed "..self:getItem( self.buttonIndex ) )
end, end
-- Grab callback. end,
function( self ) Gui:set2Top( self ) end grab = function( self ) Gui:set2Top( self ) end
}
) )
local colorpicker = Gui:ColorPicker( local colorpicker = Gui:ColorPicker(
Rect:new( 1500, 32, 128, 128 ), Rect:new( 1500, 32, 128, 128 ),
"Color Picker", "Color Picker",
Color:new() Color:new(),
{} -- Callbacks.
) )
local colorpanel = Gui:ColorPanel( local colorpanel = Gui:ColorPanel(
Rect:new( 1700, 32, 128, 128 ), Rect:new( 1700, 32, 128, 128 ),
"Color Panel", "Color Panel",
Color:new() Color:new(),
{} -- Callbacks.
) )
local colorbaralpha = Gui:ColorBarAlpha( local colorbaralpha = Gui:ColorBarAlpha(
Rect:new( 1700, 180, 128, 20 ), Rect:new( 1700, 180, 128, 20 ),
"Color Panel", "Color Panel",
1.0 1.0,
{} -- Callbacks.
) )
local colorbarhue = Gui:ColorBarHue( local colorbarhue = Gui:ColorBarHue(
Rect:new( 1840, 32, 20, 128 ), Rect:new( 1840, 32, 20, 128 ),
"Color Panel", "Color Panel",
1.0 1.0,
{} -- Callbacks.
) )
local scrollbar = Gui:GuiScrollBar( local scrollbar = Gui:GuiScrollBar(
Rect:new( 50, 760, 256, 16 ), Rect:new( 50, 760, 256, 16 ),
0, 0,
0, 0,
256, 256,
function( self ) print( "Scrollbar value: ", self.value ) end { -- Callbacks.
scroll = function( self ) print( "Scrollbar value: ", self.value ) end
}
) )
end end

File diff suppressed because it is too large Load Diff