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
jchernus-fikst
Associate III

My button settings, should they be helpful in debugging:

jchernusfikst_1-1744840653032.png

 

ferro
Lead

Hi @jchernus-fikst 

Not sure how you code works but the alignment is set in Text view, so your TypedTextIds in 'Before' pic have got different alignment from 'After'.

ferro_0-1744874948537.png

And I think this

const touchgfx::TypedText ThingANames[]

should be

const touchgfx::TypedTextId ThingANames[]

I understand now the 'const touchgfx::TypedText ThingANames[]'.

 

Maybe if you could share the example you quote.

ferro
Lead

This example might help

https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/text-area-alignment-change/m-p/694806

 

Maybe this ...

https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/add-function-setalignment-to-set-text-alignment-in-textarea/m-p/765075

... will be available soon. At the moment the alignment is hardcoded - even the structure members are const.

\touchgfx\TypedText.hpp

ferro_0-1744894012759.png

\generated\texts\src\TypedTextDatabase.cpp

ferro_1-1744894075563.png

 

 

 

 

 

jchernus-fikst
Associate III

Thanks, @ferro , I appreciate your help.

Like Bhavya, I sometimes need the alignment left and sometimes centered. Unfortunately, I am using a button and not a TextArea. 

I will do with a left-aligned prototype for now and fix this for the final product once the TouchGFX folks add programmatic alignment - I didn't know this work was slated, thank you for sharing!

Julia

No problem @jchernus-fikst 

"I sometimes need the alignment left and sometimes centered. Unfortunately, I am using a button and not a TextArea."

Do not know what is the diffrence between Button vs TextArea. I'll have a look.

The problem seems to be in the text beeing wrogly aligned right ? Could you not have texts with all 3 alignments and use the correct one ?

I can but it's messy and requires greater overhead to maintain, I'm okay waiting until they release the feature! 

"I am using a button and not a TextArea."

But FlexButton uses TextArea and also provides access to wildcared buffer. So you do not use

buttonSelectThingA.setWildcardText ()

but change content of the TextArea buffer. In the same way as you use TexAreaWildCard widget.

https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_text_area_with_one_wildcard

ferro_0-1744913810656.png

 

ferro
Lead

Hi @jchernus-fikst 

Attached is an example showing how to change Flex Button text.

ferro_0-1744972645499.png

 

The implementaion in
\gui\src\screen1_screen\Screen1View.cpp

void Screen1View
::changeText () // override final
{
    auto circular_next_ttid = []() -> touchgfx::TypedTextId
	{
        static std::array<touchgfx::TypedTextId, 3> ttIds
		{
			T_BTN_FLEX_TEXT_ALIGN_CENTRE ,
			T_BTN_FLEX_TEXT_ALIGN_RIGHT  ,
			T_BTN_FLEX_TEXT_ALIGN_LEFT   
		};
        static std::size_t index = 0;

        int result = ttIds [ index ];
        index = (index + 1) % ttIds.size();
        return result;
    };



	Unicode::snprintf
	(
		flexButton1Buffer,
		FLEXBUTTON1_SIZE,
		"%s",
		TypedText ( circular_next_ttid () ).getText()
	);


	flexButton1.invalidate ();

}