2020-11-20 08:53 AM
Hello!
I am trying to add a button to my application manually through code. I thought it would be quite simple, but for some reason I am having some difficulties.
I have added it my screenView class, and initialised it using bitmapped images from the TouchGFX library.
It displays on screen correctly, but does not respond to any touches. I would expect at this point for the image on screen to change when I press it.
I have added other buttons from the designer, that are responding correctly.
Does anyone have any idea what I am doing wrong? Is there something I am not initialising correctly that links the button to TouchGFX engine?
I'm embarrassed to say that this has stumped me for several hours now!
Thank you.
screenView.hpp:
#ifndef SCREENVIEW_HPP
#define SCREENVIEW_HPP
#include <gui_generated/screen_screen/screenViewBase.hpp>
#include <gui/screen_screen/screenPresenter.hpp>
#include <touchgfx/widgets/Button.hpp>
class screenView : public screenViewBase
{
public:
screenView();
virtual ~screenView() {}
virtual void setupScreen();
virtual void tearDownScreen();
touchgfx::Button Button1;
protected:
private:
};
#endif // SCREENVIEW_HPP
screenView.cpp:
#include <gui/screen_screen/screenView.hpp>
#include <BitmapDatabase.hpp>
screenView::screenView()
{
}
void screenView::setupScreen()
{
screenViewBase::setupScreen();
Button1.setXY(0, 0);
Button1.setBitmaps(touchgfx::Bitmap(BITMAP_ROUND_EDGE_SMALL_ID), touchgfx::Bitmap(BITMAP_ROUND_EDGE_SMALL_PRESSED_ID));
add(Button1);
}
void screenView::tearDownScreen()
{
screenViewBase::tearDownScreen();
}
Solved! Go to Solution.
2020-11-21 07:04 AM
This is what is confusing me. I have copied the code from ViewBase exactly, but the bitmap swap isnt occuring.
2020-11-21 07:25 AM
Hi @OSton.1 . Sorry, I was unable to reproduce your issue. I started a new TouchGFX 1.14.0 project targetting the F469Disco 3.0.0 template, added a box background, a button and a slider. Then I copied your code. I got a compiler error and needed to change the bitmap set line to:
Button1.setBitmaps(touchgfx::Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_ID), touchgfx::Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_PRESSED_ID));
This reflects the bitmaps already generated for the blue button I added in the designer.
With this, in the simulator and on target the button appeared at 0,0 and the bitmap updated as it should when pressed. Perhaps consider uploading your project? Is it possible your touchscreen isn't calibrated, and it's not registering clicks in the area of 0, 0?
Edit: so that future readers don't have to scroll, an uncalibrated touchscreen was indeed the issue.
2020-11-21 07:28 AM
See attached
2020-11-21 07:31 AM
Perhaps it is something to do with with my project/environment. I'll try it with a development board instead.
2020-11-21 08:04 AM
I feel like a fool now!
I had moved the button to (50,50), in case being at the edge was the issue, but it still wouldnt work.
I've just moved it to the middle of screen now and voilà its working!
Thank you for the help!
Need to properly calibarate the touch screen I think.
2020-11-21 09:55 AM
Glad it worked out! Honestly even I thought the touchscreen idea was a bit of a long shot so don't feel that way!