UI.Button

From GiderosMobile
Revision as of 16:43, 14 October 2023 by MoKaLux (talk | contribs) (Created page with "__NOTOC__ '''Available since:''' Gideros 2023.1<br/> '''Class:''' UI<br/> === Description === Creates Button widgets. The widget can be a '''Button''', a '''ToggleButton'...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Available since: Gideros 2023.1
Class: UI

Description

Creates Button widgets. The widget can be a Button, a ToggleButton or a PopupButton.

UI.Button.new(params)

Available parameters are:

  • Repeat (number) the repeat speed
  • RepeatSpeedup (number) speedup factor (<1 to increase actual speed)
  • NoDoubleClick (boolean) disables double clicking ability (faster response)

Parameters

params: (table) the Button widget parameters

Examples

A Button

UI.Style:setDefault(UI.Theme.PointCore_Pink)

local gui=UI.Button.new()
gui:setDimensions(96, 48)
gui:setPosition(50,50)
gui:setText("button")
gui.name = "btn1"

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

stage:addChild(gui)

Two buttons, introducing the events system

UI.Style:setDefault(UI.Theme.PointCore_Pink)

local buttonA=UI.Button.new()
buttonA:setDimensions(64, 48)
buttonA:setPosition(150,50)
buttonA:setText("btn1")

local buttonB=UI.Button.new()
buttonB:setDimensions(64, 48)
buttonB:setPosition(150,150)
buttonB:setText("btn2")

stage:addChild(buttonA)
stage:addChild(buttonB)

--Here we put the WidgetAction listener on stage. 
--It will be propagated from each button up to stage through the sprite tree
--First parameter of event listeners are always the source widget of the event
function stage:onWidgetAction(w)
	if w==buttonA then
		print("b1")
	elseif w==buttonB then
		print("b2")
	end
end

A button with repeat on

UI.Style:setDefault(UI.Theme.PointCore_Pink)

local gui=UI.Button.new({ Repeat=0.5, RepeatSpeedup=0.9, NoDoubleClick=true, })
gui:setDimensions(64, 48)
gui:setPosition(128, 128)
gui:setText("btn")
gui.name = "button"

stage:addChild(gui)

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

A button with a long click indicator

UI.Style:setDefault(UI.Theme.PointCore_Pink)

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

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

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

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

local screen=UI.Screen.new() -- needed to add the long click indicator
screen:ui(gui)