Programmatically set flex button wildcard alignment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
- Labels:
-
TouchGFX
-
TouchGFX Designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-16 2:57 PM
My button settings, should they be helpful in debugging:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-17 12:31 AM - edited ‎2025-04-17 12:41 AM
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'.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-17 5:49 AM - edited ‎2025-04-17 10:24 AM
This example might help
https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/text-area-alignment-change/m-p/694806
Maybe this ...
... will be available soon. At the moment the alignment is hardcoded - even the structure members are const.
\touchgfx\TypedText.hpp
\generated\texts\src\TypedTextDatabase.cpp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-17 9:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-17 10:21 AM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-17 10:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-17 10:34 AM
I can but it's messy and requires greater overhead to maintain, I'm okay waiting until they release the feature!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-17 11:13 AM - edited ‎2025-04-17 11:17 AM
"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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-18 3:34 AM - edited ‎2025-04-18 3:37 AM
Attached is an example showing how to change Flex Button text.
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 ();
}
