summaryrefslogtreecommitdiff
path: root/examples/raygui_examples/main.lua
blob: e0e7ac365a3449583f3e2eefd37bcd7e1691bbd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package.path = package.path..";"..RL.GetBasePath().."?.lua"
package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"

Util = require( "utillib" )
Rect = require( "rectangle" )
Vec2 = require( "vector2" )
Color = require( "color" )
Raygui = require( "raygui" )
Calculator = require( "calculator" )
FileBrowser = require( "file_browser" )

Gui = Raygui:new()

local showAllButton = nil
local calculator = nil
local fileBrowser = nil

local function loadFile( path )
	print( "Load file: "..path )
end

local function showAll()
	calculator:setVisible( true )
	fileBrowser:setVisible( true )
end

function RL.init()
	local monitor = 0
	local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
	local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
	local winSize = Vec2:new( 1024, 800 )

	RL.SetWindowTitle( "Raygui examples" )
	RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
	RL.SetWindowState( RL.FLAG_VSYNC_HINT )
	RL.SetWindowSize( winSize )
	RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )

	RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
	RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 )

	RL.GuiLoadStyle( RL.GetBasePath().."../resources/styles/style_dark.rgs" )

	showAllButton = Gui:Button(
		Rect:new( 0, 0, 108, 28 ),
		"Show All",
		{ -- callbacks.
			pressed = function() showAll() end
		}
	)

	calculator = Calculator:new( Vec2:new( 32, 32 ) )
	fileBrowser = FileBrowser:new(
		Vec2:new( 250, 100 )
	)

	fileBrowser:popup( fileBrowser.MODES.OPEN, RL.GetBasePath(), loadFile )
end

function RL.update( delta )
	Gui:update()
end

function RL.draw()
	RL.ClearBackground( RL.DARKBLUE )

	Gui:draw()
end