cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a method that returns the Unicode string of the Typedtext with wildcards applied?

Guit32010
Associate III

Is there a method that returns the Unicode string of both the Typedtext with wildcards applied?

As an example:

ypedtext Resource with wildcard is: "My value: <>"

Wildcard is currently: 1234

the function would return the * unicode char : "My value: 1234".

So far it looks like I'd have to build from scratch with TypedText::getTexts() and any wildcard strings.

5 REPLIES 5
Yoann KLEIN
ST Employee

Hello,

I'm not sure to understand why you want to get this whole string with just one function, can you please tell me what is the user case ?

Actually, I don't think that a method which returns both the TypedText and the wildcard value exists.

But there is a method to get your current wildcard value, "getWildcard()", which returns a UnicodeChar*.

Then, if you want for example to convert this value to an integer, you can use Unicode::atoi(UnicodeChar*).

To get the TypedText, you can of course use the getTypedText() function.

After that, as you said, you could use the TypedText::getText() method to convert this TypedText to UnicodeChar* object, and concatenate this text with your wildcard value.

In any case, I recommend to keep this two parts separated, and maybe use two different TextArea to display them.

Hope that this helped you,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX
Guit32010
Associate III

So the use case is that I am trying to override the set alignments in a stored text resource.

I want to have the same text resource shown centered on one screen but left centered on another screen, without having duplicated resources. Think menu/sub-menu here.

So if a resource: "My Text" is centered, I can override the centered mode by pulling the text from the resource and using it as a wildcard and using an Empty resource with left alignment.

Resource "My Text" Centered

becomes

Empty Left Aligned Resource "<>" + wildcard "My Text".

This is where the above comes in to play. I don't have an easy way to override the alignment if the resource contains a wildcard.

The only other option I can think of is fitting the textbox area to the text and move the box to Left, Right or center depending on the use case. I'm not sure how well this will fit our architecture however. I'm still thinking that one through.

Hello,

Honestly, I think that this is a too complicated way to achieve what you want.

I can only recommend you to implement the second solution you mentioned : create a textbox that will contain what you wanna display, and then you will be able to move this widget wherever you want on the screen using the setX(int) and/or setY(int) methods.

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX
Zwei.9
Associate III

You can change your mind.

[Touchgfx designer]

Add two resources:

LEFT_VALUE_TEXT ,your font,left-align,your direction,<value>;

RIGHT_VALUE_TEXT ,your font,right-align,your direction,<value>.

[Code]

YourClass.hpp
void setTextAlignment(Alignment way);
 
YourClass.cpp
void YourClass::setTextAlignment(Alignment way)
{
	if (way == LEFT)
	{
		Unicode::snprintf(textArea_ItemBuffer TEXTAREA_ITEM_SIZE, "%s", TypedText(T_ITEM_TEXT).getText());
		textArea_Item.setWildcard(textArea_ItemBuffer);
		textArea_Item.setTypedText(TypedText(T_LEFT_VALUE_TEXT));
	}
	else if (way == RIGHT)
	{
		Unicode::snprintf(textArea_ItemBuffer, TEXTAREA_ITEM_SIZE, "%s", TypedText(T_ITEM_TEXT).getText());
		textArea_ItemsetWildcard(textArea_ItemBuffer);
		textArea_Item.setTypedText(TypedText(T_RIGHT_VALUE_TEXT);
	}
	textArea_Item.invalidate();
}

As for your "My value".

You can use "Unicode::ustrcat".

static void ustrcat(Unicode::UnicodeChar* buffer, Unicode::UnicodeChar* str, uint16_t size)
{
	Unicode::snprintf(buffer + Unicode::strlen(buffer), size - Unicode::strlen(buffer), str);
}

Guit32010
Associate III

Thanks for the responses.

Yoann,

I'm curious as why the alignment is contained in the Text Resource and not natively controlled by the text box (Text Area widget)? In other GUI systems I've worked with this was the case (StemWin as an example).