Difference between revisions of "UI Buttons"

From GiderosMobile
(new page ui buttons)
 
 
(44 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__TOC__
 
__TOC__
  
<languages />
+
Here you will find various resources to help you create buttons in Gideros Studio.
  
<translate><!--T:1--> Here you will find various resources to help you create buttons in Gideros Studio.</translate>
+
'''DESKTOPS, MOBILE & HTML5 COMPATIBLE THEY ARE!'''
  
=== <translate>Simple Button</translate> ===
+
'''note''': you may have to provide your own assets (fonts, gfx, …)
<br/>
 
  
<source lang="lua">
+
=== Button '''[[Button_class]]''' ===
--[[
+
This is the base of all Gideros buttons.
A generic button class
 
  
This code is MIT licensed, see http://www.opensource.org/licenses/mit-license.php
+
{{#widget:GApp|app=ButtonDemo1.GApp|width=300|height=180}}
(C) 2010 - 2011 Gideros Mobile
 
]]
 
  
Button = Core.class(Sprite)
 
  
function Button:init(upState, downState) -- upstate and downstate are bitmaps
+
=== Button Text '''[[ButtonText_class]]''' ===
self.upState = upState
+
This is almost the same as '''Button''' but with some text you can add.
self.downState = downState
 
 
self.focus = false
 
  
-- set the visual state as "up"
 
self:updateVisualState(false)
 
  
-- register to all mouse and touch events
+
=== Button Disabled '''[[ButtonDisabled_class]]''' ===
self:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)
+
This is the same as '''Button''' but with a Disabled state.
self:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, self)
 
self:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
 
  
self:addEventListener(Event.TOUCHES_BEGIN, self.onTouchesBegin, self)
+
{{#widget:GApp|app=ButtonDisabledDemo1.GApp|width=300|height=180}}
self:addEventListener(Event.TOUCHES_MOVE, self.onTouchesMove, self)
 
self:addEventListener(Event.TOUCHES_END, self.onTouchesEnd, self)
 
self:addEventListener(Event.TOUCHES_CANCEL, self.onTouchesCancel, self)
 
end
 
  
function Button:onMouseDown(event)
 
if self:hitTestPoint(event.x, event.y) then
 
self.focus = true
 
self:updateVisualState(true)
 
event:stopPropagation()
 
end
 
end
 
  
function Button:onMouseMove(event)
+
=== Button Toggle '''[[ButtonToggle_class]]''' ===
if self.focus then
+
A button you can toggle on and off.
if not self:hitTestPoint(event.x, event.y) then
 
self.focus = false
 
self:updateVisualState(false)
 
end
 
event:stopPropagation()
 
end
 
end
 
  
function Button:onMouseUp(event)
+
{{#widget:GApp|app=ButtonToggleDemo1.GApp|width=320|height=180}}
if self.focus then
 
self.focus = false
 
self:updateVisualState(false)
 
self:dispatchEvent(Event.new("click")) -- button is clicked, dispatch "click" event
 
event:stopPropagation()
 
end
 
end
 
  
-- if button is on focus, stop propagation of touch events
 
function Button:onTouchesBegin(event)
 
if self.focus then
 
event:stopPropagation()
 
end
 
end
 
  
-- if button is on focus, stop propagation of touch events
+
=== Button Monster '''[[ButtonMonster_class]]''' ===
function Button:onTouchesMove(event)
+
This button has a lot: mouse and keyboard navigation, hover, tooltip, sound, ... It may look scary but it is a nice monster ;-)
if self.focus then
 
event:stopPropagation()
 
end
 
end
 
  
-- if button is on focus, stop propagation of touch events
+
{{#widget:GApp|app=ButtonMonsterDemo2x.GApp|width=320|height=180}}
function Button:onTouchesEnd(event)
 
if self.focus then
 
event:stopPropagation()
 
end
 
end
 
  
-- if touches are cancelled, reset the state of the button
 
function Button:onTouchesCancel(event)
 
if self.focus then
 
self.focus = false;
 
self:updateVisualState(false)
 
event:stopPropagation()
 
end
 
end
 
  
-- if state is true show downState else show upState
+
=== Button Beast '''[[ButtonBeast_class]]''' ===
function Button:updateVisualState(state)
+
This is like the '''Button Monster''' but without tooltip and without integrated keyboard navigation.
if state then
 
if self:contains(self.upState) then
 
self:removeChild(self.upState)
 
end
 
 
if not self:contains(self.downState) then
 
self:addChild(self.downState)
 
end
 
else
 
if self:contains(self.downState) then
 
self:removeChild(self.downState)
 
end
 
 
if not self:contains(self.upState) then
 
self:addChild(self.upState)
 
end
 
end
 
end
 
  
---- USAGE
+
{{#widget:GApp|app=ButtonBeastDemo1.GApp|width=320|height=180}}
---- clickable button (arrow button)
+
 
--local arrow = Texture.new("gfx/arrow_right.png")
+
 
--local arrow_pressed = Texture.new("gfx/arrow_right_down.png")
+
{{GIDEROS IMPORTANT LINKS}}
--local button = Button.new(Bitmap.new(arrow), Bitmap.new(arrow_pressed))
 
--button:addEventListener("click", function()
 
-- -- your code here
 
--end)
 
</source>
 
<br/>
 

Latest revision as of 20:44, 1 December 2023

Here you will find various resources to help you create buttons in Gideros Studio.

DESKTOPS, MOBILE & HTML5 COMPATIBLE THEY ARE!

note: you may have to provide your own assets (fonts, gfx, …)

Button Button_class

This is the base of all Gideros buttons.


Button Text ButtonText_class

This is almost the same as Button but with some text you can add.


Button Disabled ButtonDisabled_class

This is the same as Button but with a Disabled state.


Button Toggle ButtonToggle_class

A button you can toggle on and off.


Button Monster ButtonMonster_class

This button has a lot: mouse and keyboard navigation, hover, tooltip, sound, ... It may look scary but it is a nice monster ;-)


Button Beast ButtonBeast_class

This is like the Button Monster but without tooltip and without integrated keyboard navigation.