Difference between revisions of "ImGui.Core:dragFloat2"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2020.9<br/> '''Class:''' ImGui<br/> === Description === Displays 2 float drag sliders, side by side. <source lang="lua"> (number)...")
 
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(3 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Displays 2 float drag sliders, side by side.
 
Displays 2 float drag sliders, side by side.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(number), (number), (bool) =
 
(number), (number), (bool) =
 
   ImGui:dragFloat2(label, value1, value2, [incStep=1, min=0, max=0, formatString="%.3f", ImGuiSliderFlags=0])
 
   ImGui:dragFloat2(label, value1, value2, [incStep=1, min=0, max=0, formatString="%.3f", ImGuiSliderFlags=0])
</source>
+
</syntaxhighlight>
 
 
 
 
'''Widgets: Drag Sliders'''
 
* CTRL+Click on any drag box to turn them into an input box. Manually input values aren't clamped and can go off-bounds.
 
* For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x
 
* Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc.
 
* Format string may also be set to NULL or use the default format ("%f" or "%d").
 
* Speed are per-pixel of mouse movement (v_speed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(v_speed, minimum_step_at_given_precision).
 
* Use v_min < v_max to clamp edits to given limits. Note that CTRL+Click manual input can override those limits.
 
* Use v_max = FLT_MAX / INT_MAX etc to avoid clamping to a maximum, same with v_min = -FLT_MAX / INT_MIN to avoid clamping to a minimum.
 
* We use the same sets of flags for DragXXX() and SliderXXX() functions as the features are the same and it makes it easier to swap them.
 
  
 
=== Parameters ===
 
=== Parameters ===
Line 37: Line 26:
  
 
=== Example ===
 
=== Example ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
require "ImGui"
 
require "ImGui"
  
Line 49: Line 38:
 
function onEnterFrame(e)
 
function onEnterFrame(e)
 
-- 1 we start ImGui
 
-- 1 we start ImGui
imgui:newFrame(e)
+
imgui:newFrame(e.deltaTime)
 
-- 2 we add some child windows and build our GUI
 
-- 2 we add some child windows and build our GUI
 
window01 = imgui:beginWindow("Window 01") -- no close button (X)
 
window01 = imgui:beginWindow("Window 01") -- no close button (X)
Line 65: Line 54:
  
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
</source>
+
</syntaxhighlight>
  
 
{{ImGui}}
 
{{ImGui}}

Latest revision as of 15:29, 13 July 2023

Available since: Gideros 2020.9
Class: ImGui

Description

Displays 2 float drag sliders, side by side.

(number), (number), (bool) =
  ImGui:dragFloat2(label, value1, value2, [incStep=1, min=0, max=0, formatString="%.3f", ImGuiSliderFlags=0])

Parameters

label: (string) the label
value1: (number) the current 1st value
value2: (number) the current 2nd value
incStep: (number) the increment step
min: (number) the min value
max: (number) the max value
formatString: (string) the format of the value
ImGuiSliderFlags: (number) the drag slider flag

Return values

Returns (number) the current 1st value
Returns (number) the current 2nd value
Returns (bool) whether one of the current values has changed

Example

require "ImGui"

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

local window01 = true
local dragvalue01 = 0
local dragvalue02 = 30

function onEnterFrame(e)
	-- 1 we start ImGui
	imgui:newFrame(e.deltaTime)
	-- 2 we add some child windows and build our GUI
	window01 = imgui:beginWindow("Window 01") -- no close button (X)
	if window01 then -- the variable is false when window is collapsed
		imgui:text("Hello Dear ImGui!") -- we add a text element to our GUI
		local isChanged = false
		dragvalue01, dragvalue02, isChanged = imgui:dragFloat2("x, y", dragvalue01, dragvalue02, 0.2, 0, 100, "%.3f", 2)
		if isChanged then print(dragvalue01, dragvalue02) end
--		print(e.deltaTime)
	end
	-- 3 we end the frame and render to screen
	imgui:endFrame()
	imgui:render()
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)