2020-04-06 06:33 PM
Hi everyone.
I've been trying to create an header file with some default colors for an user interface. Apparently, TouchGFX has a struct called colortype that is used as a type for colors. I created an .hpp file, included touchgfx/Color.hpp and tried to define variables with type "colortype". It doesn't build, I get the compiler message " 'colortype' does not name a type". What would be a proper way of defining some global default colors into a header file to be included into other ui files?
2020-04-07 02:54 AM
Hi,
From my understanding, it is not that straightforward to do so. The best way in my opinion is to declare your colors as follows :
colortype BLUE = Color::getColorFrom24BitRGB(0, 174, 239);
This declaration should be either in your view .hpp file and you will be able to call it in your functions in the .cpp file of this view, or you define them in the Model and create getters to retrieve the colors from any view.
/Alexandre
2020-04-07 03:16 AM
Color::getColorFrom24BitRGB() returns a colortype and .setColor() takes a colortype. You could do something like the following and keep defines in a seperate header file that you include where you need it.
//defines.hpp
#include <touchgfx/Color.hpp>
#define BLUE Color::getColorFrom24BitRGB(0, 0, 255)
//myview.hpp
#include <defines.hpp>
...
box.setColor(BLUE);
2020-04-07 05:21 AM
Thanks for you fast replies. It was enough to solve the issue.
2020-04-07 07:27 AM
Another question on the same topic. Let's say I have a theme. So eventually, I need to change system colors. For that, I need color variables. I could successfully create some #defines as you guys pointed, but when I create a variable with type 'colortype' the compiler returns that same error I told you before. What would be a proper way of declaring my variables and assign my defined colors to it?
I tryed:
// system_colors.hpp
#include <touchgfx/Color.hpp>
#define COLOR_BLUE Color::getColorFrom24BitRGB(0, 130, 240)
colortype syscolor_test = COLOR_BLUE;
2020-04-07 07:41 AM
Hi,
I am not sure why you want to create a colortype here.
COLOR_BLUE already defines a colortype. A way would be to do the same as with the first line :
#define COLOR_BLUE Color::getColorFrom24BitRGB(0, 130, 240)
#define SYSCOLOR COLOR_BLUE
/Alexandre
2020-04-07 07:50 AM
Hi, Alexandre.
I don't want it to be a constant because I need to change it's color value on run time, so it has to be a variable.
2020-04-07 07:58 AM
I understand what you want to do now. Then in this case, I think using the Model to save the color would be the solution I would go for.
Because I do not think that you will be able to declare a colortype in the .hpp file like this as in the end getColorFrom24BitRGB() cannot be called before HAL has been initialized.
static colortype getColorFrom24BitRGB(uint8_t red, uint8_t green, uint8_t blue)
{
assert(HAL::getInstance() && "Cannot set color before HAL is initialized");
return HAL::lcd().getColorFrom24BitRGB(red, green, blue);
}
2020-04-07 10:31 AM
I got it. I'll do that. Thanks!
2021-09-01 06:14 AM
Hi,
any chance to have similar capability (to have some kind of color "define") not only by code but also in the designer ?
e.g. : have a page to put color pre-defined values with a label, to recall then on the widgets color configuration.
It will be very useful for adapt GUI in several applications that changes only for color palette used.
Thanks for reply