Difference between revisions of "UI.Behavior"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2023.1<br/> '''Class:''' UI<br/> === Description === Adds behaviors to a widget. Available behaviors are ''LongClick'', ''Linger'...")
 
 
(One intermediate revision by the same user not shown)
Line 17: Line 17:
 
'''params''': (table) any of Behavior parameters<br/>
 
'''params''': (table) any of Behavior parameters<br/>
  
=== Example ===
+
=== Examples ===
 +
'''Click and Long Click'''
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
local gui=UI.Button.new()
 
local gui=UI.Button.new()
Line 41: Line 42:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{GIDEROS IMPORTANT LINKS}}
+
'''Drag'''
 +
<syntaxhighlight lang="lua">
 +
local gui = UI.Button.new()
 +
gui:setDimensions(64, 48)
 +
gui:setPosition(128, 128)
 +
gui:setText("btn")
 +
gui.name = "button"
 +
stage:addChild(gui)
 +
 
 +
UI.Behavior.DragClick.new(gui)
 +
 
 +
function gui:onWidgetDragClick(w, x, y)
 +
print(w.name, x, y)
 +
end
 +
</syntaxhighlight>
 +
 
 +
 
 +
{{UI}}

Latest revision as of 19:41, 5 September 2024

Available since: Gideros 2023.1
Class: UI

Description

Adds behaviors to a widget. Available behaviors are LongClick, Linger, DragMove, DragSize.

UI.Behavior.LongClick.new(widget,params)

A Behavior can have the following parameters:

  • clsIndicator: the Indicator class to use UI.ProgressBar, UI.CircularProgress, ...
  • szIndicator: the Indicator size

Parameters

widget: (sprite) the widget to add behavior to
params: (table) any of Behavior parameters

Examples

Click and Long Click

local gui=UI.Button.new()
gui:setDimensions(64, 48)
gui:setPosition(128, 128)
gui:setText("btn")
gui.name = "button"
stage:addChild(gui)

UI.Behavior.LongClick.new(gui,{ clsIndicator=UI.CircularProgress, szIndicator=32 })

function gui:onWidgetAction(w)
	print(w.name, "clicked")
end

function gui:onWidgetLongAction(w)
	print(w.name, "long clicked!")
end

-- we need a Screen widget to see the Circular Progress Indicator
local screen=UI.Screen.new()
screen:ui(gui)

Drag

local gui = UI.Button.new()
gui:setDimensions(64, 48)
gui:setPosition(128, 128)
gui:setText("btn")
gui.name = "button"
stage:addChild(gui)

UI.Behavior.DragClick.new(gui)

function gui:onWidgetDragClick(w, x, y)
	print(w.name, x, y)
end