<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 設計應用 > TouchGFX 處理按鈕長(cháng)按的一種方法

TouchGFX 處理按鈕長(cháng)按的一種方法

作者: 時(shí)間:2023-11-13 來(lái)源:ST 收藏

1. 前言在使用 設計UI 界面時(shí),用同一按鈕的長(cháng)按和短按表示不同的功能是個(gè)比較常見(jiàn)的實(shí)際需求。普通的Button 控件可以通過(guò)Interactions 處理一些基本的交互動(dòng)作,通過(guò)下面一些簡(jiǎn)單的操作,我們可以將這個(gè)普通的Button 改造成可以根據不同的按鍵時(shí)間處理不同事務(wù)的多功能按鈕。

本文引用地址:http://dyxdggzs.com/article/202311/452791.htm

2. 操作方法

(1)創(chuàng )建一個(gè)按鈕,并在Mixins 中勾選ClickListener 功能,使Button 能夠響應觸控輸入。

圖1. Enable ClickListener

1699856700813691.png

啟用ClickListener Mixin 后,會(huì )更改生成的控件的聲明,下面的代碼表示button1 啟用了ClickListener Mixin。

touchgfx::ClickListener< touchgfx::Button > button1;

(2)用戶(hù)代碼中實(shí)現回調

Designer 中對Button 控件啟用ClickListener Mixin 后,下一步是在這個(gè)Button 所在的Screen 的頭文件中添加控件的Click 的回調和其回調處理函數的聲明。

回調函數的聲明應包含以下三點(diǎn)內容:要綁定的類(lèi)名,此例中為Screen1View;回調來(lái)自哪個(gè)Widget,此處為Button;以及發(fā)生事件的類(lèi)型ClickEvent。

Screen1View.hpp

class Screen1View : public Screen1ViewBase

{

public:

Screen1View();

virtual ~Screen1View() {} 

virtual void setupScreen(); 

virtual void tearDownScreen(); 

void ButtonClickHandler(const Button& b, const ClickEvent& e); 

protected: 

Callback<Screen1View, const Button&, const ClickEvent&> buttonClickedCallback; 

};

然后,將回調函數的聲明和回調函數的處理函數綁定到視圖對象。

1699856765753628.png

下一步是通過(guò)setClickAction()的方法告訴Button1這個(gè)Widget,當它被按下時(shí),去調用哪個(gè)回調函數。

1699856810836730.png

最后,實(shí)現回調函數的處理函數,同時(shí)可以根據需要自行增加按鈕按下和釋放時(shí)的處理。

1699856851688229.png

(3)添加handleTickEvent()聲明和定義,用于處理計時(shí)相關(guān)邏輯,此函數以60Hz的頻率被引擎調用。

1699856886220882.png

1699856909590616.png

1699856929549479.png

(4)根據實(shí)際應用需求實(shí)現長(cháng)按鍵的處理

在我們的測試例程中,實(shí)現了三秒長(cháng)按鍵后,切換Text文本顯示的功能,如下。

圖2. 長(cháng)按前效果

1699856970428313.png


圖3. 長(cháng)按3S后效果

1699856999839906.png


3. 總結

本文解釋了如何通過(guò)ClickListener實(shí)現對按鈕控件自定義功能,實(shí)際應用中大多數的Widgets以及View本身都可以通過(guò)ClickListener實(shí)現點(diǎn)擊和釋放時(shí)的自定義處理。




關(guān)鍵詞: TouchGFX Botton ST

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>