summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--changelog1
-rw-r--r--devnotes3
-rw-r--r--examples/raygui_extensions/main.lua29
-rw-r--r--examples/raygui_extensions/property_list.lua4
-rw-r--r--examples/raygui_lib/main.lua44
-rw-r--r--examples/resources/lib/raygui.lua92
-rw-r--r--src/main.c2
8 files changed, 97 insertions, 82 deletions
diff --git a/README.md b/README.md
index 61489c0..cc796da 100644
--- a/README.md
+++ b/README.md
@@ -74,6 +74,10 @@ Application should now start successfully from executable. All functionality can
ReiLua_API.lua can be put into project folder to provide annotations when using "Lua Language Server".
+## Object unloading
+
+Some objects allocate memory that needs to be freed when object is no longer needed. By default objects like Textures are unloaded by the Lua garbage collector. It is generatty however recommended to handle this manually in more complex projects. You can change the behavior with SetGCUnload.
+
## Interpreter Mode
ReiLua can also be used to run single lua file using interpreter mode with arguments -i or --interpret. Given file will be called with dofile. Usage example:
diff --git a/changelog b/changelog
index bc5d451..bb7ef67 100644
--- a/changelog
+++ b/changelog
@@ -35,6 +35,7 @@ KEY CHANGES:
- ADDED: Raygui lib extensions property list.
- ADDED: Text codepoints management functions.
- ADDED: Rune, UTF8 lib.
+ - CHANGE: Raygui styles include properties, texture and font.
DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
diff --git a/devnotes b/devnotes
index dd33255..c5fbe71 100644
--- a/devnotes
+++ b/devnotes
@@ -3,9 +3,8 @@ Current {
Backlog {
* Raygui lib
- * Fonts for controls. Remember that it needs to affect init measurements.
* Check if could remove flickering from changing draw order by making queue for order changing and only
- change them after everything is drawn.
+ change them after everything is drawn.
* Platform desktop SDL
* Text input not working on gui. Could this be Raylib issue?
* Haptic functions.
diff --git a/examples/raygui_extensions/main.lua b/examples/raygui_extensions/main.lua
index e52c96d..8ce1913 100644
--- a/examples/raygui_extensions/main.lua
+++ b/examples/raygui_extensions/main.lua
@@ -35,11 +35,13 @@ local function addButton( bounds, text, callback )
{ source = { 48, 0, 48, 48 }, left = 16, top = 16, right = 16, bottom = 16, layout = RL.NPATCH_NINE_PATCH },
callback,
{
- { RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
- { RL.DEFAULT, RL.TEXT_SIZE, 32 },
- { RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) },
- { RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) },
- { RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) },
+ properties = {
+ { RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
+ { RL.DEFAULT, RL.TEXT_SIZE, 32 },
+ { RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) },
+ { RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) },
+ { RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) },
+ },
}
)
end
@@ -75,7 +77,9 @@ local function addPropertyList()
function( self ) Gui:set2Top( self ) end,
nil,
{
- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
+ properties = {
+ { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
+ }
}
)
RL.GuiSetStyle( RL.SPINNER, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT )
@@ -148,9 +152,6 @@ local function addPropertyList()
"Flipped",
cat.flipped,
function( self ) cat.flipped = self.checked end
- -- {
- -- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT }
- -- }
), transformGroup )
-- Visibility.
@@ -163,7 +164,9 @@ local function addPropertyList()
cat.visible,
function( self ) cat.visible = self.checked end,
{
- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT }
+ properties = {
+ { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT },
+ }
}
), visibilityGroup )
@@ -199,8 +202,10 @@ local function addPropertyList()
false,
function( self ) print( "Checked" ) end,
{
- -- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT },
- { RL.DEFAULT, RL.TEXT_SIZE, 32 }
+ properties = {
+ -- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT },
+ { RL.DEFAULT, RL.TEXT_SIZE, 32 }
+ }
}
), test )
end
diff --git a/examples/raygui_extensions/property_list.lua b/examples/raygui_extensions/property_list.lua
index 04c2b78..35f2f36 100644
--- a/examples/raygui_extensions/property_list.lua
+++ b/examples/raygui_extensions/property_list.lua
@@ -141,7 +141,9 @@ function PropertyList:addGroup( name, active, group )
active,
function( this ) this.text = setGroupText( name, this.active ) self:updateContent() end,
{
- { RL.TOGGLE, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT }
+ properties = {
+ { RL.TOGGLE, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT }
+ }
}
)
control._controls = {} -- Prefix _ to try to prevent clashing with control definition.
diff --git a/examples/raygui_lib/main.lua b/examples/raygui_lib/main.lua
index 0bb01fb..fcc6ea0 100644
--- a/examples/raygui_lib/main.lua
+++ b/examples/raygui_lib/main.lua
@@ -70,13 +70,14 @@ function RL.init()
"Dog",
function() toggleGroup:setText( "Dog;Cat\nEagle" ) end,
{
- { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
- { RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) },
- { RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) },
+ properties = {
+ { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
+ { RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) },
+ { RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) },
+ },
+ texture = { texture = texture, rect = textureRect },
}
)
- button.texture = texture
- button.textureRect = textureRect
local checkbox = Gui:CheckBox(
Rect:new( 116, 128, 20, 20 ),
"Visible",
@@ -140,10 +141,11 @@ function RL.init()
0,
0,
100,
- function( self ) print( "Changed value "..self.value ) end
+ function( self ) print( "Changed value "..self.value ) end,
+ {
+ texture = { texture = texture, rect = textureRect },
+ }
)
- slider.texture = texture
- slider.textureRect = textureRect
local sliderbar = Gui:SliderBar(
Rect:new( 50, 550, 256, 32 ),
"min",
@@ -185,11 +187,12 @@ function RL.init()
function( self ) Gui:set2Top( self ) end,
nil,
{
- { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
+ properties = {
+ { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
+ },
+ texture = { texture = texture, rect = textureRect },
}
)
- windowbox.texture = texture
- windowbox.textureRect = textureRect
local groupbox = Gui:GroupBox(
Rect:new( 400, 700, 256, 256 ),
@@ -206,9 +209,11 @@ function RL.init()
function( self ) Gui:set2Top( self ) end,
nil,
{
- { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.MAGENTA ) },
- { RL.DEFAULT, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
- { RL.DEFAULT, RL.BACKGROUND_COLOR, RL.ColorToInt( RL.DARKBLUE ) },
+ properties = {
+ { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.MAGENTA ) },
+ { RL.DEFAULT, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
+ { RL.DEFAULT, RL.BACKGROUND_COLOR, RL.ColorToInt( RL.DARKBLUE ) },
+ }
}
)
tabBar = Gui:GuiTabBar(
@@ -243,13 +248,14 @@ function RL.init()
0,
function( self ) print( self:getItem( self.active ) ) end,
{
- { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
- { RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) },
- { RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) },
+ properties = {
+ { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
+ { RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) },
+ { RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) },
+ },
+ texture = { texture = texture, rect = textureRect },
}
)
- listviewex.texture = texture
- listviewex.textureRect = textureRect
local messagebox = Gui:MessageBox(
Rect:new( 1100, 150, 300, 128 ),
"Title",
diff --git a/examples/resources/lib/raygui.lua b/examples/resources/lib/raygui.lua
index 36c7cff..d95d0f8 100644
--- a/examples/resources/lib/raygui.lua
+++ b/examples/resources/lib/raygui.lua
@@ -1701,10 +1701,11 @@ function Raygui:new()
object.textEdit = false
object.defaultTexture = RL.GetTextureDefault()
object.defaultRect = Rect:new( 0, 0, 1, 1 ) -- For texture.
+ object.defaultFont = RL.GetFontDefault()
object.mouseOffset = Vec2:new()
object.view = Rect:new() -- Active if larger than 0. Then only controls in view will be processed and drawn.
- object._lastStyles = {}
+ object._lastProperties = {}
object._mousePressPos = Vec2:new( -1, -1 ) -- Use to check if release and check are inside bounds.
return object
@@ -1774,17 +1775,17 @@ function Raygui:drag( control )
return mouseOver
end
--- Add style before current draw that we can then return them.
-function Raygui:_addLastStyle( style )
- local lastStyle = { style[1], style[2], RL.GuiGetStyle( style[1], style[2] ) }
+-- Add property before current draw that we can then return them.
+function Raygui:_addLastProperty( property )
+ local lastProperty = { property[1], property[2], RL.GuiGetStyle( property[1], property[2] ) }
- for i, slot in ipairs( self._lastStyles ) do
+ for i, slot in ipairs( self._lastProperties ) do
if slot == 0 then
- self._lastStyles[i] = lastStyle
+ self._lastProperties[i] = lastProperty
return
end
end
- table.insert( self._lastStyles, lastStyle )
+ table.insert( self._lastProperties, lastProperty )
end
function Raygui:draw()
@@ -1804,43 +1805,21 @@ function Raygui:draw()
-- Set mouse ofset if gui is for example embedded to some control.
RL.SetMouseOffset( self.mouseOffset )
- for i, control in ipairs( self.controls ) do
- if not self.locked and not self.disabled and i == self.focused then
- RL.GuiUnlock()
- end
+ for i, control in ipairs( self.controls ) do
+ if not self.locked and not self.disabled and i == self.focused then
+ RL.GuiUnlock()
+ end
- if control.visible and control.draw ~= nil and self:inView( control ) then
+ if control.visible and control.draw ~= nil and self:inView( control ) then
if control.disabled then
RL.GuiDisable()
else
RL.GuiEnable()
end
- if control.styles ~= nil then
- for _, style in ipairs( control.styles ) do
- self:_addLastStyle( style )
- RL.GuiSetStyle( style[1], style[2], style[3] )
- end
- end
- if control.texture ~= nil then
- RL.SetShapesTexture( control.texture, control.textureRect )
- end
-
- control:draw()
- if control.texture ~= nil then
- RL.SetShapesTexture( self.defaultTexture, self.defaultRect )
- end
- -- Set previous styles back.
- if 0 < #self._lastStyles then
- for j, style in ipairs( self._lastStyles ) do
- if type( style ) == "table" then
- RL.GuiSetStyle( style[1], style[2], style[3] )
- end
- self._lastStyles[j] = 0
- end
- end
- end
- end
+ self:drawControl( control )
+ end
+ end
RL.GuiUnlock()
RL.GuiEnable()
RL.SetMouseOffset( { 0, 0 } )
@@ -1902,24 +1881,42 @@ function Raygui:editMode( editMode )
self.textEdit = not editMode
end
--- Mainly to set focusBounds and viewBounds by drawing control.
-function Raygui:applyStyles( control )
+function Raygui:drawControl( control )
if control == nil or control.draw == nil then
return
end
- local oldStyles = {}
if control.styles ~= nil then
- for _, style in ipairs( control.styles ) do
- local oldStyle = { style[1], style[2], RL.GuiGetStyle( style[1], style[2] ) }
- table.insert( oldStyles, oldStyle )
- RL.GuiSetStyle( style[1], style[2], style[3] )
+ for name, style in pairs( control.styles ) do
+ if name == "properties" then
+ for _, property in ipairs( style ) do
+ self:_addLastProperty( property )
+ RL.GuiSetStyle( property[1], property[2], property[3] )
+ end
+ elseif name == "texture" then
+ RL.SetShapesTexture( style.texture, style.rect )
+ elseif name == "font" then
+ RL.GuiSetFont( style )
+ end
end
end
+
control:draw()
+
if control.styles ~= nil then
- for _, style in ipairs( oldStyles ) do
- RL.GuiSetStyle( style[1], style[2], style[3] )
+ for name, _ in pairs( control.styles ) do
+ if name == "properties" then
+ for j, property in ipairs( self._lastProperties ) do
+ if type( property ) == "table" then
+ RL.GuiSetStyle( property[1], property[2], property[3] )
+ self._lastProperties[j] = 0
+ end
+ end
+ elseif name == "texture" then
+ RL.SetShapesTexture( self.defaultTexture, self.defaultRect )
+ elseif name == "font" then
+ RL.GuiSetFont( self.defaultFont )
+ end
end
end
end
@@ -1928,7 +1925,8 @@ end
function Raygui:addControl( control )
control._parent = self
- self:applyStyles( control )
+ -- self:applyStyles( control )
+ self:drawControl( control )
table.insert( self.controls, control )
return control
end
diff --git a/src/main.c b/src/main.c
index b5be6d9..75bd693 100644
--- a/src/main.c
+++ b/src/main.c
@@ -77,5 +77,5 @@ int main( int argn, const char **argc ) {
}
stateFree();
- return 1;
+ return 0;
}