Raygui tree view.

This commit is contained in:
jussi
2024-03-20 19:18:01 +02:00
parent ae1d0b65f1
commit 842e0efe36
8 changed files with 693 additions and 112 deletions

View File

@@ -34,6 +34,7 @@ DETAILED CHANGES:
- ADDED: Raygui lib tooltip. - ADDED: Raygui lib tooltip.
- ADDED: Round. - ADDED: Round.
- ADDED: PubSub lib. - ADDED: PubSub lib.
- ADDED: Raygui lib tree view.
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0 Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0

View File

@@ -2,6 +2,9 @@ Current {
} }
Backlog { Backlog {
* Raygui
* Icon enums.
* Set callbacks to single table?
* 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

@@ -10,6 +10,8 @@ Raygui = require( "raygui" )
require( "sprite_button" ):register( Raygui ) require( "sprite_button" ):register( Raygui )
require( "property_list" ):register( Raygui ) require( "property_list" ):register( Raygui )
require( "tree_view" ):register( Raygui )
require( "tree_item" ):register( Raygui )
Gui = Raygui:new() Gui = Raygui:new()
@@ -72,11 +74,9 @@ 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",
-- Callback. nil, -- Callback.
nil, function( self ) Gui:set2Top( self ) end, -- Grab callback.
-- Grab callback. nil, -- Drag callback.
function( self ) Gui:set2Top( self ) end,
nil,
{ {
properties = { properties = {
-- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE }, -- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
@@ -240,6 +240,42 @@ local function addPropertyList()
end end
end end
local function selected( controls )
for i, control in ipairs( controls ) do
print( i, control.text, control._id )
end
end
local function addTreeView()
TreeView = Gui:TreeView(
Rect:new( 600, 20, 256, 328 ),
-- Rect:new( 600, 20, 256, 600 ),
"Tree View",
function( controls ) selected( controls ) end, -- Callback.
function( self ) Gui:set2Top( self ) end, -- Grab callback.
nil, -- Drag callback.
{
properties = {
-- { 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_PRESSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) },
}
}
)
-- Items.
local folder = TreeView:addItem( RL.GuiIconText( 1, "Images" ) )
local folderEmpty = TreeView:addItem( RL.GuiIconText( 1, "Empty Folder" ) )
local folder2 = TreeView:addItem( RL.GuiIconText( 1, "More images" ), folder )
TreeView:addItem( RL.GuiIconText( 12, "Cat.png" ), folder )
TreeView:addItem( RL.GuiIconText( 12, "Dog.png" ), folder2 )
TreeView:addItem( RL.GuiIconText( 12, "Horse.png" ), folder2 )
for i = 0, 10 do
TreeView:addItem( RL.GuiIconText( 12, "Duck"..i..".png" ), folder2 )
end
end
function RL.init() function RL.init()
local monitor = 0 local monitor = 0
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) )
@@ -264,6 +300,7 @@ function RL.init()
addSpriteButtons() addSpriteButtons()
addPropertyList() addPropertyList()
addTreeView()
end end
function RL.update( delta ) function RL.update( delta )

View File

@@ -1,25 +1,15 @@
local PropertyList = {} local PropertyList = {}
PropertyList.__index = PropertyList PropertyList.__index = PropertyList
local RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT = 24
function PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) function PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
local scrollBarWidth = RL.GuiGetStyle( RL.LISTVIEW, RL.SCROLLBAR_WIDTH )
local borderWidth = RL.GuiGetStyle( RL.DEFAULT, RL.BORDER_WIDTH )
object.padding = 4 -- Content edges. object.padding = 4 -- Content edges.
object.spacing = 4 -- Between controls. object.spacing = 4 -- Between controls.
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
object.content = Rect:new(
0,
RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT,
bounds.width - scrollBarWidth - object.padding * 2 - borderWidth * 2,
bounds.height - scrollBarWidth - object.padding * 2 - borderWidth * 2
)
object.scroll = Vec2:new() object.scroll = Vec2:new()
object.view = Rect:new() object.view = Rect:new()
object.callback = callback object.callback = callback
@@ -31,19 +21,17 @@ function PropertyList:new( bounds, text, callback, grabCallback, dragCallback, s
object.gui = Raygui:new() -- Contains full independent gui system. object.gui = Raygui:new() -- Contains full independent gui system.
object.controls = {} object.controls = {}
-- Set initial view. -- Set in setSize.
local _, _, view = RL.GuiScrollPanel( object.bounds, object.text, object.content, object.scroll, object.view ) object.framebufferSize = nil
object.view = Rect:new( view ) object.framebuffer = nil
object.defaultControlSize = nil
object.gui.view = Rect:new( 0, 0, object.view.width, object.view.height )
object.framebufferSize = Vec2:new( object.bounds.width, object.bounds.height - RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT )
object.framebuffer = RL.LoadRenderTexture( object.framebufferSize )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.draggable = true object.draggable = true
object.mouseScale = 1 -- Set this if drawing in different size to render texture for example. object.mouseScale = 1 -- Set this if drawing in different size to render texture for example.
object.defaultControlSize = Vec2:new( object.content.width, 22 )
object:setSize( Vec2:new( object.bounds.width, object.bounds.height ) )
object._forceCheckScroll = false object._forceCheckScroll = false
object._posY = 0 -- In control list update. object._posY = 0 -- In control list update.
@@ -61,7 +49,22 @@ local function getControlBounds( control )
return control.viewBounds or control.focusBounds or control.bounds return control.viewBounds or control.focusBounds or control.bounds
end end
local function setGroupText( text, active )
if active then
return RL.GuiIconText( 120, text )
else
return RL.GuiIconText( 119, text )
end
end
function PropertyList:updateControl( control ) function PropertyList:updateControl( control )
if control._defaultWidth then
control.bounds.width = self:getDefaultBounds().width
end
if control._defaultHeight then
control.bounds.height = self:getDefaultBounds().height
end
if control.visible then if control.visible then
control:setPosition( Vec2:new( control.bounds.x, self._posY ) ) control:setPosition( Vec2:new( control.bounds.x, self._posY ) )
local bounds = getControlBounds( control ) local bounds = getControlBounds( control )
@@ -82,6 +85,8 @@ function PropertyList:updateControl( control )
self:updateControl( groupControl ) self:updateControl( groupControl )
end end
control.text = setGroupText( control.text:sub( 6 ), control.active ) -- Sub skips icon.
end end
self.gui:set2Back( control ) self.gui:set2Back( control )
end end
@@ -106,8 +111,11 @@ end
function PropertyList:addControl( control, group, noYAdvance ) function PropertyList:addControl( control, group, noYAdvance )
control._noYAdvance = noYAdvance control._noYAdvance = noYAdvance
if control.bounds.width == 0 or control.bounds.height == 0 then if control.bounds.width == 0 then
control.bounds = self:getDefaultBounds() control._defaultWidth = true -- Set defaultWidth on updateControl.
end
if control.bounds.height == 0 then
control._defaultHeight = true -- Set defaultHeight on updateControl.
end end
if control.bounds.x == 0 then if control.bounds.x == 0 then
control.bounds.x = self.padding control.bounds.x = self.padding
@@ -123,14 +131,6 @@ function PropertyList:addControl( control, group, noYAdvance )
return control return control
end end
local function setGroupText( text, active )
if active then
return RL.GuiIconText( 120, text )
else
return RL.GuiIconText( 119, text )
end
end
function PropertyList:addGroup( name, active, group ) function PropertyList:addGroup( name, active, group )
if active == nil then if active == nil then
active = false active = false
@@ -148,6 +148,8 @@ function PropertyList:addGroup( name, active, group )
} }
) )
control._controls = {} -- Prefix _ to try to prevent clashing with control definition. control._controls = {} -- Prefix _ to try to prevent clashing with control definition.
control._defaultWidth = true -- Set defaultWidth on updateControl.
control._defaultHeight = true -- Set defaultHeight on updateControl.
if group ~= nil then if group ~= nil then
table.insert( group._controls, control ) table.insert( group._controls, control )
@@ -160,7 +162,7 @@ function PropertyList:addGroup( name, active, group )
end end
function PropertyList:update() function PropertyList:update()
if not RL.CheckCollisionRecs( self.view, RL.GetMousePosition() ) then if not self.view:checkCollisionPoint( RL.GetMousePosition() ) then
self.gui.locked = true self.gui.locked = true
else else
self.gui.locked = false self.gui.locked = false
@@ -174,7 +176,7 @@ function PropertyList:update()
self.gui:draw() self.gui:draw()
RL.EndTextureMode() RL.EndTextureMode()
return self._parent:drag( self ) return self._gui:drag( self )
end end
function PropertyList:draw() function PropertyList:draw()
@@ -185,7 +187,7 @@ function PropertyList:draw()
if self.scroll ~= oldScroll or self._forceCheckScroll then if self.scroll ~= oldScroll or self._forceCheckScroll then
if not self._forceCheckScroll then if not self._forceCheckScroll then
self._parent:checkScrolling() self._gui:checkScrolling()
end end
self._forceCheckScroll = false self._forceCheckScroll = false
@@ -218,6 +220,35 @@ function PropertyList:setPosition( pos )
self:updateMouseOffset() self:updateMouseOffset()
end end
function PropertyList:setSize( size )
self.bounds.width = size.x
self.bounds.height = size.y
local scrollBarWidth = RL.GuiGetStyle( RL.LISTVIEW, RL.SCROLLBAR_WIDTH )
local borderWidth = RL.GuiGetStyle( RL.DEFAULT, RL.BORDER_WIDTH )
self.content = Rect:new(
0,
self.gui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT,
self.bounds.width - scrollBarWidth - self.padding * 2 - borderWidth * 2,
self.bounds.height - scrollBarWidth - self.padding * 2 - borderWidth * 2
)
self.defaultControlSize = Vec2:new( self.content.width, 22 )
local _, _, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
self.view = Rect:new( view )
self.gui.view = Rect:new( 0, 0, self.view.width, self.view.height )
self.framebufferSize = Vec2:new( self.bounds.width, self.bounds.height - self.gui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT )
if self.framebuffer ~= nil and not RL.IsGCUnloadEnabled() then
RL.UnloadRenderTexture( self.framebuffer )
end
self.framebuffer = RL.LoadRenderTexture( self.framebufferSize )
self:updateContent()
end
function PropertyList:register( gui ) function PropertyList:register( gui )
function gui:PropertyList( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) function gui:PropertyList( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
return self:addControl( PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) ) return self:addControl( PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) )

