Raygui lib tooltip.

This commit is contained in:
jussi
2024-02-21 23:25:17 +02:00
parent 836c9d1d00
commit 178196b0ff
10 changed files with 273 additions and 130 deletions

View File

@@ -5,6 +5,7 @@ KEY CHANGES:
- CHANGE: GetBufferData takes also position and length arguments. - CHANGE: GetBufferData takes also position and length arguments.
- ADDED: LoadImageFromData. - ADDED: LoadImageFromData.
- CHANGE: Process renamed to update to be more inline with naming of raylib and common convention. - CHANGE: Process renamed to update to be more inline with naming of raylib and common convention.
- ADDED: Raygui lib tooltip.
DETAILED CHANGES: DETAILED CHANGES:
- ADDED: GetBufferElementSize and GetBufferLength. - ADDED: GetBufferElementSize and GetBufferLength.

View File

@@ -42,7 +42,8 @@ local function addButton( bounds, text, callback )
{ RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) }, { RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) },
{ RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) }, { RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) },
}, },
} },
text
) )
end end
@@ -103,14 +104,26 @@ local function addPropertyList()
cat.dest.x, cat.dest.x,
32, 32,
false, false,
function( self ) self.value = getTextValue( self.text ) self.text = tostring( self.value ) cat.dest.x = self.value end function( self )
self.value = getTextValue( self.text )
self.text = tostring( self.value )
cat.dest.x = self.value
end,
nil,
"Position X"
), transformGroup, true ) ), transformGroup, true )
PropertyList:addControl( PropertyList.gui:TextBox( PropertyList:addControl( PropertyList.gui:TextBox(
Rect:new( 74, 0, 64, 22 ), Rect:new( 74, 0, 64, 22 ),
cat.dest.y, cat.dest.y,
32, 32,
false, false,
function( self ) self.value = getTextValue( self.text ) self.text = tostring( self.value ) cat.dest.y = self.value end function( self )
self.value = getTextValue( self.text )
self.text = tostring( self.value )
cat.dest.y = self.value
end,
nil,
"Position Y"
), transformGroup ) ), transformGroup )
-- Origin. -- Origin.
PropertyList:addControl( PropertyList.gui:Label( PropertyList:addControl( PropertyList.gui:Label(
@@ -122,18 +135,29 @@ local function addPropertyList()
cat.dest.x, cat.dest.x,
32, 32,
false, false,
function( self ) self.value = getTextValue( self.text ) self.text = tostring( self.value ) cat.origin.x = self.value end function( self )
self.value = getTextValue( self.text )
self.text = tostring( self.value )
cat.origin.x = self.value
end,
nil,
"Origin X"
), transformGroup, true ) ), transformGroup, true )
PropertyList:addControl( PropertyList.gui:TextBox( PropertyList:addControl( PropertyList.gui:TextBox(
Rect:new( 74, 0, 64, 22 ), Rect:new( 74, 0, 64, 22 ),
cat.dest.y, cat.dest.y,
32, 32,
false, false,
function( self ) self.value = getTextValue( self.text ) self.text = tostring( self.value ) cat.origin.y = self.value end function( self )
self.value = getTextValue( self.text )
self.text = tostring( self.value )
cat.origin.y = self.value
end,
nil,
"Origin Y"
), transformGroup ) ), transformGroup )
-- Rotation. -- Rotation.
PropertyList:addControl( PropertyList.gui:Slider( PropertyList:addControl( PropertyList.gui:Slider(
-- Rect:new( 112, 0, PropertyList.defaultControlSize.x - 150, 22 ),
Rect:new( 60, 0, PropertyList.defaultControlSize.x - 150, 22 ), Rect:new( 60, 0, PropertyList.defaultControlSize.x - 150, 22 ),
"Rotation", "Rotation",
"0", "0",
@@ -144,14 +168,18 @@ local function addPropertyList()
self.value = Util.round( self.value ) self.value = Util.round( self.value )
cat.rotation = self.value cat.rotation = self.value
self.textRight = self.value self.textRight = self.value
end end,
nil,
"Rotation angle"
), transformGroup ) ), transformGroup )
-- Flipped. -- Flipped.
PropertyList:addControl( PropertyList.gui:CheckBox( PropertyList:addControl( PropertyList.gui:CheckBox(
Rect:new( 0, 0, 20, 20 ), Rect:new( 0, 0, 20, 20 ),
"Flipped", "Flipped",
cat.flipped, cat.flipped,
function( self ) cat.flipped = self.checked end function( self ) cat.flipped = self.checked end,
nil,
"Flips the image"
), transformGroup ) ), transformGroup )
-- Visibility. -- Visibility.
@@ -196,7 +224,6 @@ local function addPropertyList()
for i = 1, 5 do for i = 1, 5 do
PropertyList:addControl( PropertyList.gui:CheckBox( PropertyList:addControl( PropertyList.gui:CheckBox(
-- Rect:new( 0, 0, 20, 20 ),
Rect:new( 128, 0, 20, 20 ), Rect:new( 128, 0, 20, 20 ),
i.."_Visible", i.."_Visible",
false, false,
@@ -246,9 +273,23 @@ function RL.draw()
if cat.visible then if cat.visible then
if cat.flipped then if cat.flipped then
RL.DrawTexturePro( cat.texture, { cat.source.x, cat.source.y, -cat.source.width, cat.source.height }, cat.dest, cat.origin, cat.rotation, cat.tint ) RL.DrawTexturePro(
cat.texture,
{ cat.source.x, cat.source.y, -cat.source.width, cat.source.height },
cat.dest,
cat.origin,
cat.rotation,
cat.tint
)
else else
RL.DrawTexturePro( cat.texture, cat.source, cat.dest, cat.origin, cat.rotation, cat.tint ) RL.DrawTexturePro(
cat.texture,
cat.source,
cat.dest,
cat.origin,
cat.rotation,
cat.tint
)
end end
end end
Gui:draw() Gui:draw()

View File

@@ -3,7 +3,7 @@ PropertyList.__index = PropertyList
local RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT = 24 local RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT = 24
function PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles ) function PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -26,6 +26,7 @@ function PropertyList:new( bounds, text, callback, grabCallback, dragCallback, s
object.grabCallback = grabCallback object.grabCallback = grabCallback
object.dragCallback = dragCallback object.dragCallback = dragCallback
object.styles = styles object.styles = styles
object.tooltip = tooltip
object.gui = Raygui:new() -- Contains full independent gui system. object.gui = Raygui:new() -- Contains full independent gui system.
object.controls = {} object.controls = {}
@@ -218,8 +219,8 @@ function PropertyList:setPosition( pos )
end end
function PropertyList:register( gui ) function PropertyList:register( gui )
function gui:PropertyList( bounds, text, callback, grabCallback, dragCallback, styles ) function gui:PropertyList( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
return self:addControl( PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles ) ) return self:addControl( PropertyList:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) )
end end
end end

View File

@@ -1,7 +1,7 @@
local SpriteButton = {} local SpriteButton = {}
SpriteButton.__index = SpriteButton SpriteButton.__index = SpriteButton
function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles ) function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -12,6 +12,7 @@ function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, c
object.nPatchPressed = nPatchPressed object.nPatchPressed = nPatchPressed
object.callback = callback object.callback = callback
object.styles = styles object.styles = styles
object.tooltip = tooltip
object.visible = true object.visible = true
object.disabled = false object.disabled = false
@@ -20,6 +21,7 @@ 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
@@ -43,8 +45,8 @@ function SpriteButton:setPosition( pos )
end end
function SpriteButton:register( gui ) function SpriteButton:register( gui )
function gui:SpriteButton( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles ) function gui:SpriteButton( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles, tooltip )
return self:addControl( SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles ) ) return self:addControl( SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback, styles, tooltip ) )
end end
end end

