Trouble calling a function with enum parameter

Joined
Jan 13, 2023
Messages
3
Reaction score
0
I cannot get the call right to a function with an enumeration from a library. Not even if I duplicate that enum in my program.

In the library:
enum class Layout {
Horizontal,
Vertical
};

The function prototype from the library code:
uint16_t cdrawString(const char *str,
int32_t x = 0,
int32_t y = 0,
uint16_t fg = 0xFFFF,
uint16_t bg = 0x0000,
Layout layout = Layout::Horizontal);


The call I want to compile:
ofr.cdrawString(myBuildString, 0, 0, TFT_YELLOW, DarkerRed, Horizontal);

It says Horizontal is not defined. Even if I duplicate the enum in my code with a different name (else it says it is already defined so it knows it is there), I cannot get Horizontal defined.

Please help he with this. There is no example, anywhere, of this usage that I can find and I have searched for a while. Thanks for any pointers to make this work.
 
Joined
Jan 13, 2023
Messages
3
Reaction score
0
I cannot get the call right to a function with an enumeration from a library. Not even if I duplicate that enum in my program.

In the library:
enum class Layout {
Horizontal,
Vertical
};

The function prototype from the library code:
uint16_t cdrawString(const char *str,
int32_t x = 0,
int32_t y = 0,
uint16_t fg = 0xFFFF,
uint16_t bg = 0x0000,
Layout layout = Layout::Horizontal);


The call I want to compile:
ofr.cdrawString(myBuildString, 0, 0, TFT_YELLOW, DarkerRed, Horizontal);

It says Horizontal is not defined. Even if I duplicate the enum in my code with a different name (else it says it is already defined so it knows it is there), I cannot get Horizontal defined.

Please help he with this. There is no example, anywhere, of this usage that I can find and I have searched for a while. Thanks for any pointers to make this work.
I got this to work:

Layout lay=Layout::Horizontal;

But, still, the call to cdrawString won't compile no matter what I put in the last parm.
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
I cannot get the call right to a function with an enumeration from a library. Not even if I duplicate that enum in my program.

In the library:
enum class Layout {
Horizontal,
Vertical
};

The function prototype from the library code:
uint16_t cdrawString(const char *str,
int32_t x = 0,
int32_t y = 0,
uint16_t fg = 0xFFFF,
uint16_t bg = 0x0000,
Layout layout = Layout::Horizontal);


The call I want to compile:
ofr.cdrawString(myBuildString, 0, 0, TFT_YELLOW, DarkerRed, Horizontal);

It says Horizontal is not defined. Even if I duplicate the enum in my code with a different name (else it says it is already defined so it knows it is there), I cannot get Horizontal defined.

Please help he with this. There is no example, anywhere, of this usage that I can find and I have searched for a while. Thanks for any pointers to make this work.
It appears that you are attempting to utilize the "cdrawString" function from the library with an input of "Horizontal," which is not being acknowledged by the compiler. To fix this issue, you should specify the enum type from the library when calling the argument, as follows: "ofr.cdrawString(myBuildString, 0, 0, TFT_YELLOW, DarkerRed, Layout::Horizontal)."

Code:
ofr.cdrawString(myBuildString, 0, 0, TFT_YELLOW, DarkerRed, Layout::Horizontal);

Alternatively, you could use a typedef or using statement to bring the enum into the current namespace, like this:

Code:
typedef Layout::Horizontal Horizontal;
ofr.cdrawString(myBuildString, 0, 0, TFT_YELLOW, DarkerRed, Horizontal);
 
Joined
Jan 13, 2023
Messages
3
Reaction score
0
I tried just that and it was rejected. Here is what I finally found that worked in the Arduino IDE environment:

Align myAlign = Align::Left;
myAlign = Align::Left;
Layout myLayout = Layout::Horizontal; // One way to do it
render.setLayout(Layout::Horizontal); // Another way to do it

BBOX = render.calculateBoundingBoxFmt(0, 0, font_size, myAlign, myLayout, txtSample);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,483
Latest member
TedDvb6626

Latest Threads

Top