- UID
- 8835
- 麦力
- 1184
- 注册时间
- 2017-8-5
- 最后登录
- 2018-10-6
- 精华
- 0
- 阅读权限
- 30
- 在线时间
- 26 小时
|
6#
楼主 |
发表于 2018-9-1 11:50:36
|
只看该作者
本帖最后由 XZY 于 2018-9-1 11:51 编辑
感谢qs100371,终于实现了动态彩色文本的显示了代码如下
反复调用请将返回值即layer_id代入- //create_txt_layer_replace()
- //pwin为窗体指针
- //文本图层ID:old_lyid等于-1则创建文本图层,等于旧的ID则替换,返回新的ID
- //txt为字符串
- //font_type为字体:英文U_ASCII_ARIAL_16 U_ASCII_ARIALBD_16 U_ASCII_ARIAL_20 U_ASCII_ARIALBD_20 U_ASCII_ARIAL_24 U_ASCII_ARIALBD_24 U_ASCII_ARIAL_30 U_ASCII_ARIALBD_30 U_ASCII_ARIAL_42 U_ASCII_ARIALBD_42 汉字( U_GBK_SIMSUN_16 U_GBK_SIMSUNBD_16 U_GBK_SIMSUN_20 U_GBK_SIMSUNBD_20 )
- //x,y,h,w为显示坐标与宽高
- //frcolor为字体前景色//bkcolor为字体背景色 GColorBlack , GColorRed , GColorGreen , GColorBlue , //GColorYellow, GColorPurple, GColorCyan , GColorWhite //白色
- //align为对齐方式 GAlignCenter, GAlignTopLeft, GAlignTopRight , GAlignTop , GAlignLeft, GAlignBottom, GAlignRight, GAlignBottomRight, GAlignBottomLeft
- //eg: int8_t lyid_weekday=-1; lyid_weekday=create_txt_layer_replace(p_win,lyid_weekday, txt_buf,U_ASCII_ARIALBD_20,0, 17, 20, 176,GColorCyan,GColorBlack,GAlignTopLeft);
- static int8_t create_txt_layer_replace(Window *pwin, int8_t old_lyid,char *txt,uint8_t font_type,int16_t x,int16_t y,uint8_t h,uint8_t w,enum GColor frcolor,enum GColor bkcolor,enum GAlign align)//return layer id
- {
- GRect frame_hm;
- fillGRect( &frame_hm,x,y,h,w );
- LayerText alt_hm =
- {
- .text=(const char*) txt,
- .frame= frame_hm,
- .alignment=align,
- .foregroundColor=frcolor,//MAIA彩色表多了这个元素,之前的排列方式初始化方式会错误初始化
- .font_type=font_type,
- .bound_width= 0
- };
- P_Layer p_layer_new = app_layer_create_text(&alt_hm);
- int8_t id=-1;
- if(p_layer_new != NULL)
- {
- app_layer_set_bg_color(p_layer_new, bkcolor);
- if(old_lyid!=-1)
- {
- P_Layer p_layer_old=app_window_get_layer_by_id(pwin, old_lyid); //lyer id为0是合法值
- if(p_layer_old!=NULL)
- {
- id= app_window_replace_layer(pwin,p_layer_old, p_layer_new);//替换图层
- }
- }
- if(id==-1)
- {
- id = app_window_add_layer(pwin, p_layer_new);
- }
- }
- return id;
- }
复制代码
|
|