2025-04-16 2:18 PM
I have three buttons who's wild card text I change programatically. When I do so, the alignment of the text changes from centre-aligned to left-aligned.
Before:
After:
A) How do I prevent that from happening?
OR
B) How do I change the alignment to centre-aligned programmatically?
This is my code:
// Elsewhere:
typedef struct _Parameters {
ThingA thingA;
ThingB thingB;
ThingC thingC;
} Parameters;
const touchgfx::TypedText ThingANames[] = {
T_TEXTA,
T_TEXTAA,
T_TEXTAAA,
T_TEXTERROR,
T_TEXTNONE
};
// Here
void selectThingsView::setupScreen()
{
selectTubingCustomViewBase::setupScreen();
Parameters parameters = presenter->getParameters();
buttonSelectThingA.setWildcardText(ThingANames[static_cast<int>(parameters.thingA)]);
buttonSelectThingA.invalidate();
}
Thanks,
Julia
2025-04-18 4:02 AM
Seems better is say about TGFX, that positioning system is as of 1980 era based on point 0,0
Perfect will be soon have in designer and library inteligent or AI functions, otherwise ...
Good example is LVGL
2025-04-18 8:19 AM
@ferro I ran your example in the simulator but every time I pressed the button the text was centered - did it behave differently for you? I even tried making the button the width of the screen to ensure I wasn't missing the movement.
2025-04-18 8:33 AM
"I pressed the button the text was centered"
Yes, that is what you wanted right ?
You said: "How do I change the alignment to centre-aligned programmatically?"
The example shows that the text is always centered regardles of the TypedText alignemnt.
2025-04-18 8:38 AM - edited 2025-04-18 8:38 AM
With this code you are changing both text and alignment
buttonSelectThingA.setWildcardText(ThingANames[static_cast<int>(parameters.thingA)]);
Whereas with my code you keep the alignment and change only text
Unicode::snprintf
(
flexButton1Buffer,
FLEXBUTTON1_SIZE,
"%s",
TypedText ( circular_next_ttid () ).getText()
);
2025-04-18 8:40 AM
So, what you need to do is this
Unicode::snprintf
(
flexButton1Buffer,
FLEXBUTTON1_SIZE,
"%s",
ThingANames[static_cast<int>(parameters.thingA)].getText()
);
2025-04-18 9:03 AM