2025-01-30 06:05 AM
Hi, i'm kinda new to TouchGFX and i'm trying to programmatically add text inside a container of mine that i created to use as template in a ScrollList, but I was unsuccessful.
The idea is: For each text added, an item appears in ScrollList WITH the text
I have a textArea in touch designer with wildcard buffer
That's what im trying to do in code. At the moment, the list items appeared, but no text. Most of the code was created by ChatGPT as long as i don't know how to proceed
view.cpp
#include <gui/usb_teste_screen/usb_testeView.hpp>
usb_testeView::usb_testeView() {}
void usb_testeView::setupScreen()
{
usb_testeViewBase::setupScreen();
addItem("Test1");
addItem("Test2");
addItem("Test3");
}
void usb_testeView::tearDownScreen()
{
usb_testeViewBase::tearDownScreen();
}
void usb_testeView::addItem(const char* text)
{
int numItems = scrollList2.getNumberOfItems();
scrollList2.setNumberOfItems(numItems + 1);
scrollList2.invalidate();
}
void usb_testeView::updateItem(UsbContainer& item, int16_t itemIndex)
{
// Convert text to Unicode::UnicodeChar
Unicode::UnicodeChar textBuffer[256];
Unicode::strncpy(textBuffer, "Teste", 256);
textBuffer[256] = '\0';
item.setText(textBuffer);
}
view.hpp
#ifndef USB_TESTE_VIEW_HPP
#define USB_TESTE_VIEW_HPP
#include <gui_generated/usb_teste_screen/usb_testeViewBase.hpp>
#include <gui/usb_teste_screen/usb_testePresenter.hpp>
class usb_testeView : public usb_testeViewBase
{
public:
usb_testeView();
virtual ~usb_testeView() {}
virtual void setupScreen();
virtual void tearDownScreen();
void addItem(const char* text);
void scrollWheel1UpdateItem(UsbContainer& item, int16_t itemIndex);
void updateItem(UsbContainer& item, int16_t itemIndex);
};
#endif // USB_TESTE_VIEW_HPP
container.cpp
#include <gui/containers/UsbContainer.hpp>
#include <string.h>
#include <touchgfx/Unicode.hpp>
UsbContainer::UsbContainer()
{
}
void UsbContainer::setText(const touchgfx::Unicode::UnicodeChar* text)
{
touchgfx::Unicode::strncpy(textArea1Buffer, text, TEXTAREA1_SIZE - 1);
textArea1Buffer[TEXTAREA1_SIZE - 1] = '\0';
textArea1.setWildcard(textArea1Buffer);
textArea1.invalidate();
}
container.hpp
#ifndef USBCONTAINER_HPP
#define USBCONTAINER_HPP
#include <gui_generated/containers/UsbContainerBase.hpp>
#include <touchgfx/Unicode.hpp>
class UsbContainer : public UsbContainerBase
{
public:
UsbContainer();
virtual ~UsbContainer() {}
void setText(const char* text);
void setText(const touchgfx::Unicode::UnicodeChar* text);
};
#endif // USBCONTAINER_HPP
2025-01-30 06:55 AM
Please share GfxDesigner project demonstating what you are trying to achieve.
2025-01-30 07:29 AM
Hi, @ferro
Im trying to add items to my ScrollList via code
for example:
addItemToList("Text 1");
addItemToList("Text 2");
The final result has to be something like this:
That is a ScrollList in the image.
The scrollList template is a container with an icon and a textArea with one wildcard. This is just an example of what i'm trying to achieve. Currently, "text 1" and "text 2" are not showing up.
Hope i made it clear, sorry for any inconvenience!
2025-01-30 07:33 AM
I am not that familiar with ScrollList so cant help without running code sorry.