Raygui updated to version 4.0.
This commit is contained in:
@@ -8,17 +8,18 @@ local spinnerActive = false
|
||||
local spinnerValueRange = { 0, 10 }
|
||||
local sliderValue = 5.0
|
||||
local sliderValueRange = { 0.0, 10.0 }
|
||||
local scrollbarValue = 0.0
|
||||
local dropdownValue = 0
|
||||
local dropdownActive = false
|
||||
local index = 0
|
||||
local listView = { item = 0, scroll = 0 }
|
||||
local listViewEx = { item = 0, scroll = 0, focus = 0 }
|
||||
local messageBox = { buttonIndex = -1 }
|
||||
local textInputBox = { buttonIndex = 0, text = "", secretViewActive = 1 }
|
||||
local textInputBox = { buttonIndex = 0, text = "", secretViewActive = false }
|
||||
local colorPicker = { color = { 255, 255, 255 } }
|
||||
local colorPanel = { color = { 255, 255, 255 }, alpha = 1.0, hue = 1.0, oldHue = 1.0 }
|
||||
local comboBoxActive = 0
|
||||
local scrollPanel = { scroll = { 0, 0 }, view = { 0, 0, 320, 200 } }
|
||||
local guiTabBarActive = 0
|
||||
local colorPickerHSV = { 0, 0, 0 }
|
||||
local colorPanelHSV = { 0, 0, 0 }
|
||||
|
||||
function RL.init()
|
||||
local monitor = 0
|
||||
@@ -36,79 +37,86 @@ end
|
||||
function RL.draw()
|
||||
RL.ClearBackground( { 50, 20, 75 } )
|
||||
|
||||
local result = 0
|
||||
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 )
|
||||
|
||||
if RL.GuiButton( { 112, 16, 96, 32 }, RL.GuiIconText( 113, "Exit" ) ) then
|
||||
if RL.GuiButton( { 112, 16, 96, 32 }, RL.GuiIconText( 113, "Exit" ) ) == 1 then
|
||||
RL.CloseWindow()
|
||||
end
|
||||
|
||||
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
|
||||
RL.GuiButton( { 112, 64, 96, 32 }, RL.GuiIconText( 113, "Cat" ) )
|
||||
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 )
|
||||
RL.GuiButton( { 112, 64, 96, 32 }, RL.GuiIconText( 100, "Cat" ) )
|
||||
|
||||
if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then
|
||||
if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) == 1 then
|
||||
windowOpen = false
|
||||
end
|
||||
|
||||
RL.GuiPanel( { 60, 260, 100, 100 }, "Panel" )
|
||||
|
||||
toggled = RL.GuiToggle( { 200, 260, 64, 32 }, "Toggle", toggled )
|
||||
index = RL.GuiToggleGroup( { 520, 30, 64, 32 }, "Cat\nDog\nMonkey", index )
|
||||
checkbox = RL.GuiCheckBox( { 200, 300, 16, 16 }, "CheckBox", checkbox )
|
||||
_, toggled = RL.GuiToggle( { 200, 260, 64, 32 }, "Toggle", toggled )
|
||||
|
||||
local textBoxToggle = false
|
||||
textBoxToggle, textBoxText = RL.GuiTextBox( { 32, 400, 120, 32 }, textBoxText, 32, textBoxActive )
|
||||
-- textBoxToggle, textBoxText = RL.GuiTextBoxMulti( { 32, 400, 120, 64 }, textBoxText, 120, textBoxActive )
|
||||
_, index = RL.GuiToggleGroup( { 520, 30, 64, 32 }, "Cat\nDog\nMonkey", index )
|
||||
|
||||
_, checkbox = RL.GuiCheckBox( { 200, 300, 16, 16 }, "CheckBox", checkbox )
|
||||
|
||||
if textBoxToggle then
|
||||
result, textBoxText = RL.GuiTextBox( { 32, 400, 120, 32 }, textBoxText, 32, textBoxActive )
|
||||
if result == 1 then
|
||||
textBoxActive = not textBoxActive
|
||||
end
|
||||
|
||||
local spinnerToggle = false
|
||||
spinnerToggle, spinnerValue = RL.GuiSpinner( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive )
|
||||
-- spinnerToggle, spinnerValue = RL.GuiValueBox( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive )
|
||||
|
||||
if spinnerToggle then
|
||||
result, spinnerValue = RL.GuiSpinner( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive )
|
||||
if result == 1 then
|
||||
spinnerActive = not spinnerActive
|
||||
end
|
||||
|
||||
sliderValue = RL.GuiSliderBar( { 64, 510, 96, 32 }, "min", "max", sliderValue, sliderValueRange[1], sliderValueRange[2] )
|
||||
scrollbarValue = RL.GuiScrollBar( { 64, 550, 130, 32 }, scrollbarValue, 0, 10 )
|
||||
_, sliderValue = RL.GuiSliderBar( { 64, 510, 96, 32 }, "min", "max", sliderValue, sliderValueRange[1], sliderValueRange[2] )
|
||||
|
||||
local dropdownToggle = false
|
||||
dropdownToggle, dropdownValue = RL.GuiDropdownBox( { 2, 2, 96, 16 }, "Cat\nDog\nMonkey", dropdownValue, dropdownActive )
|
||||
|
||||
if dropdownToggle then
|
||||
result, dropdownValue = RL.GuiDropdownBox( { 2, 2, 96, 16 }, "Cat\nDog\nMonkey", dropdownValue, dropdownActive )
|
||||
if result == 1 then
|
||||
dropdownActive = not dropdownActive
|
||||
end
|
||||
|
||||
listView.item, listView.scroll = RL.GuiListView( { 200, 400, 200, 200 }, "Cat\nElefant\nSquirrel", listView.scroll, listView.item )
|
||||
messageBox.buttonIndex = RL.GuiMessageBox( { 420, 400, 200, 100 }, "Message", "Are you sure about this?", "Yes\nNo" )
|
||||
_, listView.scroll, listView.item = RL.GuiListView( { 200, 400, 200, 200 }, "Cat;Elefant;Squirrel", listView.scroll, listView.item )
|
||||
|
||||
if 0 <= messageBox.buttonIndex then
|
||||
print( "messageBox.buttonIndex", messageBox.buttonIndex )
|
||||
result = RL.GuiMessageBox( { 420, 400, 200, 100 }, "Message", "Are you sure about this?", "Yes;No" )
|
||||
if 0 <= result then
|
||||
print( "messageBox.buttonIndex", result )
|
||||
end
|
||||
|
||||
textInputBox.buttonIndex, textInputBox.text, textInputBox.secretViewActive
|
||||
result, textInputBox.text, textInputBox.secretViewActive
|
||||
= RL.GuiTextInputBox( { 420, 510, 300, 150 }, "Input Box", "Put text here", "Button", textInputBox.text, 200, textInputBox.secretViewActive )
|
||||
|
||||
if 0 <= textInputBox.buttonIndex then
|
||||
print( "textInputBox.buttonIndex", textInputBox.buttonIndex )
|
||||
if 0 <= result then
|
||||
print( "textInputBox.buttonIndex", result )
|
||||
end
|
||||
|
||||
colorPicker.color = RL.GuiColorPicker( { 620, 20, 150, 150 }, "Color Picker", colorPicker.color )
|
||||
_, colorPicker.color = RL.GuiColorPicker( { 620, 20, 150, 150 }, "Color Picker", colorPicker.color )
|
||||
|
||||
colorPanel.color = RL.GuiColorPanel( { 820, 20, 150, 150 }, "Color Panel", colorPanel.color )
|
||||
colorPanel.alpha = RL.GuiColorBarAlpha( { 820, 180, 150, 20 }, "Color alpha", colorPanel.alpha )
|
||||
colorPanel.hue = RL.GuiColorBarHue( { 980, 20, 20, 150 }, "Color hue", colorPanel.hue )
|
||||
_, colorPanel.color = RL.GuiColorPanel( { 820, 20, 150, 150 }, "Color Panel", colorPanel.color )
|
||||
_, colorPanel.alpha = RL.GuiColorBarAlpha( { 820, 180, 150, 20 }, "Color alpha", colorPanel.alpha )
|
||||
_, colorPanel.hue = RL.GuiColorBarHue( { 980, 20, 20, 150 }, "Color hue", colorPanel.hue )
|
||||
|
||||
if colorPanel.hue ~= colorPanel.oldHue then
|
||||
colorPanel.oldHue = colorPanel.hue
|
||||
|
||||
colorPanel.color = RL.ColorFromHSV( colorPanel.hue, 1.0, 1.0 )
|
||||
end
|
||||
|
||||
RL.GuiDrawIcon( 121, { 6, 20 }, 2, RL.WHITE )
|
||||
RL.GuiDrawIcon( 121, { 6, 80 }, 2, RL.BLACK )
|
||||
|
||||
comboBoxActive = RL.GuiComboBox( { 5, 50, 80, 20 }, "One\nTwo\nThree", comboBoxActive )
|
||||
_, comboBoxActive = RL.GuiComboBox( { 5, 150, 80, 20 }, "One;Two;Three", comboBoxActive )
|
||||
|
||||
result, scrollPanel.scroll, scrollPanel.view = RL.GuiScrollPanel(
|
||||
{ 64, 640, 320, 200 },
|
||||
"Scroll panel",
|
||||
{ 0, 0, 640, 400 },
|
||||
scrollPanel.scroll,
|
||||
scrollPanel.view
|
||||
)
|
||||
|
||||
_, guiTabBarActive = RL.GuiTabBar(
|
||||
{ 420, 680, 320, 32 },
|
||||
RL.GuiIconText( 13, "Play" )..";"..RL.GuiIconText( 12, "Cat.png" )..";"..RL.GuiIconText( 16, "Files" ),
|
||||
guiTabBarActive
|
||||
)
|
||||
|
||||
_, colorPickerHSV = RL.GuiColorPickerHSV( { 1024, 20, 150, 150 }, "GuiColorPuckerHSV", colorPickerHSV )
|
||||
_, colorPanelHSV = RL.GuiColorPanelHSV( { 1230, 20, 150, 150 }, "GuiColorPuckerHSV", colorPanelHSV )
|
||||
end
|
||||
|
||||
@@ -32,13 +32,11 @@ function RL.init()
|
||||
end
|
||||
|
||||
function RL.process( delta )
|
||||
-- Gui:process()
|
||||
Raygui:process()
|
||||
end
|
||||
|
||||
function RL.draw()
|
||||
RL.ClearBackground( RL.DARKBLUE )
|
||||
|
||||
-- Gui:draw()
|
||||
Raygui:draw()
|
||||
end
|
||||
|
||||
@@ -8,7 +8,26 @@ Raygui = require( "raygui" )
|
||||
|
||||
local grid = {}
|
||||
local windowbox = {}
|
||||
local winOpen = true
|
||||
local tabBar = {}
|
||||
|
||||
local function closeTab( self, id )
|
||||
local splits = Util.split( tabBar.text, ";" )
|
||||
local newText = ""
|
||||
|
||||
if #splits == 1 then
|
||||
Raygui.remove( tabBar )
|
||||
end
|
||||
table.remove( splits, id + 1 )
|
||||
|
||||
for i, tab in ipairs( splits ) do
|
||||
newText = newText..tab
|
||||
|
||||
if i < #splits then
|
||||
newText = newText..";"
|
||||
end
|
||||
end
|
||||
self.text = newText
|
||||
end
|
||||
|
||||
function RL.init()
|
||||
local monitor = 0
|
||||
@@ -82,13 +101,6 @@ function RL.init()
|
||||
false,
|
||||
function( self ) print( "Set text "..self.text ) end
|
||||
)
|
||||
local textboxmulti = Raygui.TextBoxMulti:new(
|
||||
Rect:new( 32, 400, 256, 64 ),
|
||||
"Buggy?",
|
||||
32,
|
||||
false,
|
||||
function( self ) print( "Set text "..self.text ) end
|
||||
)
|
||||
local slider = Raygui.Slider:new(
|
||||
Rect:new( 50, 500, 256, 32 ),
|
||||
"min",
|
||||
@@ -152,6 +164,14 @@ function RL.init()
|
||||
-- Grab callback.
|
||||
function( self ) Raygui.set2Top( self ) end
|
||||
)
|
||||
tabBar = Raygui.GuiTabBar:new(
|
||||
Rect:new( 700, 520, 700, 32 ),
|
||||
"Cat;Dog;Horse;Cow",
|
||||
0,
|
||||
-- function( self ) Raygui.set2Top( self ) end
|
||||
nil,
|
||||
closeTab
|
||||
)
|
||||
local scrollpanel = Raygui.ScrollPanel:new(
|
||||
Rect:new( 800, 64, 256, 256 ),
|
||||
"ScrollPanel",
|
||||
@@ -164,14 +184,14 @@ function RL.init()
|
||||
)
|
||||
local listview = Raygui.ListView:new(
|
||||
Rect:new( 1100, 64, 128, 80 ),
|
||||
"Cat\nDog\nHorse\nCow\nPig\nEagle\nLion",
|
||||
"Cat;Dog;Horse;Cow;Pig;Eagle;Lion",
|
||||
0,
|
||||
0,
|
||||
function( self ) print( self:getItem( self.active ) ) end
|
||||
)
|
||||
local listviewex = Raygui.ListViewEx:new(
|
||||
Rect:new( 1300, 64, 128, 80 ),
|
||||
"Cat\nDog\nHorse\nCow\nPig\nEagle\nLion",
|
||||
"Cat;Dog;Horse;Cow;Pig;Eagle;Lion",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -181,7 +201,7 @@ function RL.init()
|
||||
Rect:new( 1100, 150, 300, 128 ),
|
||||
"Title",
|
||||
"Message",
|
||||
"Cancel\nOk",
|
||||
"Cancel;Ok",
|
||||
function( self )
|
||||
if 0 < self.buttonIndex then
|
||||
print( "You pressed "..self:getItem( self.buttonIndex ) )
|
||||
@@ -200,10 +220,10 @@ function RL.init()
|
||||
Rect:new( 1100, 300, 300, 128 ),
|
||||
"Title",
|
||||
"Message",
|
||||
"Cancel\nOk",
|
||||
"Cancel;Ok",
|
||||
"Text",
|
||||
8,
|
||||
0,
|
||||
false,
|
||||
function( self )
|
||||
if 0 < self.buttonIndex then
|
||||
print( "You pressed "..self:getItem( self.buttonIndex ) )
|
||||
@@ -249,11 +269,11 @@ end
|
||||
function RL.draw()
|
||||
RL.ClearBackground( { 50, 20, 75 } )
|
||||
|
||||
if 0 <= grid.cell.x then
|
||||
if 0 <= grid.mouseCell.x then
|
||||
RL.DrawRectangleLines(
|
||||
{
|
||||
grid.bounds.x + grid.cell.x * 32,
|
||||
grid.bounds.y + grid.cell.y * 32,
|
||||
grid.bounds.x + grid.mouseCell.x * 32,
|
||||
grid.bounds.y + grid.mouseCell.y * 32,
|
||||
32,
|
||||
32
|
||||
},
|
||||
|
||||
@@ -32,11 +32,14 @@ Color.meta = {
|
||||
__idiv = function( c, v )
|
||||
return Color:new( c.r // v, c.g // v, c.b // v, c.a // v )
|
||||
end,
|
||||
__len = function( _ )
|
||||
__len = function()
|
||||
return 4
|
||||
end,
|
||||
__eq = function( c1, c2 )
|
||||
return c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a
|
||||
return math.floor( c1.r ) == math.floor( c2.r )
|
||||
and math.floor( c1.g ) == math.floor( c2.g )
|
||||
and math.floor( c1.b ) == math.floor( c2.b )
|
||||
and math.floor( c1.a ) == math.floor( c2.a )
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -65,7 +68,7 @@ function Color:set( r, g, b, a )
|
||||
if type( r ) == "table" then
|
||||
r, g, b, a = table.unpack( r )
|
||||
elseif type( r ) == "nil" then
|
||||
r, g, b, a = 0, 0, 0, 0
|
||||
r, g, b, a = 0, 0, 0, 255
|
||||
end
|
||||
|
||||
if a == nil then
|
||||
@@ -87,7 +90,7 @@ function Color:unpack()
|
||||
end
|
||||
|
||||
function Color:clone()
|
||||
return Color:new( self )
|
||||
return Color:new( self.r, self.g, self.b, self.a )
|
||||
end
|
||||
|
||||
function Color:scale( scalar )
|
||||
|
||||
@@ -264,7 +264,7 @@ function Text:draw()
|
||||
return
|
||||
end
|
||||
|
||||
RL.DrawText( self.font, self.text, { self._parent.bounds.x + self.bounds.x, self._parent.bounds.y + self.bounds.y }, self.fontSize, self.spacing, self.color )
|
||||
RL.DrawTextEx( self.font, self.text, { self._parent.bounds.x + self.bounds.x, self._parent.bounds.y + self.bounds.y }, self.fontSize, self.spacing, self.color )
|
||||
end
|
||||
|
||||
-- Texture.
|
||||
|
||||
@@ -27,7 +27,7 @@ Quaternion.meta = {
|
||||
__unm = function( q )
|
||||
return Quaternion:new( RL.QuaternionInvert( q ) )
|
||||
end,
|
||||
__len = function( _ )
|
||||
__len = function()
|
||||
return 4
|
||||
end,
|
||||
__eq = function( q1, q2 )
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
-- Wrapper for raygui that should make using it a bit more convenient.
|
||||
|
||||
Util = require( "utillib" )
|
||||
Rect = require( "rectangle" )
|
||||
Vec2 = require( "vector2" )
|
||||
Color = require( "color" )
|
||||
local Util = require( "utillib" )
|
||||
local Rect = require( "rectangle" )
|
||||
local Vec2 = require( "vector2" )
|
||||
local Color = require( "color" )
|
||||
|
||||
---@param text string
|
||||
---@return integer count, table rowItemCounts
|
||||
@@ -54,6 +54,7 @@ local Raygui = {
|
||||
focused = 0,
|
||||
dragging = nil,
|
||||
grabPos = Vec2:new(),
|
||||
scrolling = false,
|
||||
}
|
||||
|
||||
function Raygui.process()
|
||||
@@ -110,7 +111,11 @@ function Raygui.drag( element )
|
||||
end
|
||||
|
||||
function Raygui.draw()
|
||||
RL.GuiLock()
|
||||
if not Raygui.scrolling then
|
||||
RL.GuiLock()
|
||||
elseif RL.IsMouseButtonReleased( RL.MOUSE_BUTTON_LEFT ) then
|
||||
Raygui.scrolling = false
|
||||
end
|
||||
|
||||
for i, element in ipairs( Raygui.elements ) do
|
||||
if i == Raygui.focused then
|
||||
@@ -143,6 +148,16 @@ function Raygui.set2Back( element )
|
||||
end
|
||||
end
|
||||
|
||||
function Raygui.remove( element )
|
||||
for i, curElement in ipairs( Raygui.elements ) do
|
||||
if element == curElement then
|
||||
table.remove( Raygui.elements, i )
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Container/separator controls, useful for controls organization
|
||||
]]--
|
||||
@@ -189,7 +204,9 @@ function WindowBox:process()
|
||||
end
|
||||
|
||||
function WindowBox:draw()
|
||||
if RL.GuiWindowBox( self.bounds, self.text ) and self.callback ~= nil then
|
||||
local result = RL.GuiWindowBox( self.bounds, self.text )
|
||||
|
||||
if result == 1 and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
@@ -304,6 +321,52 @@ function Panel:setPosition( pos )
|
||||
self.bounds.y = pos.y
|
||||
end
|
||||
|
||||
-- GuiTabBar.
|
||||
|
||||
--- Tab Bar control, returns TAB to be closed or -1
|
||||
GuiTabBar = {}
|
||||
GuiTabBar.__index = GuiTabBar
|
||||
|
||||
function GuiTabBar:new( bounds, text, active, callback, closeCallback )
|
||||
local object = setmetatable( {}, GuiTabBar )
|
||||
|
||||
object.bounds = bounds:clone()
|
||||
object.text = text
|
||||
object.active = active
|
||||
|
||||
object.visible = true
|
||||
object.callback = callback
|
||||
object.closeCallback = closeCallback
|
||||
|
||||
table.insert( Raygui.elements, object )
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function GuiTabBar:process()
|
||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||
end
|
||||
|
||||
function GuiTabBar:draw()
|
||||
local oldActive = self.active
|
||||
local result = -1
|
||||
|
||||
result, self.active = RL.GuiTabBar( self.bounds, self.text, self.active )
|
||||
|
||||
if self.active ~= oldActive and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
|
||||
if 0 <= result and self.closeCallback ~= nil then
|
||||
self.closeCallback( self, result )
|
||||
end
|
||||
end
|
||||
|
||||
function GuiTabBar:setPosition( pos )
|
||||
self.bounds.x = pos.x
|
||||
self.bounds.y = pos.y
|
||||
end
|
||||
|
||||
-- ScrollPanel.
|
||||
|
||||
--- Scroll Panel control
|
||||
@@ -336,14 +399,17 @@ end
|
||||
|
||||
function ScrollPanel:draw()
|
||||
local oldScroll = self.scroll:clone()
|
||||
|
||||
local view, scroll = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll )
|
||||
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 and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
if self.scroll ~= oldScroll then
|
||||
Raygui.scrolling = true
|
||||
|
||||
if self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -401,7 +467,6 @@ function Button:new( bounds, text, callback )
|
||||
object.text = text
|
||||
object.callback = callback
|
||||
|
||||
object.clicked = false
|
||||
object.visible = true
|
||||
|
||||
table.insert( Raygui.elements, object )
|
||||
@@ -414,9 +479,9 @@ function Button:process()
|
||||
end
|
||||
|
||||
function Button:draw()
|
||||
self.clicked = RL.GuiButton( self.bounds, self.text )
|
||||
local result = RL.GuiButton( self.bounds, self.text )
|
||||
|
||||
if self.clicked and self.callback ~= nil then
|
||||
if result == 1 and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
@@ -439,7 +504,6 @@ function LabelButton:new( bounds, text, callback )
|
||||
object.text = text
|
||||
object.callback = callback
|
||||
|
||||
object.clicked = false
|
||||
object.visible = true
|
||||
|
||||
table.insert( Raygui.elements, object )
|
||||
@@ -452,9 +516,9 @@ function LabelButton:process()
|
||||
end
|
||||
|
||||
function LabelButton:draw()
|
||||
self.clicked = RL.GuiLabelButton( self.bounds, self.text )
|
||||
local result = RL.GuiLabelButton( self.bounds, self.text )
|
||||
|
||||
if self.clicked and self.callback ~= nil then
|
||||
if result == 1 and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
@@ -492,7 +556,7 @@ end
|
||||
function Toggle:draw()
|
||||
local oldActive = self.active
|
||||
|
||||
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
|
||||
self.callback( self )
|
||||
@@ -573,15 +637,11 @@ end
|
||||
function ToggleGroup:draw()
|
||||
local oldActive = self.active
|
||||
|
||||
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
|
||||
self.callback( self )
|
||||
end
|
||||
|
||||
-- for _, rect in ipairs( self.focusBounds ) do
|
||||
-- RL.DrawRectangleLines( rect, RL.RED )
|
||||
-- end
|
||||
end
|
||||
|
||||
function ToggleGroup:setPosition( pos )
|
||||
@@ -658,7 +718,7 @@ end
|
||||
function CheckBox:draw()
|
||||
local oldChecked = self.checked
|
||||
|
||||
self.checked = RL.GuiCheckBox( self.bounds, self.text, self.checked )
|
||||
_, self.checked = RL.GuiCheckBox( self.bounds, self.text, self.checked )
|
||||
|
||||
if self.checked ~= oldChecked and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
@@ -702,7 +762,7 @@ end
|
||||
function ComboBox:draw()
|
||||
local oldActive = self.active
|
||||
|
||||
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
|
||||
self.callback( self )
|
||||
@@ -768,11 +828,11 @@ function DropdownBox:process()
|
||||
end
|
||||
|
||||
function DropdownBox:draw()
|
||||
local pressed = false
|
||||
local result = 0
|
||||
|
||||
pressed, self.active = RL.GuiDropdownBox( self.bounds, self.text, self.active, self.editMode )
|
||||
result, self.active = RL.GuiDropdownBox( self.bounds, self.text, self.active, self.editMode )
|
||||
|
||||
if pressed then
|
||||
if result == 1 then
|
||||
self.editMode = not self.editMode
|
||||
|
||||
if not self.editMode and self.callback ~= nil then
|
||||
@@ -815,12 +875,12 @@ function Spinner:process()
|
||||
end
|
||||
|
||||
function Spinner:draw()
|
||||
local pressed = false
|
||||
local result = 0
|
||||
local oldValue = self.value
|
||||
|
||||
pressed, self.value = RL.GuiSpinner( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
|
||||
result, self.value = RL.GuiSpinner( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
|
||||
|
||||
if pressed then
|
||||
if result == 1 then
|
||||
self.editMode = not self.editMode
|
||||
end
|
||||
|
||||
@@ -863,12 +923,12 @@ function ValueBox:process()
|
||||
end
|
||||
|
||||
function ValueBox:draw()
|
||||
local pressed = false
|
||||
local result = 0
|
||||
local oldValue = self.value
|
||||
|
||||
pressed, self.value = RL.GuiValueBox( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
|
||||
result, self.value = RL.GuiValueBox( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
|
||||
|
||||
if pressed then
|
||||
if result == 1 then
|
||||
self.editMode = not self.editMode
|
||||
end
|
||||
|
||||
@@ -910,19 +970,19 @@ function TextBox:process()
|
||||
end
|
||||
|
||||
function TextBox:draw()
|
||||
local pressed = false
|
||||
local result = 0
|
||||
|
||||
if self.scissorMode then
|
||||
RL.BeginScissorMode( self.bounds )
|
||||
end
|
||||
|
||||
pressed, self.text = RL.GuiTextBox( self.bounds, self.text, self.textSize, self.editMode )
|
||||
result, self.text = RL.GuiTextBox( self.bounds, self.text, self.textSize, self.editMode )
|
||||
|
||||
if self.scissorMode then
|
||||
RL.EndScissorMode()
|
||||
end
|
||||
|
||||
if pressed then
|
||||
if result == 1 then
|
||||
self.editMode = not self.editMode
|
||||
|
||||
if not self.editMode and self.callback ~= nil then
|
||||
@@ -936,51 +996,6 @@ function TextBox:setPosition( pos )
|
||||
self.bounds.y = pos.y
|
||||
end
|
||||
|
||||
-- TextBoxMulti.
|
||||
|
||||
-- Text Box control with multiple lines
|
||||
TextBoxMulti = {}
|
||||
TextBoxMulti.__index = TextBoxMulti
|
||||
|
||||
function TextBoxMulti:new( bounds, text, textSize, editMode, callback )
|
||||
local object = setmetatable( {}, TextBoxMulti )
|
||||
|
||||
object.bounds = bounds:clone()
|
||||
object.text = text
|
||||
object.textSize = textSize
|
||||
object.editMode = editMode
|
||||
object.callback = callback
|
||||
|
||||
object.visible = true
|
||||
|
||||
table.insert( Raygui.elements, object )
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function TextBoxMulti:process()
|
||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||
end
|
||||
|
||||
function TextBoxMulti:draw()
|
||||
local pressed = false
|
||||
|
||||
pressed, self.text = RL.GuiTextBoxMulti( self.bounds, self.text, self.textSize, self.editMode )
|
||||
|
||||
if pressed then
|
||||
self.editMode = not self.editMode
|
||||
|
||||
if not self.editMode and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function TextBoxMulti:setPosition( pos )
|
||||
self.bounds.x = pos.x
|
||||
self.bounds.y = pos.y
|
||||
end
|
||||
|
||||
-- Slider.
|
||||
|
||||
--- Slider control
|
||||
@@ -1012,10 +1027,14 @@ end
|
||||
function Slider:draw()
|
||||
local oldValue = self.value
|
||||
|
||||
self.value = RL.GuiSlider( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
|
||||
_, self.value = RL.GuiSlider( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
|
||||
|
||||
if self.value ~= oldValue then
|
||||
self.callback( self )
|
||||
Raygui.scrolling = true
|
||||
|
||||
if self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1055,10 +1074,14 @@ end
|
||||
function SliderBar:draw()
|
||||
local oldValue = self.value
|
||||
|
||||
self.value = RL.GuiSliderBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
|
||||
_, self.value = RL.GuiSliderBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
|
||||
|
||||
if self.value ~= oldValue then
|
||||
self.callback( self )
|
||||
Raygui.scrolling = true
|
||||
|
||||
if self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1098,7 +1121,7 @@ end
|
||||
function ProgressBar:draw()
|
||||
local oldValue = self.value
|
||||
|
||||
self.value = RL.GuiProgressBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
|
||||
_, self.value = RL.GuiProgressBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
|
||||
|
||||
if self.value ~= oldValue then
|
||||
self.callback( self )
|
||||
@@ -1189,7 +1212,7 @@ function Grid:new( bounds, text, spacing, subdivs, callback )
|
||||
object.subdivs = subdivs
|
||||
object.callback = callback
|
||||
|
||||
object.cell = Vec2:new()
|
||||
object.mouseCell = Vec2:new()
|
||||
object.visible = true
|
||||
|
||||
table.insert( Raygui.elements, object )
|
||||
@@ -1202,11 +1225,13 @@ function Grid:process()
|
||||
end
|
||||
|
||||
function Grid:draw()
|
||||
local oldCell = self.cell:clone()
|
||||
local oldCell = self.mouseCell:clone()
|
||||
local mouseCell = {}
|
||||
|
||||
self.cell = Vec2:new( RL.GuiGrid( self.bounds, self.text, self.spacing, self.subdivs ) )
|
||||
_, mouseCell = RL.GuiGrid( self.bounds, self.text, self.spacing, self.subdivs, self.mouseCell )
|
||||
self.mouseCell = Vec2:new( mouseCell )
|
||||
|
||||
if oldCell ~= self.cell and self.callback ~= nil then
|
||||
if oldCell ~= self.mouseCell and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
@@ -1251,9 +1276,13 @@ end
|
||||
|
||||
function ListView:draw()
|
||||
local oldActive = self.active
|
||||
local oldScrollIndex = self.scrollIndex
|
||||
|
||||
self.active, self.scrollIndex = 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
|
||||
Raygui.scrolling = true
|
||||
end
|
||||
if oldActive ~= self.active and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
@@ -1270,14 +1299,14 @@ end
|
||||
ListViewEx = {}
|
||||
ListViewEx.__index = ListViewEx
|
||||
|
||||
function ListViewEx:new( bounds, text, focus, scrollIndex, active, callback )
|
||||
function ListViewEx:new( bounds, text, scrollIndex, active, focus, callback )
|
||||
local object = setmetatable( {}, ListViewEx )
|
||||
|
||||
object.bounds = bounds:clone()
|
||||
object.text = text
|
||||
object.focus = focus
|
||||
object.scrollIndex = scrollIndex
|
||||
object.active = active
|
||||
object.focus = focus
|
||||
object.callback = callback
|
||||
object.visible = true
|
||||
|
||||
@@ -1296,9 +1325,13 @@ end
|
||||
|
||||
function ListViewEx:draw()
|
||||
local oldActive = self.active
|
||||
local oldScrollIndex = self.scrollIndex
|
||||
|
||||
self.active, self.scrollIndex, self.focus = RL.GuiListViewEx( self.bounds, self.text, self.focus, self.scrollIndex, self.active )
|
||||
_, self.scrollIndex, self.active, self.focus = RL.GuiListViewEx( self.bounds, self.text, self.scrollIndex, self.active, self.focus )
|
||||
|
||||
if self.scrollIndex ~= oldScrollIndex then
|
||||
Raygui.scrolling = true
|
||||
end
|
||||
if oldActive ~= self.active and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
@@ -1421,24 +1454,41 @@ function ColorPicker:new( bounds, text, color, callback )
|
||||
object.callback = callback
|
||||
|
||||
object.visible = true
|
||||
object.focusBounds = Rect:new()
|
||||
|
||||
object:updateFocusBounds()
|
||||
table.insert( Raygui.elements, object )
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function ColorPicker:process()
|
||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
|
||||
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.focusBounds )
|
||||
end
|
||||
|
||||
function ColorPicker:updateFocusBounds()
|
||||
local boundsHue = Rect:new(
|
||||
self.bounds.x + self.bounds.width + RL.GuiGetStyle( RL.COLORPICKER, RL.HUEBAR_PADDING ),
|
||||
self.bounds.y,
|
||||
RL.GuiGetStyle( RL.COLORPICKER, RL.HUEBAR_WIDTH ),
|
||||
self.bounds.height
|
||||
)
|
||||
|
||||
self.focusBounds = self.bounds:fit( boundsHue )
|
||||
end
|
||||
|
||||
function ColorPicker:draw()
|
||||
local oldColor = self.color:clone()
|
||||
local color = RL.GuiColorPicker( self.bounds, self.text, self.color )
|
||||
local _, color = RL.GuiColorPicker( self.bounds, self.text, self.color )
|
||||
|
||||
self.color = Color:new( color )
|
||||
|
||||
if oldColor ~= self.color and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
if self.color ~= oldColor then
|
||||
Raygui.scrolling = true
|
||||
|
||||
if self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1474,7 +1524,7 @@ end
|
||||
|
||||
function ColorPanel:draw()
|
||||
local oldColor = self.color:clone()
|
||||
local color = RL.GuiColorPanel( self.bounds, self.text, self.color )
|
||||
local _, color = RL.GuiColorPanel( self.bounds, self.text, self.color )
|
||||
|
||||
self.color = Color:new( color )
|
||||
|
||||
@@ -1515,10 +1565,14 @@ end
|
||||
|
||||
function ColorBarAlpha:draw()
|
||||
local oldAlpha = self.alpha
|
||||
self.alpha = RL.GuiColorBarAlpha( self.bounds, self.text, self.alpha )
|
||||
_, self.alpha = RL.GuiColorBarAlpha( self.bounds, self.text, self.alpha )
|
||||
|
||||
if self.alpha ~= oldAlpha and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
if self.alpha ~= oldAlpha then
|
||||
Raygui.scrolling = true
|
||||
|
||||
if self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1554,10 +1608,14 @@ end
|
||||
|
||||
function ColorBarHue:draw()
|
||||
local oldValue = self.value
|
||||
self.value = RL.GuiColorBarHue( self.bounds, self.text, self.value )
|
||||
_, self.value = RL.GuiColorBarHue( self.bounds, self.text, self.value )
|
||||
|
||||
if self.value ~= oldValue and self.callback ~= nil then
|
||||
self.callback( self )
|
||||
if self.value ~= oldValue then
|
||||
Raygui.scrolling = true
|
||||
|
||||
if self.callback ~= nil then
|
||||
self.callback( self )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1572,6 +1630,7 @@ Raygui.WindowBox = WindowBox
|
||||
Raygui.GroupBox = GroupBox
|
||||
Raygui.Line = Line
|
||||
Raygui.Panel = Panel
|
||||
Raygui.GuiTabBar = GuiTabBar
|
||||
Raygui.ScrollPanel = ScrollPanel
|
||||
|
||||
Raygui.Label = Label
|
||||
@@ -1585,7 +1644,6 @@ Raygui.DropdownBox = DropdownBox
|
||||
Raygui.Spinner = Spinner
|
||||
Raygui.ValueBox = ValueBox
|
||||
Raygui.TextBox = TextBox
|
||||
Raygui.TextBoxMulti = TextBoxMulti
|
||||
Raygui.Slider = Slider
|
||||
Raygui.SliderBar = SliderBar
|
||||
Raygui.ProgressBar = ProgressBar
|
||||
|
||||
@@ -3,6 +3,8 @@ if table.unpack == nil then
|
||||
table.unpack = unpack
|
||||
end
|
||||
|
||||
local Vector2 = require( "vector2" )
|
||||
|
||||
Rectangle = {}
|
||||
|
||||
Rectangle.meta = {
|
||||
@@ -34,7 +36,7 @@ Rectangle.meta = {
|
||||
__idiv = function( r, v )
|
||||
return Rectangle:new( r.x // v, r.y // v, r.width // v, r.height // v )
|
||||
end,
|
||||
__len = function( _ )
|
||||
__len = function()
|
||||
return 4
|
||||
end,
|
||||
__eq = function( r1, r2 )
|
||||
@@ -108,6 +110,17 @@ function Rectangle:area()
|
||||
return self.width * self.height
|
||||
end
|
||||
|
||||
function Rectangle:fit( rec )
|
||||
local pos = Vector2:new( math.min( self.x, rec.x ), math.min( self.y, rec.y ) )
|
||||
|
||||
return Rectangle:new(
|
||||
pos.x,
|
||||
pos.y,
|
||||
math.max( self.x + self.width - pos.x, rec.x + rec.width - pos.x ),
|
||||
math.max( self.y + self.height - pos.y, rec.y + rec.height - pos.y )
|
||||
)
|
||||
end
|
||||
|
||||
function Rectangle:checkCollisionRec( rec )
|
||||
return RL.CheckCollisionRecs( self, rec )
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ Vector2.meta = {
|
||||
__unm = function( v )
|
||||
return Vector2:new( -v.x, -v.y )
|
||||
end,
|
||||
__len = function( _ )
|
||||
__len = function()
|
||||
return 2
|
||||
end,
|
||||
__eq = function( v1, v2 )
|
||||
|
||||
@@ -30,7 +30,7 @@ Vector3.meta = {
|
||||
__unm = function( v )
|
||||
return Vector3:new( -v.x, -v.y, -v.z )
|
||||
end,
|
||||
__len = function( _ )
|
||||
__len = function()
|
||||
return 3
|
||||
end,
|
||||
__eq = function( v1, v2 )
|
||||
|
||||
Reference in New Issue
Block a user