Skip to main content
Associate
January 6, 2025
Question

Update a wildcard in a custom container called in a scroll wheel

  • January 6, 2025
  • 4 replies
  • 1817 views

In my main screen there is a scroll wheel which scrolls the contents of a custom container. The custom container has 5 wildcards. Now I intend to dynamically update those wildcards with my text resources. But I'm unable to do so. Please find my codes attached.

 

Screen1View.cpp

 

#include <gui/screen1_screen/Screen1View.hpp>
#include <texts/TextKeysAndLanguages.hpp>



void TextUpdate::updateText()
{
	Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", touchgfx::TypedText(T_NAT_EVE1).getText());
	 textArea1.setWildcard(textArea1Buffer);
	 textArea1.setTypedText(touchgfx::TypedText(T_NAT_EVE1));
	 add(textArea1);
}

// Screen1View constructor
Screen1View::Screen1View()
 : tickCounter(0), targetItem(0), scrollCompleted(false),
 digitalHours(0), digitalMinutes(0), digitalSeconds(0),
 textUpdateIntervalCounter(0), textUpdateObj() // Initialize textUpdateObj
{
}

void Screen1View::setupScreen()
{
 Screen1ViewBase::setupScreen();

 tickCounter = 0; // Reset the tick counter
 textUpdateIntervalCounter = 0; // Reset the interval counter
 targetItem = scrollWheel1.getSelectedItem(); // Initialize target item
 scrollCompleted = false; // Reset scroll completion flag
 digitalHours = digitalClock1.getCurrentHour();
 digitalMinutes = digitalClock1.getCurrentMinute();
 digitalSeconds = digitalClock1.getCurrentSecond();
}

void Screen1View::tearDownScreen()
{
 Screen1ViewBase::tearDownScreen();
}

void Screen1View::handleTickEvent()
{
 tickCounter++;
 textUpdateIntervalCounter++;

 // Scroll logic: Execute every 0.5 seconds (30 ticks at 60 Hz)
 if (tickCounter % ticksPerStep == 0)
 {
 if (!scrollWheel1.isAnimating() && !scrollCompleted)
 {
 targetItem = (targetItem + 1) % scrollWheel1.getNumberOfItems();
 scrollWheel1.animateToItem(targetItem, 500); // Smooth animation (500ms)
 scrollCompleted = true;
 }
 else if (!scrollWheel1.isAnimating() && scrollCompleted)
 {
 scrollCompleted = false; // Reset flag when animation finishes
 }
 }

 // Clock update logic: Execute every second
 if (tickCounter % 60 == 0)
 {
 	textUpdateObj.updateText();
 if (++digitalSeconds >= 60)
 {
 digitalSeconds = 0;
 if (++digitalMinutes >= 60)
 {
 digitalMinutes = 0;
 if (++digitalHours >= 24)
 {
 digitalHours = 0;
 }
 }
 }

 digitalClock1.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
 }

 // Text update logic: Execute every 2 seconds (120 ticks at 60 Hz)
 if (textUpdateIntervalCounter >= 120)
 {
 	 textUpdateObj.updateText(); // Update text dynamically
 	 textUpdateIntervalCounter = 0;
 }
}

void Screen1View::resetScroll()
{
 tickCounter = 0; // Reset tick counter
 scrollCompleted = false; // Allow scrolling again
}

 

 

 

 Screen1View.hpp

 

#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP

#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <gui_generated/containers/CustomContainer1Base.hpp>

class TextUpdate : public CustomContainer1Base
{
public:
 // TextUpdate();
 //virtual ~TextUpdate(){}
 virtual void updateText();
};

class Screen1View : public Screen1ViewBase
{
public:
 Screen1View();
 virtual ~Screen1View() {}

 virtual void setupScreen();
 virtual void tearDownScreen();
 virtual void handleTickEvent();

 void resetScroll(); // Method to reset the scroll state

protected:
 int tickCounter; // Counter to track ticks
 int targetItem; // The target index for the scroll wheel
 bool scrollCompleted; // Flag to ensure the scroll happens only once
 static constexpr int ticksPerStep = 30; // Number of ticks for a 0.5-second delay (assuming 60 Hz)
 int digitalHours;
 int digitalMinutes;
 int digitalSeconds;

 int textUpdateIntervalCounter; // Counter for updating text every 2 seconds
 TextUpdate textUpdateObj; // Object for TextUpdate
};

#endif // SCREEN1VIEW_HPP

 

 

 

I intend to print only in the first wildcard for the time being.

4 replies

MM..1
Chief III
January 6, 2025
add(textArea1);

This update text on other paralel universum... try

textArea1.invalidate();

 

Roombr_VIAuthor
Associate
January 6, 2025

I did try,

textArea1.invalidate();

But it still does not update any wildcards

MM..1
Chief III
January 6, 2025
void TextUpdate::updateText()
{
	Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", touchgfx::TypedText(T_NAT_EVE1).getText());
	 textArea1.setWildcard(textArea1Buffer);
	 textArea1.setTypedText(touchgfx::TypedText(T_NAT_EVE1));

you update nothink then you nothink change see...

Roombr_VIAuthor
Associate
January 6, 2025

I have tried both these variations

void TextUpdate::updateText()
{
	Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", touchgfx::TypedText(T_NAT_EVE1).getText());
	 textArea1.setWildcard(textArea1Buffer);
	 textArea1.setTypedText(touchgfx::TypedText(T_NAT_EVE1));
	 add(textArea1);
	 textArea1.invalidate();
}

and 

void TextUpdate::updateText()
{
	Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", touchgfx::TypedText(T_NAT_EVE1).getText());
	 textArea1.setWildcard(textArea1Buffer);
	 textArea1.setTypedText(touchgfx::TypedText(T_NAT_EVE1));
	 textArea1.invalidate();
}
MM..1
Chief III
January 6, 2025

Have you basic C++ knowledge?? Your try work with containers is complete wrong.

ferro
Lead
January 6, 2025

Hi @Roombr_VI 

Please share an example project with the code in your question.

GaetanGodart
Technical Moderator
January 6, 2025

Hello @Roombr_VI ,

 

Sharing your whole project (as a 7z file) would help us understand what you want to achieve.

The scrollWhell uses callbacks to update its elements (the custom containers that are inside the scrollWheel).
There are 2 native callbacks :

You read the API documentation for the scrollWheel here .

Also, to setup these callbacks, I invite you to watch this video  (on 75% or 50% speed maybe).

 

Regards,

Roombr_VIAuthor
Associate
January 7, 2025

Please find the compressed file below. I'm trying to update the wildcard in the scroll wheel with the text resources. I'm quite new to C++ so I may have made a few errors. 

ferro
Lead
January 7, 2025

"I'm quite new to C++ so I may have made a few errors. "

The code does not build. Please fix it.

\Digital_scroll\TouchGFX\gui\src\screen1_screen\Screen1View.cpp(9,55): error C2039: 'scrollWheel11AnimateToHandler': is not a member of 'Screen1View