View File

@@ -3,7 +3,7 @@ SpriteButton.__index = SpriteButton
function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles, tooltip ) function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -21,12 +21,11 @@ function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, c
end end
function SpriteButton:update() function SpriteButton:update()
-- print( self.tooltip )
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
end end
function SpriteButton:draw() function SpriteButton:draw()
if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self:update() and not RL.GuiIsLocked() and not self._parent.scrolling then if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self:update() and not RL.GuiIsLocked() and not self._gui.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 )
@@ -34,7 +33,7 @@ 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._parent:clickedInBounds( self.bounds ) then if result == 1 and self.callback ~= nil and self._gui:clickedInBounds( self.bounds ) then
self.callback( self ) self.callback( self )
end end
end end

View File

@@ -0,0 +1,96 @@
local TreeItem = {}
TreeItem.__index = TreeItem
function TreeItem:new( bounds, text, callbacks, styles, tooltip )
local object = setmetatable( {}, self )
object._gui = nil
object.spacing = 4 -- Between controls.
object.bounds = bounds:clone()
object.text = text
object.callbacks = callbacks -- toggle, open.
object.controls = {}
object.active = false
object.open = false -- Show controls.
object.visible = true
object.disabled = false
object.styles = styles
object.tooltip = tooltip
object._depth = 0
object._indentation = 0
object._id = 0 -- Id in treeView.
object._parent = nil
object._childId = 0 -- Id in parent controls.
return object
end
function TreeItem:update()
return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
end
function TreeItem:setOpenIcon()
if self.open then
return RL.GuiIconText( 120, "" )
else
return RL.GuiIconText( 119, "" )
end
end
function TreeItem:draw()
local buttonRect = Rect:new()
local hasContainer = 0 < #self.controls
local lineCol = RL.GetColor( RL.GuiGetStyle( RL.DEFAULT, RL.LINE_COLOR ) )
if hasContainer then
buttonRect:set( self.bounds.x, self.bounds.y, self.bounds.height, self.bounds.height )
end
-- Draw indentation lines.
for i = 0, self._depth - 1 do
RL.DrawRectangle( {
self.bounds.x - i * self._indentation - self._indentation / 2,
self.bounds.y - self.spacing,
1,
self.bounds.height + self.spacing * 2
}, lineCol )
end
local toggleRect = Rect:new(
self.bounds.x + buttonRect.width,
self.bounds.y,
self.bounds.width - buttonRect.width,
self.bounds.height
)
local oldActive = self.active
_, self.active = RL.GuiToggle( toggleRect, self.text, self.active )
if self.callbacks.toggle and oldActive ~= self.active then
self.callbacks.toggle( self )
end
if hasContainer then
local pressed = RL.GuiLabelButton( buttonRect, self:setOpenIcon() )
if self.callbacks.open and 0 < pressed then
self.open = not self.open
self.callbacks.open( self )
end
end
end
function TreeItem:setPosition( pos )
self.bounds.x = pos.x
self.bounds.y = pos.y
end
function TreeItem:register( gui )
function gui:TreeItem( bounds, text, callbacks, styles, tooltip )
return self:addControl( TreeItem:new( bounds, text, callbacks, styles, tooltip ) )
end
end
return TreeItem

