Skip to content

Instantly share code, notes, and snippets.

@igniuss
Created September 4, 2017 22:47
Show Gist options
  • Save igniuss/85ae8a7218d91e7c9689ef40624ae378 to your computer and use it in GitHub Desktop.
Save igniuss/85ae8a7218d91e7c9689ef40624ae378 to your computer and use it in GitHub Desktop.
Example for Homebrew Lua code for GUI
local imgui = {}
function main(go)
imgui.gameObject = go
return imgui
end
function imgui:Start()
self.window = {
id = 1338,
rect = Rect(15,200,200,1), --x,y,width,height
update = self.UpdateWindow,
values = {
Toggle = false,
TextField = "" ,
PasswordField = "" ,
TextArea = "" ,
Toolbar = 0,
SelectionGrid = 0 ,
HorizontalSlider = 0 ,
BeginScrollView = Vector2(0,0) ,
}
}
end
function imgui:OnGUI()
self.window.rect = GUILayout.Window(self.window.id, self.window.rect, self.window.update, "")
end
function imgui.UpdateWindow(id)
GUILayout.DragWindow(Rect(0,0,imgui.window.rect.width,20)) --makes top part of window draggable
local s = imgui.window.values
local l = function(title, content)
GUILayout.BeginHorizontal()
GUILayout.Label(title)
GUILayout.Space(15)
content()
GUILayout.EndHorizontal()
end
GUILayout.Label("Label")
GUILayout.Button("Button")
s.Toggle = GUILayout.Toggle(s.Toggle, "Toggle")
GUILayout.BeginHorizontal()
GUILayout.Label("Text Field")
GUILayout.Space(15)
s.TextField = GUILayout.TextField(s.TextField)
GUILayout.EndHorizontal()
GUILayout.BeginHorizontal()
GUILayout.Label("Pass Field")
GUILayout.Space(15)
s.PasswordField = GUILayout.PasswordField(s.PasswordField)
GUILayout.EndHorizontal()
s.Toolbar = GUILayout.Toolbar(s.Toolbar, {"Option 0","Option 1","Option 2"})
s.SelectionGrid = GUILayout.SelectionGrid(s.SelectionGrid,{"Option 0","Option 1","Option 2","Option 3","Option 4","Option 5"}, 4)
s.HorizontalSlider = GUILayout.HorizontalSlider(s.HorizontalSlider, 0, 20)
GUILayout.Label(string.format("Slider value is %.2f",s.HorizontalSlider))
s.BeginScrollView = GUILayout.BeginScrollView(s.BeginScrollView, 100)
for i=0,100 do
GUILayout.Label("HELLO THERE")
end
GUILayout.EndScrollView()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment