cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically set flex button wildcard alignment

jchernus-fikst
Associate III

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: 

jchernusfikst_0-1744837871084.png

After:

jchernusfikst_1-1744837953800.png

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

15 REPLIES 15
MM..1
Chief III

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

@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.

"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.

ferro_0-1744990327854.png

 

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()
);

 

So, what you need to do is this

Unicode::snprintf
(
	flexButton1Buffer,
	FLEXBUTTON1_SIZE,
	"%s",
	ThingANames[static_cast<int>(parameters.thingA)].getText()
);
ferro
Lead

Improved example showing the difference between

	Unicode::snprintf
	(
		flexButtonPreserveAlignBuffer  ,
		FLEXBUTTONPRESERVEALIGN_SIZE   ,
		"%s"                           ,
		TypedText ( circular_next_ttid () ).getText()
	);

and

	flexButtonChangeAlign.setWildcardText ( TypedText ( circular_next_ttid () ) );

 

ferro_0-1744991864290.png