awtk开发实践——学习篇13:combo_box示例一(下拉列表控件)

说明
  本文章旨在总结备份、方便以后查询,由于是个人总结,如有不对,欢迎指正;另外,内容大部分来自网络、书籍、和各类手册,如若侵权请告知,马上删帖致歉。
  QQ 群 号:513683159 【相互学习】
内容来源
  官方的手册(免费获取)Pxx=该手册的对应页码xx
  github-awtk

控件说明

  关于 combo_box控件(下拉列表控件) 介绍,对应书 P113。(书中还有更详细内容).
  ①功能:点击右边的按钮,可弹出一个下拉列表,从中选择一项作为当前的值。
  ②combo_box_tedit_t的子类控件,edit_t 的函数均适用于combo_box_t控件。
  ③若需使用带滚动条的下拉列表控件请用combo_box_ex_t,该控件的用法、函数、属性等都与combo_box_t一样。
  注意:使用该控件的时候需要将 awtk\demos\assets\default\raw\images\x1目录下:arrow_down_*.png共3 张图片复制到自己的应用目录下(如:res\assets\default\raw\images\xx),否则将不能正常显示。

工程修改

  ①基于awtk开发实践——学习篇7:创建简单工程(方式二:基于HelloWorld.Xml-Demo工程)
  ②上篇已添加了图片资源。arrow_down_*.png共3 张图片
  ③将 awtk_c_demo 工程中styles文件夹下:color.xmlui文件夹color.xml.复制到将 awtk_simplest 工程对应文件夹下。

combo_box.c

#include "awtk.h"

static widget_t* custom_open_popup(widget_t* combo_box) {
  return window_open("color");						//从资源文件中加载并创建window_base对象。
  //打开coLor.xmlui文件
}

ret_t application_init() {
  widget_t* win = window_create(NULL, 0, 0, 0, 0);			//创建window对象
  widget_t* combo_box1 = combo_box_create(win, 0, 0, 0, 0);	//创建combo_box对象
  widget_t* combo_box2 = combo_box_create(win, 0, 0, 0, 0);	//创建combo_box对象

  combo_box_set_options(combo_box1, "left;center;right;");	//设置三个选项:left,center,right(0,1,2)
  combo_box_set_selected_index(combo_box1, 1);				//设置第1个选项为当前选中的选项。
  widget_set_self_layout_params(combo_box1, "center", "middle:-30", "50%", "30");//设置控件自己的布局(缺省布局器)参数(过时,请用widget_set_self_layout)。

  combo_box_set_custom_open_popup(combo_box2, custom_open_popup, NULL);	//设置自定义的打开弹出窗口的函数。
  widget_set_self_layout_params(combo_box2, "center", "middle:30", "50%", "30");//设置控件自己的布局(缺省布局器)参数(过时,请用widget_set_self_layout)。

  widget_layout(win);										//布局当前控件及子控件
  return RET_OK;
}

styles下的color.xml

<popup theme="color" close_when_click_outside="true" h="128" >
  <list_view x="0"  y="0" w="100%" h="100%" item_height="30">
    <scroll_view name="view" x="0"  y="0" w="-12" h="100%">
      <combo_box_item tr_text="red"/>
      <combo_box_item tr_text="green" />
      <combo_box_item tr_text="blue" />
      <combo_box_item tr_text="orange" />
      <combo_box_item tr_text="gold" />
      <combo_box_item tr_text="black" />
      <combo_box_item tr_text="white" />
    </scroll_view>
    <scroll_bar_d name="bar" x="right" y="0" w="12" h="100%" value="0"/>
  </list_view>
</popup>

styles下的color.xml

<combo_box_item>
  <style name="default" icon_at="left" text_color="black" bg_color="#f0f0f0" icon="empty">
    <normal  icon="empty"/>
    <pressed icon="empty" bg_color="#1296db" text_color="white" />
    <over    icon="empty" bg_color="#1296db" text_color="white" />
    <normal  icon="check"/>
    <pressed icon="check" bg_color="#1296db" text_color="white" />
    <over    icon="check" bg_color="#1296db" text_color="white" />
  </style>
</combo_box_item>

执行过程:

  1.生成资源:sh assets_gen.sh,添加新资源故需重新生成资源。【因为此处并不使用.data文件,故可省略】
  2.编译:scons
  3.执行:./bin/demo

实现效果:

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值