touchgfx 浮点数显示

最近在研究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只支持浮点数

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值