View File

@@ -52,7 +52,7 @@ end
local WindowBox = {} local WindowBox = {}
WindowBox.__index = WindowBox WindowBox.__index = WindowBox
function WindowBox:new( bounds, text, callback, grabCallback, dragCallback, styles ) function WindowBox:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -66,6 +66,7 @@ function WindowBox:new( bounds, text, callback, grabCallback, dragCallback, styl
object.disabled = false object.disabled = false
object.draggable = true object.draggable = true
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -95,13 +96,14 @@ end
local GroupBox = {} local GroupBox = {}
GroupBox.__index = GroupBox GroupBox.__index = GroupBox
function GroupBox:new( bounds, text, styles ) function GroupBox:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
object.styles = styles object.styles = styles
object.tooltip = tooltip
object.visible = true object.visible = true
object.disabled = false object.disabled = false
@@ -128,7 +130,7 @@ end
local Line = {} local Line = {}
Line.__index = Line Line.__index = Line
function Line:new( bounds, text, styles ) function Line:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -138,6 +140,7 @@ function Line:new( bounds, text, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -161,7 +164,7 @@ end
local Panel = {} local Panel = {}
Panel.__index = Panel Panel.__index = Panel
function Panel:new( bounds, text, grabCallback, dragCallback, styles ) function Panel:new( bounds, text, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -174,6 +177,7 @@ function Panel:new( bounds, text, grabCallback, dragCallback, styles )
object.disabled = false object.disabled = false
object.draggable = true object.draggable = true
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -197,7 +201,7 @@ end
local GuiTabBar = {} local GuiTabBar = {}
GuiTabBar.__index = GuiTabBar GuiTabBar.__index = GuiTabBar
function GuiTabBar:new( bounds, text, active, callback, closeCallback, styles ) function GuiTabBar:new( bounds, text, active, callback, closeCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -210,6 +214,7 @@ function GuiTabBar:new( bounds, text, active, callback, closeCallback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -250,7 +255,7 @@ end
local ScrollPanel = {} local ScrollPanel = {}
ScrollPanel.__index = ScrollPanel ScrollPanel.__index = ScrollPanel
function ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback, dragCallback, styles ) function ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -267,6 +272,7 @@ function ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback,
object.disabled = false object.disabled = false
object.draggable = true object.draggable = true
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -304,7 +310,7 @@ end
local Label = {} local Label = {}
Label.__index = Label Label.__index = Label
function Label:new( bounds, text, styles ) function Label:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -314,6 +320,7 @@ function Label:new( bounds, text, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -337,7 +344,7 @@ end
local Button = {} local Button = {}
Button.__index = Button Button.__index = Button
function Button:new( bounds, text, callback, styles ) function Button:new( bounds, text, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -348,6 +355,7 @@ function Button:new( bounds, text, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -375,7 +383,7 @@ end
local LabelButton = {} local LabelButton = {}
LabelButton.__index = LabelButton LabelButton.__index = LabelButton
function LabelButton:new( bounds, text, callback, styles ) function LabelButton:new( bounds, text, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -386,6 +394,7 @@ function LabelButton:new( bounds, text, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -413,7 +422,7 @@ end
local Toggle = {} local Toggle = {}
Toggle.__index = Toggle Toggle.__index = Toggle
function Toggle:new( bounds, text, active, callback, styles ) function Toggle:new( bounds, text, active, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -425,6 +434,7 @@ function Toggle:new( bounds, text, active, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -461,7 +471,7 @@ end
local ToggleGroup = {} local ToggleGroup = {}
ToggleGroup.__index = ToggleGroup ToggleGroup.__index = ToggleGroup
function ToggleGroup:new( bounds, text, active, callback, styles ) function ToggleGroup:new( bounds, text, active, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -475,6 +485,7 @@ function ToggleGroup:new( bounds, text, active, callback, styles )
object.focusBounds = {} object.focusBounds = {}
object.viewBounds = bounds:clone() object.viewBounds = bounds:clone()
object.styles = styles object.styles = styles
object.tooltip = tooltip
object:updateFocusBounds() object:updateFocusBounds()
return object return object
@@ -565,7 +576,7 @@ end
local CheckBox = {} local CheckBox = {}
CheckBox.__index = CheckBox CheckBox.__index = CheckBox
function CheckBox:new( bounds, text, checked, callback, styles ) function CheckBox:new( bounds, text, checked, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -581,6 +592,7 @@ function CheckBox:new( bounds, text, checked, callback, styles )
object._focusBoundsOffset = Vec2:new() -- Used in set position. object._focusBoundsOffset = Vec2:new() -- Used in set position.
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -622,7 +634,7 @@ end
local ComboBox = {} local ComboBox = {}
ComboBox.__index = ComboBox ComboBox.__index = ComboBox
function ComboBox:new( bounds, text, active, callback, styles ) function ComboBox:new( bounds, text, active, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -634,6 +646,7 @@ function ComboBox:new( bounds, text, active, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -670,7 +683,7 @@ end
local DropdownBox = {} local DropdownBox = {}
DropdownBox.__index = DropdownBox DropdownBox.__index = DropdownBox
function DropdownBox:new( bounds, text, active, editMode, callback, styles ) function DropdownBox:new( bounds, text, active, editMode, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -684,6 +697,7 @@ function DropdownBox:new( bounds, text, active, editMode, callback, styles )
object.disabled = false object.disabled = false
object.editModeBounds = bounds:clone() object.editModeBounds = bounds:clone()
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -736,7 +750,7 @@ end
local Spinner = {} local Spinner = {}
Spinner.__index = Spinner Spinner.__index = Spinner
function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callback, styles ) function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -755,6 +769,7 @@ function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callbac
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new()
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -806,7 +821,7 @@ end
local ValueBox = {} local ValueBox = {}
ValueBox.__index = ValueBox ValueBox.__index = ValueBox
function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callback, styles ) function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -825,6 +840,7 @@ function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callba
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new()
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -869,7 +885,7 @@ end
local TextBox = {} local TextBox = {}
TextBox.__index = TextBox TextBox.__index = TextBox
function TextBox:new( bounds, text, textSize, editMode, callback, styles ) function TextBox:new( bounds, text, textSize, editMode, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -883,6 +899,7 @@ function TextBox:new( bounds, text, textSize, editMode, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -924,7 +941,7 @@ end
local Slider = {} local Slider = {}
Slider.__index = Slider Slider.__index = Slider
function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -944,6 +961,7 @@ function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, cal
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new()
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -987,7 +1005,7 @@ end
local SliderBar = {} local SliderBar = {}
SliderBar.__index = SliderBar SliderBar.__index = SliderBar
function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1007,6 +1025,7 @@ function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue,
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new()
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1050,7 +1069,7 @@ end
local ProgressBar = {} local ProgressBar = {}
ProgressBar.__index = ProgressBar ProgressBar.__index = ProgressBar
function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1070,6 +1089,7 @@ function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new()
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1112,7 +1132,7 @@ end
local StatusBar = {} local StatusBar = {}
StatusBar.__index = StatusBar StatusBar.__index = StatusBar
function StatusBar:new( bounds, text, styles ) function StatusBar:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1122,6 +1142,7 @@ function StatusBar:new( bounds, text, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1145,7 +1166,7 @@ end
local DummyRec = {} local DummyRec = {}
DummyRec.__index = DummyRec DummyRec.__index = DummyRec
function DummyRec:new( bounds, text, styles ) function DummyRec:new( bounds, text, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1155,6 +1176,7 @@ function DummyRec:new( bounds, text, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1178,7 +1200,7 @@ end
local Grid = {} local Grid = {}
Grid.__index = Grid Grid.__index = Grid
function Grid:new( bounds, text, spacing, subdivs, callback, styles ) function Grid:new( bounds, text, spacing, subdivs, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1192,6 +1214,7 @@ function Grid:new( bounds, text, spacing, subdivs, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1227,7 +1250,7 @@ end
local ListView = {} local ListView = {}
ListView.__index = ListView ListView.__index = ListView
function ListView:new( bounds, text, scrollIndex, active, callback, styles ) function ListView:new( bounds, text, scrollIndex, active, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1240,6 +1263,7 @@ function ListView:new( bounds, text, scrollIndex, active, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1277,7 +1301,7 @@ end
local ListViewEx = {} local ListViewEx = {}
ListViewEx.__index = ListViewEx ListViewEx.__index = ListViewEx
function ListViewEx:new( bounds, text, scrollIndex, active, focus, callback, styles ) function ListViewEx:new( bounds, text, scrollIndex, active, focus, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1291,6 +1315,7 @@ function ListViewEx:new( bounds, text, scrollIndex, active, focus, callback, sty
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1328,7 +1353,7 @@ end
local MessageBox = {} local MessageBox = {}
MessageBox.__index = MessageBox MessageBox.__index = MessageBox
function MessageBox:new( bounds, title, message, buttons, callback, grabCallback, dragCallback, styles ) function MessageBox:new( bounds, title, message, buttons, callback, grabCallback, dragCallback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1345,6 +1370,7 @@ function MessageBox:new( bounds, title, message, buttons, callback, grabCallback
object.disabled = false object.disabled = false
object.draggable = true object.draggable = true
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1376,7 +1402,7 @@ end
local TextInputBox = {} local TextInputBox = {}
TextInputBox.__index = TextInputBox TextInputBox.__index = TextInputBox
function TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback, grabCallback, dragCallback, styles ) 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._parent = nil
@@ -1396,6 +1422,7 @@ function TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, s
object.disabled = false object.disabled = false
object.draggable = true object.draggable = true
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1427,7 +1454,7 @@ end
local ColorPicker = {} local ColorPicker = {}
ColorPicker.__index = ColorPicker ColorPicker.__index = ColorPicker
function ColorPicker:new( bounds, text, color, callback, styles ) function ColorPicker:new( bounds, text, color, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1440,6 +1467,7 @@ function ColorPicker:new( bounds, text, color, callback, styles )
object.disabled = false object.disabled = false
object.focusBounds = Rect:new() object.focusBounds = Rect:new()
object.styles = styles object.styles = styles
object.tooltip = tooltip
object:updateFocusBounds() object:updateFocusBounds()
@@ -1492,7 +1520,7 @@ end
local ColorPanel = {} local ColorPanel = {}
ColorPanel.__index = ColorPanel ColorPanel.__index = ColorPanel
function ColorPanel:new( bounds, text, color, callback, styles ) function ColorPanel:new( bounds, text, color, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1504,6 +1532,7 @@ function ColorPanel:new( bounds, text, color, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1541,7 +1570,7 @@ end
local ColorBarAlpha = {} local ColorBarAlpha = {}
ColorBarAlpha.__index = ColorBarAlpha ColorBarAlpha.__index = ColorBarAlpha
function ColorBarAlpha:new( bounds, text, alpha, callback, styles ) function ColorBarAlpha:new( bounds, text, alpha, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1553,6 +1582,7 @@ function ColorBarAlpha:new( bounds, text, alpha, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1589,7 +1619,7 @@ end
local ColorBarHue = {} local ColorBarHue = {}
ColorBarHue.__index = ColorBarHue ColorBarHue.__index = ColorBarHue
function ColorBarHue:new( bounds, text, value, callback, styles ) function ColorBarHue:new( bounds, text, value, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1601,6 +1631,7 @@ function ColorBarHue:new( bounds, text, value, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1637,7 +1668,7 @@ end
local GuiScrollBar = {} local GuiScrollBar = {}
GuiScrollBar.__index = GuiScrollBar GuiScrollBar.__index = GuiScrollBar
function GuiScrollBar:new( bounds, value, minValue, maxValue, callback, styles ) function GuiScrollBar:new( bounds, value, minValue, maxValue, callback, styles, tooltip )
local object = setmetatable( {}, self ) local object = setmetatable( {}, self )
object._parent = nil object._parent = nil
@@ -1650,6 +1681,7 @@ function GuiScrollBar:new( bounds, value, minValue, maxValue, callback, styles )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
object.tooltip = tooltip
return object return object
end end
@@ -1704,6 +1736,13 @@ function Raygui:new()
object.defaultFont = RL.GetFontDefault() object.defaultFont = RL.GetFontDefault()
object.mouseOffset = Vec2:new() object.mouseOffset = Vec2:new()
object.view = Rect:new() -- Active if larger than 0. Then only controls in view will be updated and drawn. object.view = Rect:new() -- Active if larger than 0. Then only controls in view will be updated and drawn.
object.tooltip = {
text = nil,
offset = Vec2:new( 12, 24 ),
delay = 0.5,
timer = 0.0,
focused = 0
}
object._lastProperties = {} object._lastProperties = {}
object._mousePressPos = Vec2:new( -1, -1 ) -- Use to check if release and check are inside bounds. object._mousePressPos = Vec2:new( -1, -1 ) -- Use to check if release and check are inside bounds.
@@ -1733,6 +1772,7 @@ function Raygui:update()
end end
-- Focused is 0 if not over any control. -- Focused is 0 if not over any control.
self.focused = 0 self.focused = 0
self.tooltip.text = nil
for i = #self.controls, 1, -1 do for i = #self.controls, 1, -1 do
local control = self.controls[i] local control = self.controls[i]
@@ -1740,10 +1780,33 @@ function Raygui:update()
if control.visible and control.update ~= nil and self:inView( control ) then if control.visible and control.update ~= nil and self:inView( control ) then
if control:update() then if control:update() then
self.focused = i self.focused = i
return
if i ~= self.tooltip.focused then
self.tooltip.focused = -1 -- Note that we don't want it to be 0, same as self.focus.
self.tooltip.timer = 0.0
end
if control.tooltip ~= nil then
self.tooltip.focused = i
if self.tooltip.timer < self.tooltip.delay then
self.tooltip.timer = self.tooltip.timer + RL.GetFrameTime()
else
self.tooltip.text = control.tooltip
self.tooltip.position = Vec2:new( RL.GetMousePosition() ) + self.tooltip.offset
end
end
break
end end
end end
end end
if self.focused == 0 then
self.tooltip.focused = -1 -- Note that we don't want it to be 0, same as self.focus.
self.tooltip.timer = 0.0
end
RL.SetMouseOffset( { 0, 0 } ) RL.SetMouseOffset( { 0, 0 } )
end end
@@ -1788,6 +1851,25 @@ function Raygui:_addLastProperty( property )
table.insert( self._lastProperties, lastProperty ) table.insert( self._lastProperties, lastProperty )
end end
function Raygui:drawTooltip()
local textSize = Vec2:new( RL.MeasureText(
self.defaultFont,
self.tooltip.text,
RL.GuiGetStyle( RL.DEFAULT, RL.TEXT_SIZE ),
RL.GuiGetStyle( RL.DEFAULT, RL.TEXT_SPACING )
) )
local tooltipRect = Rect:new( self.tooltip.position.x, self.tooltip.position.y, textSize.x, textSize.y )
local view = self.view:clone()
-- If no view size, clamp to window size.
if view.width == 0 or view.height == 0 then
local screenSize = Vec2:new( RL.GetScreenSize() )
view.width = screenSize.x
view.height = screenSize.y
end
RL.GuiDummyRec( tooltipRect:clampInside( view ), self.tooltip.text )
end
function Raygui:draw() function Raygui:draw()
if self.locked then if self.locked then
RL.GuiLock() RL.GuiLock()
@@ -1802,7 +1884,7 @@ function Raygui:draw()
self.scrolling = false self.scrolling = false
end end
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 )
for i, control in ipairs( self.controls ) do for i, control in ipairs( self.controls ) do
@@ -1820,6 +1902,12 @@ function Raygui:draw()
self:drawControl( control ) self:drawControl( control )
end end
end end
if self.tooltip.text ~= nil and self.controls[ self.tooltip.focused ]:update()
and self.tooltip.delay <= self.tooltip.timer then
self:drawTooltip()
end
RL.GuiUnlock() RL.GuiUnlock()
RL.GuiEnable() RL.GuiEnable()
RL.SetMouseOffset( { 0, 0 } ) RL.SetMouseOffset( { 0, 0 } )
@@ -1942,24 +2030,24 @@ end
---@param dragCallback function|nil ---@param dragCallback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table WindowBox ---@return table WindowBox
function Raygui:WindowBox( bounds, text, callback, grabCallback, dragCallback, styles ) function Raygui:WindowBox( bounds, text, callback, grabCallback, dragCallback, styles, tooltip )
return self:addControl( WindowBox:new( bounds, text, callback, grabCallback, dragCallback, styles ) ) return self:addControl( WindowBox:new( bounds, text, callback, grabCallback, dragCallback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
---@param text string ---@param text string
---@param styles table|nil ---@param styles table|nil
---@return table GroupBox ---@return table GroupBox
function Raygui:GroupBox( bounds, text, styles ) function Raygui:GroupBox( bounds, text, styles, tooltip )
return self:addControl( GroupBox:new( bounds, text, styles ) ) return self:addControl( GroupBox:new( bounds, text, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
---@param text string ---@param text string
---@param styles table|nil ---@param styles table|nil
---@return table Line ---@return table Line
function Raygui:Line( bounds, text, styles ) function Raygui:Line( bounds, text, styles, tooltip )
return self:addControl( Line:new( bounds, text, styles ) ) return self:addControl( Line:new( bounds, text, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -1968,8 +2056,8 @@ end
---@param dragCallback function|nil ---@param dragCallback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table Panel ---@return table Panel
function Raygui:Panel( bounds, text, grabCallback, dragCallback, styles ) function Raygui:Panel( bounds, text, grabCallback, dragCallback, styles, tooltip )
return self:addControl( Panel:new( bounds, text, grabCallback, dragCallback, styles ) ) return self:addControl( Panel:new( bounds, text, grabCallback, dragCallback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -1979,8 +2067,8 @@ end
---@param closeCallback function|nil ---@param closeCallback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table GuiTabBar ---@return table GuiTabBar
function Raygui:GuiTabBar( bounds, text, active, callback, closeCallback, styles ) function Raygui:GuiTabBar( bounds, text, active, callback, closeCallback, styles, tooltip )
return self:addControl( GuiTabBar:new( bounds, text, active, callback, closeCallback, styles ) ) return self:addControl( GuiTabBar:new( bounds, text, active, callback, closeCallback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -1992,16 +2080,16 @@ end
---@param dragCallback function|nil ---@param dragCallback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ScrollPanel ---@return table ScrollPanel
function Raygui:ScrollPanel( bounds, text, content, scroll, callback, grabCallback, dragCallback, styles ) function Raygui:ScrollPanel( bounds, text, content, scroll, callback, grabCallback, dragCallback, styles, tooltip )
return self:addControl( ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback, dragCallback, styles ) ) return self:addControl( ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback, dragCallback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
---@param text string ---@param text string
---@param styles table|nil ---@param styles table|nil
---@return table Label ---@return table Label
function Raygui:Label( bounds, text, styles ) function Raygui:Label( bounds, text, styles, tooltip )
return self:addControl( Label:new( bounds, text, styles ) ) return self:addControl( Label:new( bounds, text, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2009,8 +2097,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table Button ---@return table Button
function Raygui:Button( bounds, text, callback, styles ) function Raygui:Button( bounds, text, callback, styles, tooltip )
return self:addControl( Button:new( bounds, text, callback, styles ) ) return self:addControl( Button:new( bounds, text, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2018,8 +2106,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table LabelButton ---@return table LabelButton
function Raygui:LabelButton( bounds, text, callback, styles ) function Raygui:LabelButton( bounds, text, callback, styles, tooltip )
return self:addControl( LabelButton:new( bounds, text, callback, styles ) ) return self:addControl( LabelButton:new( bounds, text, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2028,8 +2116,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table Toggle ---@return table Toggle
function Raygui:Toggle( bounds, text, active, callback, styles ) function Raygui:Toggle( bounds, text, active, callback, styles, tooltip )
return self:addControl( Toggle:new( bounds, text, active, callback, styles ) ) return self:addControl( Toggle:new( bounds, text, active, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2038,8 +2126,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ToggleGroup ---@return table ToggleGroup
function Raygui:ToggleGroup( bounds, text, active, callback, styles ) function Raygui:ToggleGroup( bounds, text, active, callback, styles, tooltip )
return self:addControl( ToggleGroup:new( bounds, text, active, callback, styles ) ) return self:addControl( ToggleGroup:new( bounds, text, active, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2048,8 +2136,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table CheckBox ---@return table CheckBox
function Raygui:CheckBox( bounds, text, checked, callback, styles ) function Raygui:CheckBox( bounds, text, checked, callback, styles, tooltip )
return self:addControl( CheckBox:new( bounds, text, checked, callback, styles ) ) return self:addControl( CheckBox:new( bounds, text, checked, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2058,8 +2146,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ComboBox ---@return table ComboBox
function Raygui:ComboBox( bounds, text, active, callback, styles ) function Raygui:ComboBox( bounds, text, active, callback, styles, tooltip )
return self:addControl( ComboBox:new( bounds, text, active, callback, styles ) ) return self:addControl( ComboBox:new( bounds, text, active, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2069,8 +2157,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table DropdownBox ---@return table DropdownBox
function Raygui:DropdownBox( bounds, text, active, editMode, callback, styles ) function Raygui:DropdownBox( bounds, text, active, editMode, callback, styles, tooltip )
return self:addControl( DropdownBox:new( bounds, text, active, editMode, callback, styles ) ) return self:addControl( DropdownBox:new( bounds, text, active, editMode, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2082,8 +2170,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table Spinner ---@return table Spinner
function Raygui:Spinner( bounds, text, value, minValue, maxValue, editMode, callback, styles ) function Raygui:Spinner( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip )
return self:addControl( Spinner:new( bounds, text, value, minValue, maxValue, editMode, callback, styles ) ) return self:addControl( Spinner:new( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2095,8 +2183,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ValueBox ---@return table ValueBox
function Raygui:ValueBox( bounds, text, value, minValue, maxValue, editMode, callback, styles ) function Raygui:ValueBox( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip )
return self:addControl( ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callback, styles ) ) return self:addControl( ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2106,8 +2194,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table TextBox ---@return table TextBox
function Raygui:TextBox( bounds, text, textSize, editMode, callback, styles ) function Raygui:TextBox( bounds, text, textSize, editMode, callback, styles, tooltip )
return self:addControl( TextBox:new( bounds, text, textSize, editMode, callback, styles ) ) return self:addControl( TextBox:new( bounds, text, textSize, editMode, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2119,8 +2207,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table Slider ---@return table Slider
function Raygui:Slider( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) function Raygui:Slider( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
return self:addControl( Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) ) return self:addControl( Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2132,8 +2220,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table SliderBar ---@return table SliderBar
function Raygui:SliderBar( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) function Raygui:SliderBar( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
return self:addControl( SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) ) return self:addControl( SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2145,24 +2233,24 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ProgressBar ---@return table ProgressBar
function Raygui:ProgressBar( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) function Raygui:ProgressBar( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip )
return self:addControl( ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles ) ) return self:addControl( ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
---@param text string ---@param text string
---@param styles table|nil ---@param styles table|nil
---@return table StatusBar ---@return table StatusBar
function Raygui:StatusBar( bounds, text, styles ) function Raygui:StatusBar( bounds, text, styles, tooltip )
return self:addControl( StatusBar:new( bounds, text, styles ) ) return self:addControl( StatusBar:new( bounds, text, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
---@param text string ---@param text string
---@param styles table|nil ---@param styles table|nil
---@return table DummyRec ---@return table DummyRec
function Raygui:DummyRec( bounds, text, styles ) function Raygui:DummyRec( bounds, text, styles, tooltip )
return self:addControl( DummyRec:new( bounds, text, styles ) ) return self:addControl( DummyRec:new( bounds, text, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2172,8 +2260,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table Grid ---@return table Grid
function Raygui:Grid( bounds, text, spacing, subdivs, callback, styles ) function Raygui:Grid( bounds, text, spacing, subdivs, callback, styles, tooltip )
return self:addControl( Grid:new( bounds, text, spacing, subdivs, callback, styles ) ) return self:addControl( Grid:new( bounds, text, spacing, subdivs, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2183,8 +2271,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ListView ---@return table ListView
function Raygui:ListView( bounds, text, scrollIndex, active, callback, styles ) function Raygui:ListView( bounds, text, scrollIndex, active, callback, styles, tooltip )
return self:addControl( ListView:new( bounds, text, scrollIndex, active, callback, styles ) ) return self:addControl( ListView:new( bounds, text, scrollIndex, active, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2195,8 +2283,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ListViewEx ---@return table ListViewEx
function Raygui:ListViewEx( bounds, text, scrollIndex, active, focus, callback, styles ) function Raygui:ListViewEx( bounds, text, scrollIndex, active, focus, callback, styles, tooltip )
return self:addControl( ListViewEx:new( bounds, text, scrollIndex, active, focus, callback, styles ) ) return self:addControl( ListViewEx:new( bounds, text, scrollIndex, active, focus, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2208,8 +2296,8 @@ end
---@param dragCallback function|nil ---@param dragCallback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table MessageBox ---@return table MessageBox
function Raygui:MessageBox( bounds, title, message, buttons, callback, grabCallback, dragCallback, styles ) function Raygui:MessageBox( bounds, title, message, buttons, callback, grabCallback, dragCallback, styles, tooltip )
return self:addControl( MessageBox:new( bounds, title, message, buttons, callback, grabCallback, dragCallback, styles ) ) return self:addControl( MessageBox:new( bounds, title, message, buttons, callback, grabCallback, dragCallback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2224,8 +2312,8 @@ end
---@param dragCallback function|nil ---@param dragCallback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table TextInputBox ---@return table TextInputBox
function Raygui:TextInputBox( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback, grabCallback, dragCallback, styles ) function Raygui:TextInputBox( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback, grabCallback, dragCallback, styles, tooltip )
return self:addControl( TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback, grabCallback, dragCallback, styles ) ) return self:addControl( TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback, grabCallback, dragCallback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2234,8 +2322,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ColorPicker ---@return table ColorPicker
function Raygui:ColorPicker( bounds, text, color, callback, styles ) function Raygui:ColorPicker( bounds, text, color, callback, styles, tooltip )
return self:addControl( ColorPicker:new( bounds, text, color, callback, styles ) ) return self:addControl( ColorPicker:new( bounds, text, color, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2244,8 +2332,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ColorPanel ---@return table ColorPanel
function Raygui:ColorPanel( bounds, text, color, callback, styles ) function Raygui:ColorPanel( bounds, text, color, callback, styles, tooltip )
return self:addControl( ColorPanel:new( bounds, text, color, callback, styles ) ) return self:addControl( ColorPanel:new( bounds, text, color, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2254,8 +2342,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ColorBarAlpha ---@return table ColorBarAlpha
function Raygui:ColorBarAlpha( bounds, text, alpha, callback, styles ) function Raygui:ColorBarAlpha( bounds, text, alpha, callback, styles, tooltip )
return self:addControl( ColorBarAlpha:new( bounds, text, alpha, callback, styles ) ) return self:addControl( ColorBarAlpha:new( bounds, text, alpha, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2264,8 +2352,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ColorBarHue ---@return table ColorBarHue
function Raygui:ColorBarHue( bounds, text, value, callback, styles ) function Raygui:ColorBarHue( bounds, text, value, callback, styles, tooltip )
return self:addControl( ColorBarHue:new( bounds, text, value, callback, styles ) ) return self:addControl( ColorBarHue:new( bounds, text, value, callback, styles, tooltip ) )
end end
---@param bounds Rectangle ---@param bounds Rectangle
@@ -2275,8 +2363,8 @@ end
---@param callback function|nil ---@param callback function|nil
---@param styles table|nil ---@param styles table|nil
---@return table ColorBarHue ---@return table ColorBarHue
function Raygui:GuiScrollBar( bounds, value, minValue, maxValue, callback, styles ) function Raygui:GuiScrollBar( bounds, value, minValue, maxValue, callback, styles, tooltip )
return self:addControl( GuiScrollBar:new( bounds, value, minValue, maxValue, callback, styles ) ) return self:addControl( GuiScrollBar:new( bounds, value, minValue, maxValue, callback, styles, tooltip ) )
end end
return Raygui return Raygui

View File

@@ -109,7 +109,7 @@ function Rectangle:area()
return self.width * self.height return self.width * self.height
end end
--- Returns rectangle that fits both rectangles inside it -- Returns rectangle that fits both rectangles inside it
function Rectangle:fit( rec ) function Rectangle:fit( rec )
local pos = Vector2:new( math.min( self.x, rec.x ), math.min( self.y, rec.y ) ) local pos = Vector2:new( math.min( self.x, rec.x ), math.min( self.y, rec.y ) )
@@ -121,10 +121,20 @@ function Rectangle:fit( rec )
) )
end end
--- If rectangle is fully inside another rectangle -- If rectangle is fully inside another rectangle
function Rectangle:isInside( rect ) function Rectangle:isInside( rec )
return rect.x <= self.x and self.x + self.width <= rect.x + rect.width return rec.x <= self.x and self.x + self.width <= rec.x + rec.width
and rect.y <= self.y and self.y + self.height <= rect.y + rect.height and rec.y <= self.y and self.y + self.height <= rec.y + rec.height
end
-- Returns clamped rectangle that is inside another rectangle.
function Rectangle:clampInside( rec )
return Rectangle:new(
math.max( rec.x, math.min( self.x, rec.x + rec.width - self.width ) ),
math.max( rec.y, math.min( self.y, rec.y + rec.height - self.height ) ),
self.width,
self.height
)
end end
function Rectangle:checkCollisionRec( rec ) function Rectangle:checkCollisionRec( rec )

View File

@@ -2,7 +2,7 @@
#include "lua_core.h" #include "lua_core.h"
void unloadBuffer( Buffer *buffer ); void unloadBuffer( Buffer* buffer );
/* Window-related functions. */ /* Window-related functions. */
int lcoreCloseWindow( lua_State* L ); int lcoreCloseWindow( lua_State* L );
int lcoreIsWindowReady( lua_State* L ); int lcoreIsWindowReady( lua_State* L );

View File

@@ -42,7 +42,7 @@ typedef struct {
#endif #endif
} State; } State;
extern State *state; extern State* state;
bool stateInit( int argn, const char** argc, const char* exePath ); bool stateInit( int argn, const char** argc, const char* exePath );
void stateInitInterpret( int argn, const char** argc ); void stateInitInterpret( int argn, const char** argc );

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
void unloadGlyphInfo( GlyphInfo *glyph ); void unloadGlyphInfo( GlyphInfo* glyph );
/* Font loading/unloading functions. */ /* Font loading/unloading functions. */
int ltextGetFontDefault( lua_State* L ); int ltextGetFontDefault( lua_State* L );
int ltextLoadFont( lua_State* L ); int ltextLoadFont( lua_State* L );

View File

@@ -4,7 +4,7 @@
#include "textures.h" #include "textures.h"
#include "models.h" #include "models.h"
State *state; State* state;
bool stateInit( int argn, const char** argc, const char* exePath ) { bool stateInit( int argn, const char** argc, const char* exePath ) {
state = malloc( sizeof( State ) ); state = malloc( sizeof( State ) );