summaryrefslogtreecommitdiff
path: root/examples/raygui_extensions/property_list.lua
diff options
context:
space:
mode:
authorjussi2024-01-05 23:15:22 +0200
committerjussi2024-01-05 23:15:22 +0200
commit863f596b76043ec374fafa38f14cdc4a97d0b267 (patch)
tree9fbf9c424e2a1644b52b795715cdb60b6ed04eae /examples/raygui_extensions/property_list.lua
parent70a2bcba18aa9855380c132f89e26b61bfd2cb40 (diff)
downloadreilua-enhanced-863f596b76043ec374fafa38f14cdc4a97d0b267.tar.gz
reilua-enhanced-863f596b76043ec374fafa38f14cdc4a97d0b267.tar.bz2
reilua-enhanced-863f596b76043ec374fafa38f14cdc4a97d0b267.zip
Raygui lib enhancements and Raygui lib extensions example.
Diffstat (limited to 'examples/raygui_extensions/property_list.lua')
-rw-r--r--examples/raygui_extensions/property_list.lua100
1 files changed, 100 insertions, 0 deletions
diff --git a/examples/raygui_extensions/property_list.lua b/examples/raygui_extensions/property_list.lua
new file mode 100644
index 0000000..e05c84c
--- /dev/null
+++ b/examples/raygui_extensions/property_list.lua
@@ -0,0 +1,100 @@
+local PropertyList = {}
+PropertyList.__index = PropertyList
+
+function PropertyList:new( bounds, text, content, scroll, callback, grabCallback, dragCallback )
+ local object = setmetatable( {}, self )
+ object._parent = nil
+
+ object.bounds = bounds:clone()
+ object.text = text
+ object.content = content:clone()
+ object.scroll = scroll:clone()
+ object.view = Rect:new()
+ object.callback = callback
+ object.grabCallback = grabCallback
+ object.dragCallback = dragCallback
+
+ object.gui = Raygui:new() -- Contains full independent gui system.
+
+ -- Set initial view and scroll.
+ local _, scrollP, view = RL.GuiScrollPanel( object.bounds, object.text, object.content, object.scroll, object.view )
+ object.scroll = Vec2:new( scrollP )
+ object.view = Rect:new( view )
+
+ object.gui.view = Rect:new( 0, 0, object.view.width, object.view.height )
+ object.framebuffer = RL.LoadRenderTexture( { object.view.width, object.view.height } )
+
+ object.visible = true
+ object.disabled = false
+ object.draggable = true
+ object.mouseScale = 1
+
+ object:updateMouseOffset()
+
+ return object
+end
+
+function PropertyList:process()
+ if not RL.CheckCollisionRecs( self.view, RL.GetMousePosition() ) then
+ self.gui.locked = true
+ else
+ self.gui.locked = false
+ end
+
+ self.gui:process()
+
+ RL.BeginTextureMode( self.framebuffer )
+ RL.ClearBackground( RL.BLANK )
+ RL.rlTranslatef( { self.scroll.x, self.scroll.y, 0 } )
+ self.gui:draw()
+ RL.EndTextureMode()
+
+ return self._parent:drag( self )
+end
+
+function PropertyList:draw()
+ local oldScroll = self.scroll:clone()
+ local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
+
+ self.view = Rect:new( view )
+ self.scroll = Vec2:new( scroll )
+
+ if self.scroll ~= oldScroll then
+ self._parent:checkScrolling()
+
+ self.gui.view:set( -self.scroll.x, -self.scroll.y, self.view.width, self.view.height )
+ self:updateMouseOffset()
+
+ if self.callback ~= nil then
+ self.callback( self )
+ end
+ end
+
+ RL.DrawTexturePro(
+ RL.GetRenderTextureTexture( self.framebuffer ),
+ { 0, 0, self.view.width, -self.view.height },
+ { math.floor( self.view.x ), math.floor( self.view.y ), self.view.width, self.view.height },
+ { 0, 0 },
+ 0.0,
+ RL.WHITE
+ )
+end
+
+function PropertyList:updateMouseOffset()
+ self.gui.mouseOffset = Vec2:new( -self.view.x - self.scroll.x, -self.view.y - self.scroll.y ):scale( self.mouseScale )
+end
+
+function PropertyList:setPosition( pos )
+ self.bounds.x = pos.x
+ self.bounds.y = pos.y
+
+ self:updateMouseOffset()
+end
+
+function PropertyList:register( gui )
+ function gui:PropertyList( bounds, text, texture, nPatchNormal, nPatchPressed, callback )
+ return self:addElement( PropertyList:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback ) )
+ end
+end
+
+return PropertyList