Raygui styles include properties, texture and font.

This commit is contained in:
jussi
2024-02-05 22:40:31 +02:00
parent d21512d88c
commit eda4eacfce
8 changed files with 97 additions and 82 deletions

View File

@@ -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". 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 ## 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: 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:

View File

@@ -35,6 +35,7 @@ KEY CHANGES:
- ADDED: Raygui lib extensions property list. - ADDED: Raygui lib extensions property list.
- ADDED: Text codepoints management functions. - ADDED: Text codepoints management functions.
- ADDED: Rune, UTF8 lib. - ADDED: Rune, UTF8 lib.
- CHANGE: Raygui styles include properties, texture and font.
DETAILED CHANGES: DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic. - REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.

View File

@@ -3,9 +3,8 @@ Current {
Backlog { Backlog {
* Raygui lib * 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 * 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 * Platform desktop SDL
* Text input not working on gui. Could this be Raylib issue? * Text input not working on gui. Could this be Raylib issue?
* Haptic functions. * Haptic functions.

View File

@@ -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 }, { source = { 48, 0, 48, 48 }, left = 16, top = 16, right = 16, bottom = 16, layout = RL.NPATCH_NINE_PATCH },
callback, callback,
{ {
{ RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER }, properties = {
{ RL.DEFAULT, RL.TEXT_SIZE, 32 }, { RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
{ RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) }, { RL.DEFAULT, RL.TEXT_SIZE, 32 },
{ RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) }, { RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) },
{ RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) }, { 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 end
@@ -75,7 +77,9 @@ local function addPropertyList()
function( self ) Gui:set2Top( self ) end, function( self ) Gui:set2Top( self ) end,
nil, 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 ) RL.GuiSetStyle( RL.SPINNER, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT )
@@ -148,9 +152,6 @@ local function addPropertyList()
"Flipped", "Flipped",
cat.flipped, cat.flipped,
function( self ) cat.flipped = self.checked end function( self ) cat.flipped = self.checked end
-- {
-- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT }
-- }
), transformGroup ) ), transformGroup )
-- Visibility. -- Visibility.
@@ -163,7 +164,9 @@ local function addPropertyList()
cat.visible, cat.visible,
function( self ) cat.visible = self.checked end, 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 ) ), visibilityGroup )
@@ -199,8 +202,10 @@ local function addPropertyList()
false, false,
function( self ) print( "Checked" ) end, function( self ) print( "Checked" ) end,
{ {
-- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT }, properties = {
{ RL.DEFAULT, RL.TEXT_SIZE, 32 } -- { RL.CHECKBOX, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT },
{ RL.DEFAULT, RL.TEXT_SIZE, 32 }
}
} }
), test ) ), test )
end end

View File

@@ -141,7 +141,9 @@ function PropertyList:addGroup( name, active, group )
active, active,
function( this ) this.text = setGroupText( name, this.active ) self:updateContent() end, 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. control._controls = {} -- Prefix _ to try to prevent clashing with control definition.

View File