View File

@@ -0,0 +1,414 @@
local TreeView = {}
TreeView.__index = TreeView
TreeView.SINGLE_SELECT = 0
TreeView.MULTI_SELECT = 1
TreeView.RANGE_SELECT = 2
TreeView.MOVE_ITEM_NONE = 0
TreeView.MOVE_ITEM_IN = 1
TreeView.MOVE_ITEM_UP = 2
TreeView.MOVE_ITEM_DOWN = 3
function TreeView:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self )
object._gui = nil
object.padding = 4 -- Content edges.
object.spacing = 4 -- Between controls.
object.indentation = 14 -- Indentation for one depth level.
object.bounds = bounds:clone()
object.text = text
object.scroll = Vec2:new()
object.view = Rect:new()
object.callback = callback
object.grabCallback = grabCallback
object.dragCallback = dragCallback
object.styles = styles
object.tooltip = tooltip
object.gui = Raygui:new() -- Contains full independent gui system.
object.controls = {}
-- Set in setSize.
object.framebufferSize = nil
object.framebuffer = nil
object.defaultControlSize = nil
object.visible = true
object.disabled = false
object.draggable = true
object.mouseScale = 1 -- Set this if drawing in different size to render texture for example.
object.selectedItems = {}
object:setSize( Vec2:new( object.bounds.width, object.bounds.height ) )
object._forceCheckScroll = false
object._posY = 0 -- In control list update.
object._curDepth = 0 -- Current indentation.
object._curId = 0 -- Running number to give id's for controls.
object._idRange = { 1, 1 }
object._lastActiveItem = nil
object._clickedItem = nil
object._movingItem = object.MOVE_ITEM_NONE
object:updateMouseOffset()
return object
end
function TreeView:getDefaultBounds()
return Rect:new( self.padding, self.padding, self.defaultControlSize.x, self.defaultControlSize.y )
end
local function getControlBounds( control )
return control.viewBounds or control.focusBounds or control.bounds
end
function TreeView:updateControl( control )
control.bounds = self:getDefaultBounds()
control._depth = self._curDepth
control._indentation = self.indentation
control._id = self._curId
self._curId = self._curId + 1
if control.visible then
control:setPosition( Vec2:new( control.bounds.x, self._posY ) )
local bounds = getControlBounds( control )
bounds.x = bounds.x + self._curDepth * self.indentation
bounds.width = bounds.width - self._curDepth * self.indentation
if not control._noYAdvance then
self._posY = self._posY + bounds.height + self.spacing
end
self.content = self.content:fit( bounds )
end
if 0 < #control.controls then
self._curDepth = self._curDepth + 1
for i, groupControl in ipairs( control.controls ) do
groupControl.visible = control.open
groupControl._parent = control
groupControl._childId = i
if not control.open and 0 < #control.controls then
groupControl.open = false
groupControl.active = false
end
self:updateControl( groupControl )
end
self._curDepth = self._curDepth - 1
end
end
function TreeView:updateContent()
self._posY = self.padding
self._curId = 1
self.content.width = 0
self.content.height = 0
for i, control in ipairs( self.controls ) do
control._parent = nil -- Sets parent in updateControl if any.
control._childId = i
self:updateControl( control )
end
self.content.x = 0
self.content.y = 0
self.content.height = self.content.height + self.padding
self.content.width = self.content.width + self.padding
self._forceCheckScroll = true
end
function TreeView:addItem( name, group )
local control = self.gui:TreeItem(
self:getDefaultBounds(),
name,
{ -- Callbacks.
open = function( this ) self:updateContent() end,
toggle = function( this ) self:itemSelect( this ) end,
},
{ -- Styles.
properties = {
{ RL.TOGGLE, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT },
{ RL.TOGGLE, RL.BASE_COLOR_NORMAL, RL.ColorToInt( RL.BLANK ) },
{ RL.TOGGLE, RL.BORDER_COLOR_NORMAL, RL.ColorToInt( RL.BLANK ) },
}
}
)
if group ~= nil then
table.insert( group.controls, control )
else
table.insert( self.controls, control )
end
self:updateContent()
return control
end
function TreeView:checkItem( controls, item, mode )
for _, control in ipairs( controls ) do
if mode == self.SINGLE_SELECT and control ~= item then
control.active = false
end
if 0 < #control.controls then
self:checkItem( control.controls, item, mode )
end
if mode == self.RANGE_SELECT then
if self._idRange[1] <= control._id and control._id <= self._idRange[2] then
control.active = true
end
end
if control.active then
table.insert( self.selectedItems, control )
-- table.insert( self.selectedItems, 1, control )
end
end
end
-- Check if trying to move parent to child.
function TreeView:isChild( item, newParent )
local to = newParent
while to ~= nil do
to = to._parent
if item == to then
return true
end
end
return false
end
function TreeView:itemSelect( item )
-- Item move.
local moveItems = {}
if self._movingItem ~= self.MOVE_ITEM_NONE then
for i = #self.selectedItems, 1, -1 do
local moveItem = self.selectedItems[i]
-- print( moveItem.text, "moveItem._id", moveItem._id, item.text, "item._id", item._id )
if moveItem ~= item and not self:isChild( moveItem, item ) then
local parentControls = self.controls
if moveItem._parent ~= nil then
parentControls = moveItem._parent.controls
end
local pos = #self.selectedItems - i + 1
if moveItem._parent == item._parent and moveItem._childId < item._childId then
pos = 1
end
table.insert( moveItems, pos, table.remove( parentControls, moveItem._childId ) )
end
moveItem.active = false
end
for _, moveItem in ipairs( moveItems ) do
local newParentControls = self.controls
if item._parent ~= nil then
newParentControls = item._parent.controls
end
local offset = 0
if moveItem._parent == item._parent and moveItem._childId < item._childId then
offset = -1
end
if self._movingItem == self.MOVE_ITEM_IN then
table.insert( item.controls, 1, moveItem )
elseif self._movingItem == self.MOVE_ITEM_UP then
local pos = RL.Clamp( item._childId + offset, 1, #newParentControls + 1 )
table.insert( newParentControls, pos, moveItem )
elseif self._movingItem == self.MOVE_ITEM_DOWN then
local pos = RL.Clamp( item._childId + offset + 1, 1, #newParentControls + 1 )
table.insert( newParentControls, pos, moveItem )
end
end
item.active = false
self._movingItem = self.MOVE_ITEM_NONE
self:updateContent()
return
end
-- Item select.
local mode = self.SINGLE_SELECT
if RL.IsKeyDown( RL.KEY_LEFT_CONTROL ) or RL.IsKeyDown( RL.KEY_RIGHT_CONTROL ) then
mode = self.MULTI_SELECT
elseif RL.IsKeyDown( RL.KEY_LEFT_SHIFT ) or RL.IsKeyDown( RL.KEY_RIGHT_SHIFT ) then
mode = self.RANGE_SELECT
end
if self._lastActiveItem ~= nil then
self._idRange = { math.min( self._lastActiveItem._id, item._id ), math.max( self._lastActiveItem._id, item._id ) }
end
self.selectedItems = {}
self:checkItem( self.controls, item, mode )
if mode ~= self.RANGE_SELECT then
self._lastActiveItem = item -- Old clicked.
end
if self.callback ~= nil then
self.callback( self.selectedItems )
end
end
function TreeView:update()
local mousePos = Vec2:new( RL.GetMousePosition() )
local guiMousePos = mousePos + self.gui.mouseOffset
local mouseInView = self.view:checkCollisionPoint( mousePos )
if not mouseInView then
self.gui.locked = true
else
self.gui.locked = false
end
self.gui:update()
local mouseInClickedItem = false
if RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then
if 0 < self.gui.focused and mouseInView and self.gui.controls[ self.gui.focused ].active then
self._clickedItem = self.gui.controls[ self.gui.focused ]
else
self._clickedItem = nil
end
end
if self._clickedItem ~= nil then
mouseInClickedItem = self._clickedItem.bounds:checkCollisionPoint( guiMousePos )
end
RL.BeginTextureMode( self.framebuffer )
RL.ClearBackground( RL.BLANK )
RL.rlTranslatef( { self.scroll.x, self.scroll.y, 0 } )
self.gui:draw()
if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self._clickedItem ~= nil
and not mouseInClickedItem and 0 < self.gui.focused then
local focusBounds = self.gui.controls[ self.gui.focused ].bounds
local relY = ( guiMousePos.y - focusBounds.y ) / focusBounds.height
if relY <= 0.35 then
RL.DrawLine(
{ focusBounds.x, focusBounds.y },
{ focusBounds.x + focusBounds.width, focusBounds.y },
6, RL.RED
)
self._movingItem = self.MOVE_ITEM_UP
elseif 0.65 <= relY then
RL.DrawLine(
{ focusBounds.x, focusBounds.y + focusBounds.height },
{ focusBounds.x + focusBounds.width, focusBounds.y + focusBounds.height },
6, RL.RED
)
self._movingItem = self.MOVE_ITEM_DOWN
else
RL.DrawRectangleLines( focusBounds, RL.RED )
self._movingItem = self.MOVE_ITEM_IN
end
elseif RL.IsMouseButtonReleased( RL.MOUSE_BUTTON_LEFT ) then
self._clickedItem = nil
self._movingItem = self.MOVE_ITEM_NONE
end
RL.EndTextureMode()
return self._gui:drag( self )
end
function TreeView:draw()
local oldScroll = self.scroll:clone()
local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
self.view:set( view )
self.scroll:set( scroll )
if self.scroll ~= oldScroll or self._forceCheckScroll then
if not self._forceCheckScroll then
self._gui:checkScrolling()
end
self._forceCheckScroll = false
self:updateMouseOffset()
self.gui.view:set( -self.scroll.x, -self.scroll.y, self.view.width, self.view.height )
end
RL.DrawTexturePro(
RL.GetRenderTextureTexture( self.framebuffer ),
{ 0, self.framebufferSize.y - self.view.height, 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 TreeView:updateMouseOffset()
self.gui.mouseOffset = Vec2:new( -self.view.x - self.scroll.x, -self.view.y - self.scroll.y ):scale( self.mouseScale )
end
function TreeView:setPosition( pos )
self.bounds.x = pos.x
self.bounds.y = pos.y
self:updateMouseOffset()
end
function TreeView:setSize( size )
self.bounds.width = size.x
self.bounds.height = size.y
local scrollBarWidth = RL.GuiGetStyle( RL.LISTVIEW, RL.SCROLLBAR_WIDTH )
local borderWidth = RL.GuiGetStyle( RL.DEFAULT, RL.BORDER_WIDTH )
self.content = Rect:new(
0,
self.gui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT,
self.bounds.width - scrollBarWidth - self.padding * 2 - borderWidth * 2,
self.bounds.height - scrollBarWidth - self.padding * 2 - borderWidth * 2
)
self.defaultControlSize = Vec2:new( self.content.width, 22 )
local _, _, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
self.view = Rect:new( view )
self.gui.view = Rect:new( 0, 0, self.view.width, self.view.height )
self.framebufferSize = Vec2:new( self.bounds.width, self.bounds.height - self.gui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT )
if self.framebuffer ~= nil and not RL.IsGCUnloadEnabled() then
RL.UnloadRenderTexture( self.framebuffer )
end
self.framebuffer = RL.LoadRenderTexture( self.framebufferSize )
self:updateContent()
end
function TreeView:register( gui )
function gui:TreeView( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
return self:addControl( TreeView:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) )
end
end
return TreeView

View File

@@ -54,7 +54,7 @@ WindowBox.__index = WindowBox
function WindowBox:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) function WindowBox:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -72,14 +72,14 @@ function WindowBox:new( bounds, text, callback, grabCallback, dragCallback, styl
end end
function WindowBox:update() function WindowBox:update()
return self._parent:drag( self ) return self._gui:drag( self )
end 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 then if result == 1 then
-- //TODO Could add self._parent:clickedInBounds( closeButtonBounds ) -- //TODO Could add self._gui:clickedInBounds( closeButtonBounds )
if self.callback ~= nil then if self.callback ~= nil then
self.callback( self ) self.callback( self )
end end
@@ -98,7 +98,7 @@ GroupBox.__index = GroupBox
function GroupBox:new( bounds, text, styles, tooltip ) function GroupBox:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -132,7 +132,7 @@ Line.__index = Line
function Line:new( bounds, text, styles, tooltip ) function Line:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -166,7 +166,7 @@ Panel.__index = Panel
function Panel:new( bounds, text, grabCallback, dragCallback, styles, tooltip ) function Panel:new( bounds, text, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -183,7 +183,7 @@ function Panel:new( bounds, text, grabCallback, dragCallback, styles, tooltip )
end end
function Panel:update() function Panel:update()
return self._parent:drag( self ) return self._gui:drag( self )
end end
function Panel:draw() function Panel:draw()
@@ -203,7 +203,7 @@ GuiTabBar.__index = GuiTabBar
function GuiTabBar:new( bounds, text, active, callback, closeCallback, styles, tooltip ) function GuiTabBar:new( bounds, text, active, callback, closeCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -230,7 +230,7 @@ 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 then if self.active ~= oldActive then
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.active = oldActive self.active = oldActive
return return
end end
@@ -239,7 +239,7 @@ function GuiTabBar:draw()
self.callback( self ) self.callback( self )
end end
end end
if 0 <= result and self.closeCallback ~= nil and self._parent:clickedInBounds( self.bounds ) then if 0 <= result and self.closeCallback ~= nil and self._gui:clickedInBounds( self.bounds ) then
self.closeCallback( self, result ) self.closeCallback( self, result )
end end
end end
@@ -257,7 +257,7 @@ ScrollPanel.__index = ScrollPanel
function ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback, dragCallback, styles, tooltip ) function ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -278,7 +278,7 @@ function ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback,
end end
function ScrollPanel:update() function ScrollPanel:update()
return self._parent:drag( self ) return self._gui:drag( self )
end end
function ScrollPanel:draw() function ScrollPanel:draw()
@@ -288,7 +288,7 @@ function ScrollPanel:draw()
self.scroll:set( scroll ) self.scroll:set( scroll )
if self.scroll ~= oldScroll then if self.scroll ~= oldScroll then
self._parent:checkScrolling() self._gui:checkScrolling()
if self.callback ~= nil then if self.callback ~= nil then
self.callback( self ) self.callback( self )
@@ -312,7 +312,7 @@ Label.__index = Label
function Label:new( bounds, text, styles, tooltip ) function Label:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -346,7 +346,7 @@ Button.__index = Button
function Button:new( bounds, text, callback, styles, tooltip ) function Button:new( bounds, text, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -367,7 +367,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 and self._parent:clickedInBounds( self.bounds ) then if result == 1 and self.callback ~= nil and self._gui:clickedInBounds( self.bounds ) then
self.callback( self ) self.callback( self )
end end
end end
@@ -385,7 +385,7 @@ LabelButton.__index = LabelButton
function LabelButton:new( bounds, text, callback, styles, tooltip ) function LabelButton:new( bounds, text, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -406,7 +406,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 and self._parent:clickedInBounds( self.bounds ) then if result == 1 and self.callback ~= nil and self._gui:clickedInBounds( self.bounds ) then
self.callback( self ) self.callback( self )
end end
end end
@@ -424,7 +424,7 @@ Toggle.__index = Toggle
function Toggle:new( bounds, text, active, callback, styles, tooltip ) function Toggle:new( bounds, text, active, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -449,7 +449,7 @@ 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 then if self.active ~= oldActive then
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.active = oldActive self.active = oldActive
return return
end end
@@ -473,7 +473,7 @@ ToggleGroup.__index = ToggleGroup
function ToggleGroup:new( bounds, text, active, callback, styles, tooltip ) function ToggleGroup:new( bounds, text, active, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -546,7 +546,7 @@ function ToggleGroup:draw()
local inBounds = false local inBounds = false
for _, bounds in ipairs( self.focusBounds ) do for _, bounds in ipairs( self.focusBounds ) do
if self._parent:clickedInBounds( bounds ) then if self._gui:clickedInBounds( bounds ) then
inBounds = true inBounds = true
break break
end end
@@ -578,7 +578,7 @@ CheckBox.__index = CheckBox
function CheckBox:new( bounds, text, checked, callback, styles, tooltip ) function CheckBox:new( bounds, text, checked, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -611,7 +611,7 @@ function CheckBox:draw()
self._focusBoundsOffset:set( self.focusBounds.x - self.bounds.x, self.focusBounds.y - self.bounds.y ) self._focusBoundsOffset:set( self.focusBounds.x - self.bounds.x, self.focusBounds.y - self.bounds.y )
if self.checked ~= oldChecked then if self.checked ~= oldChecked then
if not self._parent:clickedInBounds( self.focusBounds ) then if not self._gui:clickedInBounds( self.focusBounds ) then
self.checked = oldChecked self.checked = oldChecked
end end
@@ -636,7 +636,7 @@ ComboBox.__index = ComboBox
function ComboBox:new( bounds, text, active, callback, styles, tooltip ) function ComboBox:new( bounds, text, active, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -661,7 +661,7 @@ 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 then if self.active ~= oldActive then
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.active = oldActive self.active = oldActive
return return
end end
@@ -685,7 +685,7 @@ DropdownBox.__index = DropdownBox
function DropdownBox:new( bounds, text, active, editMode, callback, styles, tooltip ) function DropdownBox:new( bounds, text, active, editMode, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -752,7 +752,7 @@ Spinner.__index = Spinner
function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip ) function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -793,11 +793,11 @@ function Spinner:draw()
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
if result == 1 then if result == 1 then
self._parent:editMode( self.editMode ) self._gui:editMode( self.editMode )
self.editMode = not self.editMode self.editMode = not self.editMode
end end
if self.value ~= oldValue then if self.value ~= oldValue then
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.value = oldValue self.value = oldValue
return return
end end
@@ -823,7 +823,7 @@ ValueBox.__index = ValueBox
function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip ) function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -864,7 +864,7 @@ function ValueBox:draw()
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
if result == 1 then if result == 1 then
self._parent:editMode( self.editMode ) self._gui: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 and self.callback ~= nil then
@@ -887,7 +887,7 @@ TextBox.__index = TextBox
function TextBox:new( bounds, text, textSize, editMode, callback, styles, tooltip ) function TextBox:new( bounds, text, textSize, editMode, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -921,7 +921,7 @@ function TextBox:draw()
RL.EndScissorMode() RL.EndScissorMode()
end end
if result == 1 then if result == 1 then
self._parent:editMode( self.editMode ) self._gui:editMode( self.editMode )
self.editMode = not self.editMode self.editMode = not self.editMode
if not self.editMode and self.callback ~= nil then if not self.editMode and self.callback ~= nil then
@@ -943,7 +943,7 @@ Slider.__index = Slider
function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip ) function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.textLeft = textLeft object.textLeft = textLeft
@@ -980,11 +980,11 @@ function Slider:draw()
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
if self.value ~= oldValue then if self.value ~= oldValue then
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.value = oldValue self.value = oldValue
return return
end end
self._parent:checkScrolling() self._gui:checkScrolling()
if self.callback ~= nil then if self.callback ~= nil then
self.callback( self ) self.callback( self )
@@ -1007,7 +1007,7 @@ SliderBar.__index = SliderBar
function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip ) function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.textLeft = textLeft object.textLeft = textLeft
@@ -1044,11 +1044,11 @@ function SliderBar:draw()
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
if self.value ~= oldValue then if self.value ~= oldValue then
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.value = oldValue self.value = oldValue
return return
end end
self._parent:checkScrolling() self._gui:checkScrolling()
if self.callback ~= nil then if self.callback ~= nil then
self.callback( self ) self.callback( self )
@@ -1071,7 +1071,7 @@ ProgressBar.__index = ProgressBar
function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip ) function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.textLeft = textLeft object.textLeft = textLeft
@@ -1108,7 +1108,7 @@ function ProgressBar:draw()
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
if self.value ~= oldValue then if self.value ~= oldValue then
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.value = oldValue self.value = oldValue
return return
end end
@@ -1134,7 +1134,7 @@ StatusBar.__index = StatusBar
function StatusBar:new( bounds, text, styles, tooltip ) function StatusBar:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1168,7 +1168,7 @@ DummyRec.__index = DummyRec
function DummyRec:new( bounds, text, styles, tooltip ) function DummyRec:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1202,7 +1202,7 @@ Grid.__index = Grid
function Grid:new( bounds, text, spacing, subdivs, callback, styles, tooltip ) function Grid:new( bounds, text, spacing, subdivs, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1252,7 +1252,7 @@ ListView.__index = ListView
function ListView:new( bounds, text, scrollIndex, active, callback, styles, tooltip ) function ListView:new( bounds, text, scrollIndex, active, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1283,7 +1283,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:checkScrolling() self._gui: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 )
@@ -1303,7 +1303,7 @@ ListViewEx.__index = ListViewEx
function ListViewEx:new( bounds, text, scrollIndex, active, focus, callback, styles, tooltip ) function ListViewEx:new( bounds, text, scrollIndex, active, focus, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1335,7 +1335,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:checkScrolling() self._gui: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 )
@@ -1355,7 +1355,7 @@ MessageBox.__index = MessageBox
function MessageBox:new( bounds, title, message, buttons, callback, grabCallback, dragCallback, styles, tooltip ) function MessageBox:new( bounds, title, message, buttons, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.title = title object.title = title
@@ -1380,13 +1380,13 @@ function MessageBox:getItem( id )
end end
function MessageBox:update() function MessageBox:update()
return self._parent:drag( self ) return self._gui:drag( self )
end 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 and self._parent:clickedInBounds( self.bounds ) then if 0 <= self.buttonIndex and self.callback ~= nil and self._gui:clickedInBounds( self.bounds ) then
self.callback( self ) self.callback( self )
end end
end end
@@ -1404,7 +1404,7 @@ TextInputBox.__index = TextInputBox
function TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback, grabCallback, dragCallback, styles, tooltip ) function TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.title = title object.title = title
@@ -1432,13 +1432,13 @@ function TextInputBox:getItem( id )
end end
function TextInputBox:update() function TextInputBox:update()
return self._parent:drag( self ) return self._gui:drag( self )
end 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 and self._parent:clickedInBounds( self.bounds ) then if 0 <= self.buttonIndex and self.callback ~= nil and self._gui:clickedInBounds( self.bounds ) then
self.callback( self ) self.callback( self )
end end
end end
@@ -1456,7 +1456,7 @@ ColorPicker.__index = ColorPicker
function ColorPicker:new( bounds, text, color, callback, styles, tooltip ) function ColorPicker:new( bounds, text, color, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1496,11 +1496,11 @@ function ColorPicker:draw()
self.color = Color:new( color ) self.color = Color:new( color )
if self.color ~= oldColor then if self.color ~= oldColor then
if not self._parent:clickedInBounds( self.focusBounds ) then if not self._gui:clickedInBounds( self.focusBounds ) then
self.color = oldColor self.color = oldColor
return return
end end
self._parent:checkScrolling() self._gui:checkScrolling()
if self.callback ~= nil then if self.callback ~= nil then
self.callback( self ) self.callback( self )
@@ -1522,7 +1522,7 @@ ColorPanel.__index = ColorPanel
function ColorPanel:new( bounds, text, color, callback, styles, tooltip ) function ColorPanel:new( bounds, text, color, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1548,7 +1548,7 @@ function ColorPanel:draw()
self.color = Color:new( color ) self.color = Color:new( color )
if oldColor ~= self.color then if oldColor ~= self.color then
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.color = oldColor self.color = oldColor
return return
end end
@@ -1572,7 +1572,7 @@ ColorBarAlpha.__index = ColorBarAlpha
function ColorBarAlpha:new( bounds, text, alpha, callback, styles, tooltip ) function ColorBarAlpha:new( bounds, text, alpha, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1596,11 +1596,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
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.alpha = oldAlpha self.alpha = oldAlpha
return return
end end
self._parent:checkScrolling() self._gui:checkScrolling()
if self.callback ~= nil then if self.callback ~= nil then
self.callback( self ) self.callback( self )
@@ -1621,7 +1621,7 @@ ColorBarHue.__index = ColorBarHue
function ColorBarHue:new( bounds, text, value, callback, styles, tooltip ) function ColorBarHue:new( bounds, text, value, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
@@ -1645,11 +1645,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
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.value = oldValue self.value = oldValue
return return
end end
self._parent:checkScrolling() self._gui:checkScrolling()
if self.callback ~= nil then if self.callback ~= nil then
self.callback( self ) self.callback( self )
@@ -1670,7 +1670,7 @@ GuiScrollBar.__index = GuiScrollBar
function GuiScrollBar:new( bounds, value, minValue, maxValue, callback, styles, tooltip ) function GuiScrollBar:new( bounds, value, minValue, maxValue, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._gui = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.value = value object.value = value
@@ -1696,11 +1696,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
if not self._parent:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
self.value = oldValue self.value = oldValue
return return
end end
self._parent:checkScrolling() self._gui:checkScrolling()
if self.callback ~= nil then if self.callback ~= nil then
self.callback( self ) self.callback( self )
@@ -1764,7 +1764,7 @@ function Raygui:update()
self:drag( self.dragging ) self:drag( self.dragging )
return return
end end
-- Set mouse ofset if gui is for example embedded to some control. -- Set mouse offset if gui is for example embedded to some control.
RL.SetMouseOffset( self.mouseOffset ) RL.SetMouseOffset( self.mouseOffset )
if RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then if RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then
@@ -2012,7 +2012,7 @@ end
-- Control add functions. -- Control add functions.
function Raygui:addControl( control ) function Raygui:addControl( control )
control._parent = self control._gui = self
-- self:applyStyles( control ) -- self:applyStyles( control )
self:drawControl( control ) self:drawControl( control )
table.insert( self.controls, control ) table.insert( self.controls, control )