2019-07-22 12:08 AM
hello, i have an issue on update a vaiable textArea on a Modal Window (pop up..), the background images is ok but the text field stays empty after text buffer update & invalidate..
the "funny" thing is that the .getTextWidth() on the widget returns 0 after update so it looks like it does not render the string..
i'm wondering if i put the right typography attached correctly, where i've put all the needed "wildcard" ranges, 0-9,a-z, special characters and fallback.
i suppose i do not understand/maste exactly the variable text machinery on the background, really..
anway here some snippets on the gory details. provided that "TypedText()" are rendered ok..
init on object istantiation:
textCnt.setXY(10, 10);
textCnt.setColor(touchgfx::Color::getColorFrom24BitRGB(200, 0, 0));
textCnt.setLinespacing(0);
//touchgfx::Unicode::snprintf(textCntBuffer, TEXT_SIZE, "%s", touchgfx::TypedText(T_SINGLEUSEID11).getText());
textCnt.setWildcard(textCntBuffer);
textCnt.resizeToCurrentText();
add(textCnt);
and then on the "update callback" fn, i just update:
touchgfx::Unicode::snprintf(textCntBuffer, TEXT_SIZE, "%d", value );
textCnt.invalidate();
textCnt.resizeToCurrentText();
int tSize = textCnt.getTextWidth(); // for check and debug..
textCnt.setPosition( (background.getWidth() - textCnt.getTextWidth())/2, (background.getHeight() - textCnt.getTextHeight())/2,
textCnt.getTextWidth(), textCnt.getTextHeight() );
any hint or lead to futher debug/understand what's going on?
bye
Andrea
Solved! Go to Solution.
2019-07-22 01:16 AM
Hi @Community member,
You are missing the function "setTypedText" during the setup code of the wildcard text widget. It is needed to specify where to place the dynamic text in string.
I have added this to your code snippet:
textCnt.setXY(10, 10);
textCnt.setColor(touchgfx::Color::getColorFrom24BitRGB(200, 0, 0));
textCnt.setLinespacing(0);
//touchgfx::Unicode::snprintf(textCntBuffer, TEXT_SIZE, "%s", touchgfx::TypedText(T_SINGLEUSEID11).getText());
textCnt.setWildcard(textCntBuffer);
textCnt.resizeToCurrentText();
textCnt.setTypedText(TypedText(T_SINGLEUSEID1)); //Sets the text and wildcard area
add(textCnt);
Also please have a look at our guide on using text and fonts:
https://touchgfx.zendesk.com/hc/en-us/articles/207015345-Using-texts-and-fonts
/Anders
2019-07-22 12:31 AM
umh sorry,
let me correct a bit my error report.
it's not really the line4 that works in code snippet #1 but this one:
textCnt.setTypedText(touchgfx::TypedText(T_SINGLEUSEID11)); // work
i suppose it goes a different path down in the stack..
my "feeling" is that dynamic font renderer is not working correctly on:
touchgfx::Unicode::snprintf(textCntBuffer, TEXT_SIZE, "%d", value );
but i would expect the "????" as sometime i've seen when i forget the right "wildcard chars" in the "typhography tab" in the Designer app.
i feel then that's related to the programmatic definition of a "modal window" (missing some binding?) because the the "wildcard" text area on the designer screen are working ok. i tried to look the example and code snippet here on the net, but they are a bit "sparse"
2019-07-22 01:16 AM
Hi @Community member,
You are missing the function "setTypedText" during the setup code of the wildcard text widget. It is needed to specify where to place the dynamic text in string.
I have added this to your code snippet:
textCnt.setXY(10, 10);
textCnt.setColor(touchgfx::Color::getColorFrom24BitRGB(200, 0, 0));
textCnt.setLinespacing(0);
//touchgfx::Unicode::snprintf(textCntBuffer, TEXT_SIZE, "%s", touchgfx::TypedText(T_SINGLEUSEID11).getText());
textCnt.setWildcard(textCntBuffer);
textCnt.resizeToCurrentText();
textCnt.setTypedText(TypedText(T_SINGLEUSEID1)); //Sets the text and wildcard area
add(textCnt);
Also please have a look at our guide on using text and fonts:
https://touchgfx.zendesk.com/hc/en-us/articles/207015345-Using-texts-and-fonts
/Anders
2019-07-22 05:50 AM
hi Anders, thanx for the quick reply.. indeed your help has been valuable and i solved my issue and now i understand a bit more (i hope) how dynamic font rendering works.
to improve the quality of the thread, let me explain a bit more what's needed, because i think your reply was giving some thinks for granted.
in the "programmed" TextAreaWithOneWildcard, i had to setTypedText() with the TypedText(T_SINGLEUSEIDxx) from another one of the same generated by the Designer and with the expected "string placement"; in my case a simple TypedText with <value> was enough..
now i understand that's the "trickery" used by the method called through the invalidate() step, to replace in the right "mix" of static and dynamic text..
my (potential) issue now, is for how long i can trust the TypedText(T_SINGLEUSEID90) i used and works for me now, is valid and sticky to the same Designer widget, in the future "iteration" of the Designer process.. if the index are renumbered differently, the text would not match anymore for the "magic"!
i'm wondering if i can create programmatically a "TypedText" entry with the "<xx>" magic.. i'd not like to lookup all the available TypedText[] with .getText() to find out which one has the "wildcard <>"..
in my opinion this should be explained a bit better in the link you pointed me to, at the paragraph "Displaying texts in an application"..
anyway the trick works and now i think i'll not easily forget the process behind! :)
thanx again for the quick reply
Andrea
2019-07-22 11:53 PM
Hi @Community member,
Glad it worked!
You can never trust the system! - ah OK, joking aside :)
In the Designer, in you go to the Text tab, you will be able to convert text entries which are "single use" to "resources"
For a "resource" text you may choose the variable name for that text resource, also a resource text can be used by multiple text widgets.
Screen dump of Texts -> Singe Use
Screen dump of Texts -> Resources
Looking at the generated code, we see that the resource text now has the ID I have chosen.
generated/texts/include/texts/TextKeysAndLanguages.hpp
/* DO NOT EDIT THIS FILE */
/* This file is autogenerated by the text-database code generator */
#ifndef TEXT_KEYS_AND_LANGUAGES_HPP
#define TEXT_KEYS_AND_LANGUAGES_HPP
...
typedef enum
{
T_MYRESOURCEID,
T_SINGLEUSEID1,
NUMBER_OF_TEXT_KEYS
} TEXTS;
#endif /* TEXT_KEYS_AND_LANGUAGES_HPP */
/Anders