@@ -70,13 +70,14 @@ function RL.init()
"Dog", "Dog",
function() toggleGroup:setText( "Dog;Cat\nEagle" ) end, function() toggleGroup:setText( "Dog;Cat\nEagle" ) end,
{ {
{ RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) }, properties = {
{ RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) }, { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
{ RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) }, { 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( local checkbox = Gui:CheckBox(
Rect:new( 116, 128, 20, 20 ), Rect:new( 116, 128, 20, 20 ),
"Visible", "Visible",
@@ -140,10 +141,11 @@ function RL.init()
0, 0,
0, 0,
100, 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( local sliderbar = Gui:SliderBar(
Rect:new( 50, 550, 256, 32 ), Rect:new( 50, 550, 256, 32 ),
"min", "min",
@@ -185,11 +187,12 @@ function RL.init()
function( self ) Gui:set2Top( self ) end, function( self ) Gui:set2Top( self ) end,
nil, 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( local groupbox = Gui:GroupBox(
Rect:new( 400, 700, 256, 256 ), Rect:new( 400, 700, 256, 256 ),
@@ -206,9 +209,11 @@ function RL.init()
function( self ) Gui:set2Top( self ) end, function( self ) Gui:set2Top( self ) end,
nil, nil,
{ {
{ RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.MAGENTA ) }, properties = {
{ RL.DEFAULT, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER }, { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.MAGENTA ) },
{ RL.DEFAULT, RL.BACKGROUND_COLOR, RL.ColorToInt( RL.DARKBLUE ) }, { RL.DEFAULT, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
{ RL.DEFAULT, RL.BACKGROUND_COLOR, RL.ColorToInt( RL.DARKBLUE ) },
}
} }
) )
tabBar = Gui:GuiTabBar( tabBar = Gui:GuiTabBar(
@@ -243,13 +248,14 @@ function RL.init()
0, 0,
function( self ) print( self:getItem( self.active ) ) end, function( self ) print( self:getItem( self.active ) ) end,
{ {
{ RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) }, properties = {
{ RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) }, { RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
{ RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) }, { 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( local messagebox = Gui:MessageBox(
Rect:new( 1100, 150, 300, 128 ), Rect:new( 1100, 150, 300, 128 ),
"Title", "Title",

View File

@@ -1701,10 +1701,11 @@ function Raygui:new()
object.textEdit = false object.textEdit = false
object.defaultTexture = RL.GetTextureDefault() object.defaultTexture = RL.GetTextureDefault()
object.defaultRect = Rect:new( 0, 0, 1, 1 ) -- For texture. object.defaultRect = Rect:new( 0, 0, 1, 1 ) -- For texture.
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 processed and drawn. 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. object._mousePressPos = Vec2:new( -1, -1 ) -- Use to check if release and check are inside bounds.
return object return object
@@ -1774,17 +1775,17 @@ function Raygui:drag( control )
return mouseOver return mouseOver
end end
-- Add style before current draw that we can then return them. -- Add property before current draw that we can then return them.
function Raygui:_addLastStyle( style ) function Raygui:_addLastProperty( property )
local lastStyle = { style[1], style[2], RL.GuiGetStyle( style[1], style[2] ) } 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 if slot == 0 then
self._lastStyles[i] = lastStyle self._lastProperties[i] = lastProperty
return return
end end
end end
table.insert( self._lastStyles, lastStyle ) table.insert( self._lastProperties, lastProperty )
end end
function Raygui:draw() function Raygui:draw()
@@ -1804,43 +1805,21 @@ function Raygui:draw()
-- Set mouse ofset if gui is for example embedded to some control. -- Set mouse ofset 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
if not self.locked and not self.disabled and i == self.focused then if not self.locked and not self.disabled and i == self.focused then
RL.GuiUnlock() RL.GuiUnlock()
end 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 if control.disabled then
RL.GuiDisable() RL.GuiDisable()
else else
RL.GuiEnable() RL.GuiEnable()
end 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() self:drawControl( control )
end
if control.texture ~= nil then end
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
RL.GuiUnlock() RL.GuiUnlock()
RL.GuiEnable() RL.GuiEnable()
RL.SetMouseOffset( { 0, 0 } ) RL.SetMouseOffset( { 0, 0 } )
@@ -1902,24 +1881,42 @@ function Raygui:editMode( editMode )
self.textEdit = not editMode self.textEdit = not editMode
end end
-- Mainly to set focusBounds and viewBounds by drawing control. function Raygui:drawControl( control )
function Raygui:applyStyles( control )
if control == nil or control.draw == nil then if control == nil or control.draw == nil then
return return
end end
local oldStyles = {}
if control.styles ~= nil then if control.styles ~= nil then
for _, style in ipairs( control.styles ) do for name, style in pairs( control.styles ) do
local oldStyle = { style[1], style[2], RL.GuiGetStyle( style[1], style[2] ) } if name == "properties" then
table.insert( oldStyles, oldStyle ) for _, property in ipairs( style ) do
RL.GuiSetStyle( style[1], style[2], style[3] ) 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
end end
control:draw() control:draw()
if control.styles ~= nil then if control.styles ~= nil then
for _, style in ipairs( oldStyles ) do for name, _ in pairs( control.styles ) do
RL.GuiSetStyle( style[1], style[2], style[3] ) 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 end
end end
@@ -1928,7 +1925,8 @@ end
function Raygui:addControl( control ) function Raygui:addControl( control )
control._parent = self control._parent = self
self:applyStyles( control ) -- self:applyStyles( control )
self:drawControl( control )
table.insert( self.controls, control ) table.insert( self.controls, control )
return control return control
end end

View File

@@ -77,5 +77,5 @@ int main( int argn, const char **argc ) {
} }
stateFree(); stateFree();
return 1; return 0;
} }