最近在研究touchgfx,太懵了,也就好久没有更新博文了,很坑的一点,我就想在屏幕上显示一个小数,翻看了N多的博文,没一个管用的,这里分享一下我的方案。
选择TextArea控件,enable Wildcard方式
选择动作,我这边选择的是按键触发
编写按键触发的实体函数覆盖虚函数
std::uint8_t temp[20];
touchgfx::Unicode::snprintfFloat(textArea1Buffer, TEXTAREA1_SIZE, "%.2f", 1234.5f);
textArea1.setWildcard(textArea1Buffer);
textArea1.invalidate();
textArea1.resizeToCurrentText();
textArea1.invalidate();
touchgfx::Unicode::toUTF8(textArea1.getWildcard(),temp, 20);
printf("text:%s\r\n", (char *)temp);
值得一提
值得一提的是,touchgfx中对snprintf重定义了,有下面几种函数类型
static UnicodeChar* snprintf(UnicodeChar* dst, uint16_t dstSize, const UnicodeChar* format, ...);
static UnicodeChar* snprintfFloat(UnicodeChar* dst, uint16_t dstSize, const UnicodeChar* format, const float value)
其中 snprintf只支持== %c, %s以及整型数据==
snprintfFloat只支持浮点数