Skip to main content
JHERI
Associate III
September 13, 2023
Solved

FUTURE REQUEST For Touch GFX, please ARRAY! ARRAY! ARRAY!

  • September 13, 2023
  • 5 replies
  • 4834 views

Hello

I'm still very new to Touch GFX

Still finding my way with programming in C++ as I'm more C based,

The biggest drawback I’m finding is the TouchGFX design environment when laying out screens does not allow you to add objects (Widgets) as arrays (multiples of the same).

Why on earth would this not have been implemented ??

This approach allows for much more efficient and logical coding for controlling each widget in for loops etc.
Is there any plan in the future to add this much needed option in the ToughGFX designer when laying out more complex screens of multiple objects / widgets

Thank in advance for any info

This topic has been closed for replies.
Best answer by JHERI

Thank you very much for your reply and code, very much appreciated

could you please explain what this does ? is it using images created from the youch design i.e. gradient led images as Im looking for nice gradient LED images on my screen,

or is the code using flat colours, I don't fully understand what is going on with this code ???

 

is the

 &led1,
 &led2,
 &led3,
 &led4,
 &led5,
 &led6,
 &led7,

refering to images created in the touch gfx designer ?

 

thak you for any advice

5 replies

Senior
September 13, 2023

Have you thought about how much memory this will take?
You can create an array of widgets, but I strongly advise against it.

JHERI
JHERIAuthor
Associate III
September 13, 2023

thanks for your reply

but not the reply I was expecting!

so your saying touch gfx and the high end displays a flawed for more complex designs ?

if you want say 30 red on leds images  and 30 red off leds images on a screen, you then place the 30 red led off images on top of the 30 red on leds images

you then have to initialise each led image separately ??? and control 60 separate widgets ??? just to turn on and off some led images,  

this should all be done in for loops as arrays, but if the hardware screens, arm processors and touch gfx is not up for this type of efficient code practice, it just shows how flawed it all is going down this design route

 

Senior
September 13, 2023

 

This is from me

/// \brief LedsRow
/// \file LedsRow.hpp
/// \version 1 \date 05.11.2022

#pragma once

#include <array>
#include <gui_generated/containers/LedsRowBase.hpp>

class LedsRow : public LedsRowBase
{
public:

 using SColors = Led::SColors;

 /// \brief Leds Row Constructor
 LedsRow ();

 /// \brief Leds Row class destructor
 ~LedsRow () = default;

 /// \brief Initialize Container
 void initialize () override;

 /// \brief Set the Value
 /// \param value
 void setValue (uint16_t value);

 void setParameters (uint8_t start_index, const SColors & colors_on, const SColors & colors_off);

 // auto at (uint32_t index, Led ** led_ptr) -> void;

private:

 SColors _Colors [2];

 std::array<Led *, 12> _Array; ///< Array with pointers

 uint16_t _Value;
};

 

#include <gui/containers/LedsRow.hpp>

LedsRow::LedsRow ()
{
 _Array = {
 &led1,
 &led2,
 &led3,
 &led4,
 &led5,
 &led6,
 &led7,
 &led8,
 &led9,
 &led10,
 &led11,
 &led12,
 };
}

void LedsRow::initialize ()
{
 LedsRowBase::initialize ();
}

void LedsRow::setParameters (uint8_t start_index, const SColors & colors_on, const SColors & colors_off)
{
 _Colors [0] = colors_off;
 _Colors [1] = colors_on;
 for (auto & iter : _Array)
 {
 iter->setNumber (start_index++);
 iter->setColors (colors_off);
 }
}

void LedsRow::setValue (uint16_t value)
{
 if (_Value == value) return;

 for (auto i = 0; i < _Array.size (); i++)
 {
 auto mask = (1 << i);
 _Array [i]->setColors (_Colors [(value & mask) != 0]);

 if (value ^ _Value) _Array [i]->invalidate ();
 }

 _Value = value;
}

Greetings

JHERI
JHERIAuthorBest answer
Associate III
September 13, 2023

Thank you very much for your reply and code, very much appreciated

could you please explain what this does ? is it using images created from the youch design i.e. gradient led images as Im looking for nice gradient LED images on my screen,

or is the code using flat colours, I don't fully understand what is going on with this code ???

 

is the

 &led1,
 &led2,
 &led3,
 &led4,
 &led5,
 &led6,
 &led7,

refering to images created in the touch gfx designer ?

 

thak you for any advice

JHERI
JHERIAuthor
Associate III
September 13, 2023

JHERI_0-1694598772207.png

JHERI_1-1694598791220.png

JHERI_2-1694598810480.png

these are the type of led images I would like to make in to arrays, that are placed in Touch GFX as arrays

 

 

Senior
September 13, 2023

see 
TouchGFX\gui\include\gui\example_screen\ExampleView.hpp

TouchGFX\gui\include\gui\containers\Led.hpp

TouchGFX\gui\src\containers\Led.cpp

 

 
JHERI
JHERIAuthor
Associate III
September 13, 2023

thank you, will try to work through code

 

Regards

 

Senior
September 13, 2023

At first glance, TouchGFX seems quite complicated to work with, but in practice it is not. The team that developed the environment has done a great job.

JHERI
JHERIAuthor
Associate III
September 13, 2023

Hi

yes I have followed a few in depth tutorials on touch gfx regarding sending and returning struct variables from the model to the presenters of each screen and successfully managed to set   gauges and sliders to values leave the screen and jump to another and come back to the gauge screen and it still kept the values previously.

albeit a little bit involved sending values from the screen to the presenter and then from the presenter to the model but worked fine

I'm not to sure about C++ and classes, don't really get it, so this is adding confusion to the mix though trying to break everything down bit by bit

its very different to a normal nucleo 446RE board and peripherals that im use to in C code and cube mx and visualVDB

really need to try and understand the code that the touchgfx designer creates as i guess this does some of the initial hardware initialising and creating functions for the various screens and widgets created in the designer ?

just need to understand classes and how to reference all the widgets and containers & custom containers and child object within each screen layout

but can see by using custom containers it will start to simplify code and widgets, just need to understand how to code the custom containers objects

Piranha
Principal III
September 13, 2023
JHERI
JHERIAuthor
Associate III
September 13, 2023

thanks yes did look at this as another option along with crank and embedded wizard, but last two very very costly