TouchGFX中的按钮是一种感应触控事件的控件,能够在按钮被按下/释放时发送回调
代码
#ifndef TOUCHGFX_ABSTRACTBUTTON_HPP
#define TOUCHGFX_ABSTRACTBUTTON_HPP
#include <touchgfx/Callback.hpp>
#include <touchgfx/events/ClickEvent.hpp>
#include <touchgfx/widgets/Widget.hpp>
namespace touchgfx
{
/* 按键抽象接口类 */
class AbstractButton : public Widget
{
public:
/* 构造函数 */
AbstractButton() : Widget(), action(), pressed(false)
{
setTouchable(true); //打开触摸功能
}
/* 点击事件处理函数 */
virtual void handleClickEvent(const ClickEvent& event);
/* 设置点击事件回调函数 */
void setAction(GenericCallback<const AbstractButton&>& callback)
{
action = &callback;
}
/* 执行点击事件回调函数 */
virtual void executeAction()
{
if (action && action->isValid()