Using Key and Touch Events
This section will discuss how interactive scripts receiving user inputs via key and touch events can be created.
EventDemo Widget
-- This code chunk is loaded on demand by the widget's main script
-- when the create(...) function is run. Hence, the body of this
-- file is executed by the widget's create(...) function.
-- zone and options were passed as arguments to chunk(...)
local zone, options = ...
-- The widget table will be returned to the main script
local widget = { }
function widget.refresh(event, touchState)
if event == nil then -- Widget mode
-- Draw in widget mode. The size equals zone.w by zone.h
else -- Full screen mode
-- Draw in full screen mode. The size equals LCD_W by LCD_H
if event ~= 0 then -- Do we have an event?
if touchState then -- Only touch events come with a touchState
if event == EVT_TOUCH_FIRST then
-- When the finger first hits the screen
elseif event == EVT_TOUCH_BREAK then
-- When the finger leaves the screen and did not slide on it
elseif event == EVT_TOUCH_TAP then
-- A short tap gives TAP instead of BREAK
-- touchState.tapCount shows number of taps
elseif event == EVT_TOUCH_SLIDE then
-- Sliding the finger gives a SLIDE instead of BREAK or TAP
if touchState.swipeRight then
-- Is true if user swiped right
elseif touchState.swipeLeft then
elseif touchState.swipeUp then
elseif touchState.swipeDown then
-- etc.
else
-- Sliding but not swiping
end
end
else -- event ~= 0 and touchState == nil: key event
if event == EVT_VIRTUAL_ENTER then
-- User hit ENTER
elseif event == EVT_VIRTUAL_EXIT then
-- etc.
end
end
end
end
endLibGUI
libGUI Properties
libGUI.flags
libGUI.colors
Color
Default value
Used for
libGUI.widgetRefresh
libGUI Functions
libGUI.match(x, ...)
libGUI.newGUI()
GUI Object Properties
GUI.fullScreenRefresh
GUI Object Functions
GUI.run(event, touchState)
GUI.setEventHandler(event, f)
GUI.showPrompt(guiPrompt)
GUI.dismissPrompt()
GUI Screen Elements
GUI.button (x, y, w, h, title, callBack [, flags])
GUI.toggleButton(x, y, w, h, title, value, callBack [, flags])
GUI.number(x, y, w, h, value, changeValue [, flags])
GUI.timer(x, y, w, h, tmr, changeValue [, flags])
GUI.label(x, y, w, h, title[, flags])
GUI.menu(x, y, w, h, items, callBack [, flags])
GUI.dropDown(x, y, w, h, items, selected, callBack, flags)
GUI.gui.horizontalSlider(x, y, w, value, min, max, delta, callBack)
GUI.gui.verticalSlider(x, y, w, value, min, max, delta, callBack)
gui.custom(self, x, y, w, h)
gui.gui(x, y, w, h)
Last updated
Was this helpful?