Skip to main content
mehmet06
Associate
August 6, 2025
Solved

How does Clicklistener work?

  • August 6, 2025
  • 2 replies
  • 504 views

Hello

I'm an amateur Touchgfx user.
I've completed many challenging tasks with Touchgfx, but I need a very simple one.
I want to set the output port high for the duration of a keystroke.

I used the ClickListener instructions in the program, but they didn't work.
I tried creating Box1 the same way and it works perfectly.
With this code, it works while I hold the button down, and stops when I release it, just as I wanted.

void BRHZLView::boxClickHandler( const Box& b, const ClickEvent& evt)
{

if (evt.getType() == ClickEvent::PRESSED) {
HAL_GPIO_WritePin(GPIOG, BZR_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, PST_I_Pin, GPIO_PIN_SET);

} else if(evt.getType() == ClickEvent::RELEASED){

HAL_GPIO_WritePin(GPIOG, BZR_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, PST_I_Pin, GPIO_PIN_RESET);

}

But the flexbutton group keeps giving definition errors, and the program won't compile.
I'm using Stm32h7b3i Evk, and the definitions in the base file don't match the definitions at https://support.touchgfx.com/docs/development/ui-development/touchgfx-engine-features/mixins.

The program gives an error.
Could you please provide a link to a sample program?

 

_Base.hpp

/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#ifndef BRHZLVIEWBASE_HPP
#define BRHZLVIEWBASE_HPP

#include <gui/common/FrontendApplication.hpp>
#include <mvp/View.hpp>
#include <gui/brhzl_screen/BRHZLPresenter.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/widgets/Image.hpp>
#include <touchgfx/widgets/BoxWithBorder.hpp>
#include <touchgfx/containers/buttons/Buttons.hpp>
#include <touchgfx/widgets/TextArea.hpp>
#include <touchgfx/mixins/ClickListener.hpp>
#include <touchgfx/widgets/TextAreaWithWildcard.hpp>

class BRHZLViewBase : public touchgfx::View<BRHZLPresenter>
{
public:
 BRHZLViewBase();
 virtual ~BRHZLViewBase();
 virtual void setupScreen();

 /*
 * Virtual Action Handlers
 */
 virtual void P_Gde()
 {
 // Override and implement this function in BRHZL
 }
 virtual void P_ILR()
 {
 // Override and implement this function in BRHZL
 }
 virtual void P_GRI()
 {
 // Override and implement this function in BRHZL
 }

protected:
 FrontendApplication& application() {
 return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
 }

 /*
 * Member Declarations
 */
 touchgfx::Box __background;
 touchgfx::Image image1;
 touchgfx::BoxWithBorder boxWithBorder1;
 touchgfx::ImageButtonStyle< touchgfx::TouchButtonTrigger > bck2;
 touchgfx::TextArea textArea1;
 touchgfx::TextArea textArea2;
 touchgfx::Image image2;
 touchgfx::ClickListener< touchgfx::TextButtonStyle< touchgfx::ImageButtonStyle< touchgfx::TouchButtonTrigger > > > P_ileri;
 touchgfx::ClickListener< touchgfx::TextButtonStyle< touchgfx::ImageButtonStyle< touchgfx::TouchButtonTrigger > > > P_geri;
 touchgfx::ClickListener< touchgfx::Box > box1;
 touchgfx::TextArea pgmi;
 touchgfx::ImageButtonStyle< touchgfx::ToggleButtonTrigger > pg_ok;
 touchgfx::TextAreaWithOneWildcard hrkt_bar;
 touchgfx::TextButtonStyle< touchgfx::ImageButtonStyle< touchgfx::TouchButtonTrigger > > ileri2;
 touchgfx::ClickListener< touchgfx::TextButtonStyle< touchgfx::BoxWithBorderButtonStyle< touchgfx::ClickButtonTrigger > > > button1;

 /*
 * Wildcard Buffers
 */
 static const uint16_t HRKT_BAR_SIZE = 10;
 touchgfx::Unicode::UnicodeChar hrkt_barBuffer[HRKT_BAR_SIZE];

private:

 /*
 * Callback Declarations
 */
 touchgfx::Callback<BRHZLViewBase, const touchgfx::AbstractButtonContainer&> flexButtonCallback;

 /*
 * Callback Handler Declarations
 */
 void flexButtonCallbackHandler(const touchgfx::AbstractButtonContainer& src);

};

#endif // BRHZLVIEWBASE_HPP

 

Best answer by mehmet06
mehmet06_0-1754516473286.jpeg

 

 
MM..1
Chief III
 
 

‎2020-12-09 7:03 AM

??? Place Button with Label and do methods

------------------------------------ bu cevap çok işime yaradı , bilginiz olsun !!! --------------------------------------

Now it works great.
void BRHZLView::buttonClickHandler(const ButtonWithLabel& b, const ClickEvent& evt)
{

if(&b ==&PSTI){

if (evt.getType() == ClickEvent::PRESSED) {

HAL_GPIO_WritePin(GPIOG, BZR_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, PST_I_Pin, GPIO_PIN_SET);

} else if(evt.getType() == ClickEvent::RELEASED){

HAL_GPIO_WritePin(GPIOG, BZR_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, PST_I_Pin, GPIO_PIN_RESET);

}
}

2 replies

mehmet06
mehmet06Author
Associate
August 6, 2025
#ifndef BRHZLVIEW_HPP
#define BRHZLVIEW_HPP
#include <gui_generated/brhzl_screen/BRHZLViewBase.hpp>
#include <gui/brhzl_screen/BRHZLPresenter.hpp>

class BRHZLView : public BRHZLViewBase
{
public:
 BRHZLView();
 virtual ~BRHZLView() {}
 virtual void setupScreen();
 virtual void tearDownScreen();
 virtual void P_Gde();
 // virtual void P_ILR();
 // virtual void P_GRI();

 virtual void HIZALA(uint8_t PILERI,uint8_t PGERI,uint8_t PSTOP);

 virtual void handleTickEvent();
 //void boxClickHandler(const Box& b, const ClickEvent& evt);
 void ButtonCallbackHandler(const TouchButtonTrigger& b , const ClickEvent& evt);

protected:
 
 // Callback<BRHZLView, const Box&, const ClickEvent&> boxClickedCallback;

 Callback<BRHZLView, const TouchButtonTrigger& , const ClickEvent&> ButtonCallback;
};

#endif // BRHZLVIEW_HPP
Osman SOYKURT
Technical Moderator
August 6, 2025

Hello @mehmet06 ,

Interaction with a widget can be performed using the ClickListener, as you have done with a Box widget, by obtaining the event type. The Button and FlexButton widgets are designed to react only to click events; therefore, I do not recommend using them in the same way as a Box.

Alternatively, you can override the handleClickEvent method in your ScreenView to detect the position of the click and compare it with the coordinates of your FlexButton.

Osman SOYKURTST Software Developer | TouchGFX
mehmet06
mehmet06AuthorBest answer
Associate
August 6, 2025
mehmet06_0-1754516473286.jpeg

 

 
MM..1
Chief III
 
 

‎2020-12-09 7:03 AM

??? Place Button with Label and do methods

------------------------------------ bu cevap çok işime yaradı , bilginiz olsun !!! --------------------------------------

Now it works great.
void BRHZLView::buttonClickHandler(const ButtonWithLabel& b, const ClickEvent& evt)
{

if(&b ==&PSTI){

if (evt.getType() == ClickEvent::PRESSED) {

HAL_GPIO_WritePin(GPIOG, BZR_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, PST_I_Pin, GPIO_PIN_SET);

} else if(evt.getType() == ClickEvent::RELEASED){

HAL_GPIO_WritePin(GPIOG, BZR_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, PST_I_Pin, GPIO_PIN_RESET);

}
}

mehmet06
mehmet06Author
Associate
August 6, 2025
#include <gui/brhzl_screen/BRHZLView.hpp>
#include "main.h"


uint8_t pgde=0,PILERI=0,PGERI=0,PSTOP=0;


// BRHZLView::BRHZLView(): boxClickedCallback(this, &BRHZLView::boxClickHandler) { }

// BRHZLView::BRHZLView(): flexButtonCallback(this, &BRHZLView::flexButtonCallbackHandler) { }
BRHZLView::BRHZLView():ButtonCallback(this,&BRHZLView::ButtonCallbackHandler)
{

}

void BRHZLView::setupScreen()
{
 BRHZLViewBase::setupScreen();

 P_ileri.setAction(ButtonCallback);
 //box1.setClickAction(boxClickedCallback);
}

void BRHZLView::tearDownScreen()
{
 BRHZLViewBase::tearDownScreen();

}

 void BRHZLView::handleTickEvent()
{

}

 

void BRHZLView::setupScreen()

{

BRHZLViewBase::setupScreen();

 

P_ileri.setAction(ButtonCallback); // <<-- Now it only gives an error here

//box1.setClickAction(boxClickedCallback);

}

error mesage : 

C:/Users/Mehmet/Desktop/H7B-EV/POLYWELD/TouchGFX/gui/src/brhzl_screen/BRHZLView.cpp:20:23: error: cannot convert 'touchgfx::Callback<BRHZLView, const touchgfx::TouchButtonTrigger&, const touchgfx::ClickEvent&>' to 'touchgfx::GenericCallback<const touchgfx::AbstractButtonContainer&>&'

20 | P_ileri.setAction(ButtonCallback);

| ^~~~~~~~~~~~~~

| |

| touchgfx::Callback<BRHZLView, const touchgfx::TouchButtonTrigger&, const touchgfx::ClickEvent&>