Difference between revisions of "ImGui.Core:beginWindow"

From GiderosMobile
Line 4: Line 4:
  
 
=== Description ===
 
=== Description ===
Pushes window to the stack and starts appending to it.
+
Pushes a window to the stack and starts appending to it.
 
<source lang="lua">
 
<source lang="lua">
 
(bool) (bool) = ImGui:beginWindow(name,open,flags)
 
(bool) (bool) = ImGui:beginWindow(name,open,flags)
 
</source>
 
</source>
  
'''note''': if ''open'' is nil then only the first boolean is returned
+
'''note''': if ''open'' is nil (window with no X button) then only the second boolean is returned. The boolean will then return whether the window is expanded or colapsed.
  
 
=== Parameters ===
 
=== Parameters ===
Line 17: Line 17:
  
 
=== Return values ===
 
=== Return values ===
 +
'''Returns''': (bool) if second argument (''open'') is nil, returns only the second boolean below, otherwise it returns the status of the window, true=opened, false=closed<br/>
 
'''Returns''': (bool) whether the window is collapsed or expanded<br/>
 
'''Returns''': (bool) whether the window is collapsed or expanded<br/>
'''Returns''': (bool) the status of the window, true=opened, false=closed, '''nil=non closeable window'''<br/>
 
  
 
=== Example ===
 
=== Example ===
Line 27: Line 27:
 
stage:addChild(imgui)
 
stage:addChild(imgui)
  
local window01 = true -- the starting state of window01 (collapsed, expanded), with a close button
+
local window01 = true -- the starting state of window01, true=window is visible at start up
local window02 = true -- the starting state of window02 (collapsed, expanded), with no close button
+
local window02 = true -- the starting state of window02, true=window is visible at start up
local window03 = true -- the starting state of window03 (collapsed, expanded), with no title bar
+
local window03 = true -- the starting state of window03, true=window is visible at start up
  
 
function onEnterFrame(e)
 
function onEnterFrame(e)
Line 36: Line 36:
  
 
-- 2 we add a child window and build our GUI
 
-- 2 we add a child window and build our GUI
if window01 then -- is window expanded?
+
if window01 then -- is window visible (not closed)?
local windowdrawn = false
+
local windowdrawn = false -- is window expanded or colapsed?
 
window01, windowdrawn = imgui:beginWindow( -- with close button
 
window01, windowdrawn = imgui:beginWindow( -- with close button
 
"Hello ImGui v"..ImGui._VERSION, -- window title
 
"Hello ImGui v"..ImGui._VERSION, -- window title
window01 -- is window expanded?
+
window01 -- returns window visibility
 
)
 
)
 
if windowdrawn then -- the variable is false when main window is collapsed
 
if windowdrawn then -- the variable is false when main window is collapsed
Line 50: Line 50:
  
 
window02 = imgui:beginWindow("Window02") -- no close button
 
window02 = imgui:beginWindow("Window02") -- no close button
if window02 then
+
if window02 then -- is window expanded or colapsed?
 
imgui:text("I am a text in window02")
 
imgui:text("I am a text in window02")
 
print(e.deltaTime) -- test
 
print(e.deltaTime) -- test
Line 57: Line 57:
  
 
window03 = imgui:beginWindow(
 
window03 = imgui:beginWindow(
0,
+
0, -- dummy title because we set the window with no title bar
 
nil, -- no close button
 
nil, -- no close button
 
ImGui.WindowFlags_NoTitleBar -- no title bar
 
ImGui.WindowFlags_NoTitleBar -- no title bar
 
)
 
)
if window03 then -- if window is expanded
+
if window03 then -- is window expanded or colapsed?
 
imgui:text("This is an ImGui text.") -- we add a text element to our GUI
 
imgui:text("This is an ImGui text.") -- we add a text element to our GUI
 
imgui:textColored("This is a colored text.", 0xff00ff, 1)
 
imgui:textColored("This is a colored text.", 0xff00ff, 1)

Revision as of 22:31, 25 March 2021

Available since: Gideros 2020.9
Class: ImGui

Description

Pushes a window to the stack and starts appending to it.

(bool) (bool) = ImGui:beginWindow(name,open,flags)

note: if open is nil (window with no X button) then only the second boolean is returned. The boolean will then return whether the window is expanded or colapsed.

Parameters

name: (string) the window title to be displayed
open: (bool) the status of the window, true=opened, false=closed, nil=no close button on window
flags: (string) any of the ImGui Window flags, see ImGui Constants - Window Flags

Return values

Returns: (bool) if second argument (open) is nil, returns only the second boolean below, otherwise it returns the status of the window, true=opened, false=closed
Returns: (bool) whether the window is collapsed or expanded

Example

require "ImGui"

local imgui = ImGui.new()
stage:addChild(imgui)

local window01 = true -- the starting state of window01, true=window is visible at start up
local window02 = true -- the starting state of window02, true=window is visible at start up
local window03 = true -- the starting state of window03, true=window is visible at start up

function onEnterFrame(e)
	-- 1 we start ImGui
	imgui:newFrame(e)

	-- 2 we add a child window and build our GUI
	if window01 then -- is window visible (not closed)?
		local windowdrawn = false -- is window expanded or colapsed?
		window01, windowdrawn = imgui:beginWindow( -- with close button
			"Hello ImGui v"..ImGui._VERSION, -- window title
			window01 -- returns window visibility
		)
		if windowdrawn then -- the variable is false when main window is collapsed
			imgui:text("This is an ImGui text.") -- we add a text element to our GUI
			imgui:textColored("This is a colored text.", 0xff00ff, 1)
			-- ...
		end
	end

	window02 = imgui:beginWindow("Window02") -- no close button
	if window02 then -- is window expanded or colapsed?
		imgui:text("I am a text in window02")
		print(e.deltaTime) -- test
		-- ...
	end

	window03 = imgui:beginWindow(
		0, -- dummy title because we set the window with no title bar
		nil, -- no close button
		ImGui.WindowFlags_NoTitleBar -- no title bar
	)
	if window03 then -- is window expanded or colapsed?
		imgui:text("This is an ImGui text.") -- we add a text element to our GUI
		imgui:textColored("This is a colored text.", 0xff00ff, 1)
		-- ...
	end

	-- 3 we end the frame and render to screen
	imgui:endFrame()
	imgui:render()
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)