Raygui wrapper library disable and styles for each element.

This commit is contained in:
jussi
2023-12-01 00:26:43 +02:00
parent a5d40f7025
commit 4a783a156e
8 changed files with 243 additions and 390 deletions

View File

@@ -18,6 +18,7 @@ KEY CHANGES:
- ADDED: Platform web. - ADDED: Platform web.
- ADDED: Raygui textures with SetShapesTexture. - ADDED: Raygui textures with SetShapesTexture.
- CHANGE: Raygui wrapper library is now object based. Possible to have multiple separated gui systems. - CHANGE: Raygui wrapper library is now object based. Possible to have multiple separated gui systems.
- ADDED: Raygui wrapper library disabled and styles for each element.
DETAILED CHANGES: DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic. - REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.

View File

@@ -1,8 +1,10 @@
Current { Current {
* Gui library to object based.
} }
Backlog { Backlog {
* Raygui lib
* Check if could remove flickering from changing draw order by making queue for order changing and only
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

@@ -27,7 +27,7 @@ function Calculator:new( pos )
object.handle:add( Gui.texture:new( { object.handle:add( Gui.texture:new( {
bounds = object.handle.bounds:clone(), bounds = object.handle.bounds:clone(),
texture = bgrTexture, texture = BgrTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:new( RL.LIGHTGRAY ),
@@ -35,7 +35,7 @@ function Calculator:new( pos )
object.handle:add( Gui.texture:new( { object.handle:add( Gui.texture:new( {
bounds = object.handle.bounds:clone(), bounds = object.handle.bounds:clone(),
texture = borderTexture, texture = BorderTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:new( RL.LIGHTGRAY ),
@@ -57,7 +57,7 @@ function Calculator:new( pos )
object.closeButton:add( Gui.texture:new( { object.closeButton:add( Gui.texture:new( {
bounds = object.closeButton.bounds:clone(), bounds = object.closeButton.bounds:clone(),
texture = cancelTexture, texture = CancelTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
} ) ) } ) )
@@ -70,7 +70,7 @@ function Calculator:new( pos )
object.panel:add( Gui.texture:new( { object.panel:add( Gui.texture:new( {
bounds = object.panel.bounds:clone(), bounds = object.panel.bounds:clone(),
texture = bgrTexture, texture = BgrTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.GRAY ), color = Color:new( RL.GRAY ),
@@ -78,7 +78,7 @@ function Calculator:new( pos )
object.panel:add( Gui.texture:new( { object.panel:add( Gui.texture:new( {
bounds = object.panel.bounds:clone(), bounds = object.panel.bounds:clone(),
texture = borderTexture, texture = BorderTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:new( RL.LIGHTGRAY ),

View File

@@ -27,7 +27,7 @@ function FileExplorer:new( pos )
object.handle:add( Gui.texture:new( { object.handle:add( Gui.texture:new( {
bounds = object.handle.bounds:clone(), bounds = object.handle.bounds:clone(),
texture = bgrTexture, texture = BgrTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:new( RL.LIGHTGRAY ),
@@ -35,7 +35,7 @@ function FileExplorer:new( pos )
object.handle:add( Gui.texture:new( { object.handle:add( Gui.texture:new( {
bounds = object.handle.bounds:clone(), bounds = object.handle.bounds:clone(),
texture = borderTexture, texture = BorderTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:new( RL.LIGHTGRAY ),
@@ -57,7 +57,7 @@ function FileExplorer:new( pos )
object.closeButton:add( Gui.texture:new( { object.closeButton:add( Gui.texture:new( {
bounds = object.closeButton.bounds:clone(), bounds = object.closeButton.bounds:clone(),
texture = cancelTexture, texture = CancelTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
} ) ) } ) )
@@ -70,7 +70,7 @@ function FileExplorer:new( pos )
object.panel:add( Gui.texture:new( { object.panel:add( Gui.texture:new( {
bounds = object.panel.bounds:clone(), bounds = object.panel.bounds:clone(),
texture = bgrTexture, texture = BgrTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.GRAY ), color = Color:new( RL.GRAY ),
@@ -78,7 +78,7 @@ function FileExplorer:new( pos )
object.panel:add( Gui.texture:new( { object.panel:add( Gui.texture:new( {
bounds = object.panel.bounds:clone(), bounds = object.panel.bounds:clone(),
texture = borderTexture, texture = BorderTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:new( RL.LIGHTGRAY ),
@@ -110,7 +110,7 @@ function FileExplorer:new( pos )
object.backButton:add( Gui.texture:new( { object.backButton:add( Gui.texture:new( {
bounds = Rect:new( 0, 0, object.HANDLE_HIGHT, object.HANDLE_HIGHT ), bounds = Rect:new( 0, 0, object.HANDLE_HIGHT, object.HANDLE_HIGHT ),
texture = backTexture, texture = BackTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
color = Color:new( RL.BLACK ) color = Color:new( RL.BLACK )
} ) ) } ) )
@@ -153,8 +153,8 @@ function FileExplorer:new( pos )
object.path = RL.GetBasePath() object.path = RL.GetBasePath()
-- Take last '/' away. -- Take last '/' away.
if util.utf8Sub( object.path, utf8.len( object.path ), utf8.len( object.path ) ) == "/" then if Util.utf8Sub( object.path, utf8.len( object.path ), utf8.len( object.path ) ) == "/" then
object.path = util.utf8Sub( object.path, 1, utf8.len( object.path ) - 1 ) object.path = Util.utf8Sub( object.path, 1, utf8.len( object.path ) - 1 )
end end
object.file = "" object.file = ""
@@ -228,11 +228,11 @@ function FileExplorer:updateFiles()
table.sort( folders, function( a, b ) return a < b end ) table.sort( folders, function( a, b ) return a < b end )
for _, folder in ipairs( folders ) do for _, folder in ipairs( folders ) do
self:addFileToList( folder, folderTexture, { 150, 120, 80 }, function() self:changeDir( folder ) end ) self:addFileToList( folder, FolderTexture, { 150, 120, 80 }, function() self:changeDir( folder ) end )
end end
for _, file in ipairs( files ) do for _, file in ipairs( files ) do
self:addFileToList( file, filesTexture, RL.WHITE, function() self:fileSelect( file ) end ) self:addFileToList( file, FilesTexture, RL.WHITE, function() self:fileSelect( file ) end )
end end
end end

View File

@@ -1,7 +1,7 @@
package.path = package.path..";"..RL.GetBasePath().."?.lua" package.path = package.path..";"..RL.GetBasePath().."?.lua"
package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
util = require( "utillib" ) Util = require( "utillib" )
Vec2 = require( "vector2" ) Vec2 = require( "vector2" )
Rect = require( "rectangle" ) Rect = require( "rectangle" )
Color = require( "color" ) Color = require( "color" )
@@ -13,29 +13,29 @@ FileExplorer = require( "file_explorer" )
-- Textures. -- Textures.
-- Note that textures are global. -- Note that textures are global.
cancelTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cancel.png" ) CancelTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cancel.png" )
backTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/previous-button.png" ) BackTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/previous-button.png" )
folderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/open-folder.png" ) FolderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/open-folder.png" )
filesTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/files.png" ) FilesTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/files.png" )
borderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" ) BorderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" )
bgrTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_bgr.png" ) BgrTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_bgr.png" )
RL.GenTextureMipmaps( cancelTexture ) RL.GenTextureMipmaps( CancelTexture )
RL.GenTextureMipmaps( backTexture ) RL.GenTextureMipmaps( BackTexture )
RL.GenTextureMipmaps( folderTexture ) RL.GenTextureMipmaps( FolderTexture )
RL.GenTextureMipmaps( filesTexture ) RL.GenTextureMipmaps( FilesTexture )
RL.GenTextureMipmaps( borderTexture ) RL.GenTextureMipmaps( BorderTexture )
RL.GenTextureMipmaps( bgrTexture ) RL.GenTextureMipmaps( BgrTexture )
RL.SetTextureFilter( cancelTexture, RL.TEXTURE_FILTER_TRILINEAR ) RL.SetTextureFilter( CancelTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( backTexture, RL.TEXTURE_FILTER_TRILINEAR ) RL.SetTextureFilter( BackTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( folderTexture, RL.TEXTURE_FILTER_TRILINEAR ) RL.SetTextureFilter( FolderTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( filesTexture, RL.TEXTURE_FILTER_TRILINEAR ) RL.SetTextureFilter( FilesTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( borderTexture, RL.TEXTURE_FILTER_TRILINEAR ) RL.SetTextureFilter( BorderTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( bgrTexture, RL.TEXTURE_FILTER_TRILINEAR ) RL.SetTextureFilter( BgrTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureWrap( borderTexture, RL.TEXTURE_WRAP_REPEAT ) RL.SetTextureWrap( BorderTexture, RL.TEXTURE_WRAP_REPEAT )
RL.SetTextureWrap( bgrTexture, RL.TEXTURE_WRAP_REPEAT ) RL.SetTextureWrap( BgrTexture, RL.TEXTURE_WRAP_REPEAT )
-- End of calculator definition. -- End of calculator definition.
@@ -43,7 +43,7 @@ local calculator = nil
local fileExplorer = nil local fileExplorer = nil
local showButton = nil local showButton = nil
function initGui() local function initGui()
showButton = Gui.element:new( { showButton = Gui.element:new( {
bounds = Rect:new( 0, 0, 96, 32 ), bounds = Rect:new( 0, 0, 96, 32 ),
drawBounds = true, drawBounds = true,
@@ -65,7 +65,7 @@ function RL.init()
local monitor = 0 local monitor = 0
local mPos = RL.GetMonitorPosition( monitor ) local mPos = RL.GetMonitorPosition( monitor )
local mSize = RL.GetMonitorSize( monitor ) local mSize = RL.GetMonitorSize( monitor )
winSize = RL.GetScreenSize() local winSize = RL.GetScreenSize()
RL.SetWindowTitle( "ReiLuaGui examples" ) RL.SetWindowTitle( "ReiLuaGui examples" )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
@@ -84,4 +84,4 @@ function RL.draw()
RL.ClearBackground( RL.RAYWHITE ) RL.ClearBackground( RL.RAYWHITE )
Gui.draw() Gui.draw()
end end

View File

@@ -47,10 +47,13 @@ function RL.init()
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 ) RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 ) RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 )
RL.GuiSetStyle( RL.SPINNER, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT ) RL.GuiSetStyle( RL.SPINNER, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT )
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT )
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) ) -- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) )
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) ) -- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.ORANGE ) )
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) ) -- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( RL.GREEN ) )
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_LINE_SPACING, 20 )
local label = Gui:Label( local label = Gui:Label(
Rect:new( 16, 16, 64, 32 ), Rect:new( 16, 16, 64, 32 ),
@@ -65,17 +68,26 @@ function RL.init()
local button = Gui:Button( local button = Gui:Button(
Rect:new( 245, 188, 64, 32 ), Rect:new( 245, 188, 64, 32 ),
"Dog", "Dog",
function() toggleGroup:setText( "Dog;Cat\nEagle" ) end, function() toggleGroup:setText( "Dog;Cat\nEagle" ) end
texture,
textureRect
) )
button.styles = {
{ 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 ) },
}
button.texture = texture
button.textureRect = textureRect
local checkbox = Gui:CheckBox( local checkbox = Gui:CheckBox(
Rect:new( 64, 128, 20, 20 ), Rect:new( 116, 128, 20, 20 ),
"Dog", "Visible",
toggleGroup.visible,
function( self ) toggleGroup.visible = self.checked end
)
local toggle = Gui:Toggle(
Rect:new( 32, 160, 100, 32 ),
"Toggle",
false, false,
nil, nil
texture,
textureRect
) )
local combobox = Gui:ComboBox( local combobox = Gui:ComboBox(
Rect:new( 64, 256, 128, 32 ), Rect:new( 64, 256, 128, 32 ),
@@ -128,10 +140,10 @@ 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,
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",
@@ -171,10 +183,13 @@ function RL.init()
function( self ) self.visible = false end, function( self ) self.visible = false end,
-- Grab callback. -- Grab callback.
function( self ) Gui:set2Top( self ) end, function( self ) Gui:set2Top( self ) end,
nil, nil
texture,
textureRect
) )
windowbox.styles = {
{ RL.DEFAULT, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( RL.RED ) },
}
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 ),
"GroupBox" "GroupBox"
@@ -189,15 +204,17 @@ function RL.init()
-- Grab callback. -- Grab callback.
function( self ) Gui:set2Top( self ) end function( self ) Gui:set2Top( self ) end
) )
panel.styles = {
{ 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( tabBar = Gui:GuiTabBar(
Rect:new( 700, 520, 700, 32 ), Rect:new( 700, 520, 700, 32 ),
"Cat;Dog;Horse;Cow", "Cat;Dog;Horse;Cow",
0, 0,
-- function( self ) Gui:set2Top( self ) end
nil, nil,
closeTab, closeTab
texture,
textureRect
) )
local scrollpanel = Gui:ScrollPanel( local scrollpanel = Gui:ScrollPanel(
Rect:new( 800, 64, 256, 256 ), Rect:new( 800, 64, 256, 256 ),
@@ -222,23 +239,26 @@ function RL.init()
0, 0,
0, 0,
0, 0,
function( self ) print( self:getItem( self.active ) ) end, function( self ) print( self:getItem( self.active ) ) end
texture,
textureRect
) )
listviewex.styles = {
{ 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 ) },
}
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",
"Message", "Should we disable\nwindow box?",
"Cancel;Ok", "No;Yes",
function( self ) function( self )
if 0 < self.buttonIndex then if 0 < self.buttonIndex then
print( "You pressed "..self:getItem( self.buttonIndex ) )
if self.buttonIndex == 1 then if self.buttonIndex == 1 then
Gui:set2Back( windowbox ) windowbox.disabled = false
elseif self.buttonIndex == 2 then elseif self.buttonIndex == 2 then
Gui:set2Top( windowbox ) windowbox.disabled = true
end end
end end
end, end,

View File

@@ -875,4 +875,4 @@ Gui.shape = Shape
Gui.element = Element Gui.element = Element
Gui.container = Container Gui.container = Container
return Gui return Gui

File diff suppressed because it is too large Load Diff