Difference between revisions of "ImGui.Core:checkbox"

From GiderosMobile
(modified the page a bit)
m (added a variation as example)
Line 15: Line 15:
 
=== Return values ===
 
=== Return values ===
 
'''Returns''' (bool) the new current boolean value<br/>
 
'''Returns''' (bool) the new current boolean value<br/>
'''Returns''' (bool) whether a value has changed<br/>
+
'''Returns''' (bool) whether a value has changed '''optional'''<br/>
  
=== Example ===
+
=== Examples ===
 +
'''Using a flag'''
 
<source lang="lua">
 
<source lang="lua">
 
MyClass = Core.class(Sprite)
 
MyClass = Core.class(Sprite)
Line 47: Line 48:
 
self.isbold, ischanged = self.imgui:checkbox("Bold", self.isbold)
 
self.isbold, ischanged = self.imgui:checkbox("Bold", self.isbold)
 
if ischanged then print(self.isbold) end
 
if ischanged then print(self.isbold) end
 +
end
 +
self.imgui:endWindow()
 +
end
 +
self.imgui:endFrame()
 +
self.imgui:render()
 +
end
 +
 +
-- EVENT LISTENERS
 +
function MyClass:onTransitionInBegin()
 +
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
 +
end
 +
</source>
 +
 +
 +
'''Without using a flag'''
 +
<source lang="lua">
 +
MyClass = Core.class(Sprite)
 +
 +
function MyClass:init()
 +
self.imgui = ImGui.new()
 +
-- we create a variable to hold our window status
 +
self.window01 = true -- window01 exists at start up
 +
self.isbold = false -- checkbox starting status
 +
-- order
 +
self:addChild(self.imgui)
 +
-- LISTENERS
 +
self:addEventListener("enterBegin", self.onTransitionInBegin, self)
 +
end
 +
 +
-- LOOP
 +
function MyClass:onEnterFrame(e)
 +
-- 1 we start ImGui
 +
self.imgui:newFrame(e.deltaTime)
 +
-- 2 we build our GUI
 +
if self.window01 then -- is window01 existant?
 +
local windowdrawn = false -- is window01 colapsed?
 +
local ischanged = false
 +
self.window01, windowdrawn = self.imgui:beginWindow(
 +
"Hello ImGui", -- window title
 +
self.window01 -- is window01 existant?
 +
)
 +
if windowdrawn then -- the variable is false when window01 is collapsed
 +
self.isbold = self.imgui:checkbox("Bold", self.isbold)
 
end
 
end
 
self.imgui:endWindow()
 
self.imgui:endWindow()

Revision as of 01:29, 1 December 2021

Available since: Gideros 2020.9
Class: ImGui

Description

Displays a checkbox.

(bool), (bool) = ImGui:checkbox(text,flag)

Parameters

text: (string) the checkbox text
flag: (bool) the checkbox status, true=checked, false=unchecked

Return values

Returns (bool) the new current boolean value
Returns (bool) whether a value has changed optional

Examples

Using a flag

MyClass = Core.class(Sprite)

function MyClass:init()
	self.imgui = ImGui.new()
	-- we create a variable to hold our window status
	self.window01 = true -- window01 exists at start up
	self.isbold = false -- checkbox starting status
	-- order
	self:addChild(self.imgui)
	-- LISTENERS
	self:addEventListener("enterBegin", self.onTransitionInBegin, self)
end

-- LOOP
function MyClass:onEnterFrame(e)
	-- 1 we start ImGui
	self.imgui:newFrame(e.deltaTime)
	-- 2 we build our GUI
	if self.window01 then -- is window01 existant?
		local windowdrawn = false -- is window01 colapsed?
		local ischanged = false
		self.window01, windowdrawn = self.imgui:beginWindow(
			"Hello ImGui", -- window title
			self.window01 -- is window01 existant?
		)
		if windowdrawn then -- the variable is false when window01 is collapsed
			self.isbold, ischanged = self.imgui:checkbox("Bold", self.isbold)
			if ischanged then print(self.isbold) end
		end
		self.imgui:endWindow()
	end
	self.imgui:endFrame()
	self.imgui:render()
end

-- EVENT LISTENERS
function MyClass:onTransitionInBegin()
	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end


Without using a flag

MyClass = Core.class(Sprite)

function MyClass:init()
	self.imgui = ImGui.new()
	-- we create a variable to hold our window status
	self.window01 = true -- window01 exists at start up
	self.isbold = false -- checkbox starting status
	-- order
	self:addChild(self.imgui)
	-- LISTENERS
	self:addEventListener("enterBegin", self.onTransitionInBegin, self)
end

-- LOOP
function MyClass:onEnterFrame(e)
	-- 1 we start ImGui
	self.imgui:newFrame(e.deltaTime)
	-- 2 we build our GUI
	if self.window01 then -- is window01 existant?
		local windowdrawn = false -- is window01 colapsed?
		local ischanged = false
		self.window01, windowdrawn = self.imgui:beginWindow(
			"Hello ImGui", -- window title
			self.window01 -- is window01 existant?
		)
		if windowdrawn then -- the variable is false when window01 is collapsed
			self.isbold = self.imgui:checkbox("Bold", self.isbold)
		end
		self.imgui:endWindow()
	end
	self.imgui:endFrame()
	self.imgui:render()
end

-- EVENT LISTENERS
function MyClass:onTransitionInBegin()
	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end