Difference between revisions of "ImGui.Core:beginWindow"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
m
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
=== Description ===
 
=== Description ===
Pushes a window to the stack and starts appending to it.
+
Pushes a Window to the stack and starts appending to it.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
(bool) (bool) = ImGui:beginWindow(name,open,flags)
 
(bool) (bool) = ImGui:beginWindow(name,open,flags)
</source>
+
</syntaxhighlight>
  
 
'''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.
 
'''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.
Line 14: Line 14:
 
'''name''': (string) the window title to be displayed<br/>
 
'''name''': (string) the window title to be displayed<br/>
 
'''open''': (bool) the status of the window, true=opened, false=closed, '''nil=no close button on window'''<br/>
 
'''open''': (bool) the status of the window, true=opened, false=closed, '''nil=no close button on window'''<br/>
'''flags''': (string) any of the ImGui Window flags, see '''[[ImGui.Core|ImGui Constants - Window Flags]]'''<br/>
+
'''flags''': (string) any of the ImGui Window flags, see '''[[ImGui.CONST.WindowFlags|ImGui.WindowFlags]]'''<br/>
  
 
=== Return values ===
 
=== Return values ===
Line 73: Line 73:
  
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
</source>
+
</syntaxhighlight>
  
 
{{ImGui}}
 
{{ImGui}}

Latest revision as of 04:46, 12 October 2023

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.WindowFlags

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.deltaTime)

	-- 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)