Skip to content

Latest commit

 

History

History
316 lines (209 loc) · 8.19 KB

dialog_t.md

File metadata and controls

316 lines (209 loc) · 8.19 KB

dialog_t

概述

image

对话框。

对话框是一种特殊的窗口,大小和位置可以自由设置。 AWTK中的对话框是模态的,也就是说用户不能操作对话框后面的窗口。

对话框通常由对话框标题和对话框客户区两部分组成:

image

dialog_t是window_base_t的子类控件,window_base_t的函数均适用于dialog_t控件。

在xml中使用"dialog"标签创建对话框。如:

<dialog anim_hint="center_scale(duration=300)" x="c" y="m" w="80%" h="160" text="Dialog">
<dialog_title x="0" y="0" w="100%" h="30" text="Hello AWTK" />
<dialog_client x="0" y="bottom" w="100%" h="-30">
  <label name="" x="center" y="middle:-20" w="200" h="30" text="Are you ready?"/>
  <button name="quit" x="10" y="bottom:10" w="40%" h="30" text="确定"/>
  <button name="quit" x="right:10" y="bottom:10" w="40%" h="30" text="取消"/>
</dialog_client>
</dialog>

如果你不需要对话框的标题,可以这样写:

<dialog anim_hint="center_scale(duration=300)" x="c" y="m" w="80%" h="160" text="Dialog">
  <label name="" x="center" y="middle:-20" w="200" h="30" text="Are you ready?"/>
  <button name="quit" x="10" y="bottom:10" w="40%" h="30" text="确定"/>
  <button name="quit" x="right:10" y="bottom:10" w="40%" h="30" text="取消"/>
</dialog>

与窗口不同的是,打开对话框之后,还需要调用dialog_modal。

 widget_t* dlg = dialog_open(name);

 ret = dialog_modal(dlg);

更多用法请参考:dialog.xml

在c代码中使用函数dialog_create创建对话框。如:

  widget_t* ok = NULL;
  widget_t* cancel = NULL;
  widget_t* label = NULL;

  widget_t* dlg = dialog_create_simple(NULL, 0, 0, 240, 160);

  dialog_set_title(dlg, "Dialog");

  ok = button_create(dialog_get_client(dlg), 20, 80, 80, 30);
  widget_set_text(ok, L"Go");

  cancel = button_create(dialog_get_client(dlg), 140, 80, 80, 30);
  widget_set_text(cancel, L"Cancel");

  label = label_create(dialog_get_client(dlg), 10, 30, 200, 30);
  widget_set_text(label, L"AWTK is cool!");

  widget_on(ok, EVT_CLICK, on_dialog_btn_click, (char*)NULL + 1);
  widget_on(cancel, EVT_CLICK, on_dialog_btn_click, (char*)NULL + 2);

  code = dialog_modal(dlg);

  log_debug("code=%d\n", code);

创建之后,再创建子控件,最后调用dialog_modal显示对话框。对话框关闭之后dialog_modal才会返回。

完整示例请参考:dialog demo

可用通过style来设置控件的显示风格,如字体的大小和颜色等等。如:

<style name="default">
  <normal border_color="#606060" />
</style>

更多用法请参考:theme default


函数

函数名称 说明
dialog_cast 转换dialog对象(供脚本语言使用)。
dialog_create 创建dialog对象。
dialog_create_simple 创建dialog对象,同时创建title/client。
dialog_get_client 获取client控件。
dialog_get_title 获取title控件。
dialog_modal 模态显示对话框。
dialog_open 从资源文件中加载并创建Dialog对象。
dialog_quit 退出模态显示,关闭对话框。
dialog_set_title 设置对话框的标题文本。

dialog_cast 函数


  • 函数功能:

转换dialog对象(供脚本语言使用)。

  • 函数原型:
widget_t* dialog_cast (widget_t* widget);
  • 参数说明:
参数 类型 说明
返回值 widget_t* dialog对象。
widget widget_t* dialog对象。

dialog_create 函数


  • 函数功能:

创建dialog对象。

  • 函数原型:
widget_t* dialog_create (widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
  • 参数说明:
参数 类型 说明
返回值 widget_t* dialog对象。
parent widget_t* 父控件
x xy_t x坐标
y xy_t y坐标
w wh_t 宽度
h wh_t 高度

dialog_create_simple 函数


  • 函数功能:

创建dialog对象,同时创建title/client。

  • 函数原型:
widget_t* dialog_create_simple (widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
  • 参数说明:
参数 类型 说明
返回值 widget_t* dialog对象。
parent widget_t* 父控件
x xy_t x坐标
y xy_t y坐标
w wh_t 宽度
h wh_t 高度

dialog_get_client 函数


  • 函数功能:

获取client控件。

  • 函数原型:
widget_t* dialog_get_client (widget_t* widget);
  • 参数说明:
参数 类型 说明
返回值 widget_t* client对象。
widget widget_t* dialog对象。

dialog_get_title 函数


  • 函数功能:

获取title控件。

  • 函数原型:
widget_t* dialog_get_title (widget_t* widget);
  • 参数说明:
参数 类型 说明
返回值 widget_t* title对象。
widget widget_t* dialog对象。

dialog_modal 函数


  • 函数功能:

模态显示对话框。

dialog_modal返回后,dialog对象将在下一个idle函数中回收。 也就是在dialog_modal调用完成后仍然可以访问dialog中控件,直到本次事件结束。

  • 函数原型:
ret_t dialog_modal (widget_t* widget);
  • 参数说明:
参数 类型 说明
返回值 ret_t 返回RET_OK表示成功,否则表示失败。
widget widget_t* dialog对象。

dialog_open 函数


  • 函数功能:

从资源文件中加载并创建Dialog对象。

本函数在ui_loader/ui_builder_default里实现。

  • 函数原型:
widget_t* dialog_open (const char* name);
  • 参数说明:
参数 类型 说明
返回值 widget_t* 对象。
name const char* dialog的名称。

dialog_quit 函数


  • 函数功能:

退出模态显示,关闭对话框。

比如,在对话框中关闭按钮的事件处理函数中,调用本函数关闭对话框。

  • 函数原型:
ret_t dialog_quit (widget_t* widget, uint32_t code);
  • 参数说明:
参数 类型 说明
返回值 ret_t 返回RET_OK表示成功,否则表示失败。
widget widget_t* dialog对象。
code uint32_t 退出码,作为dialog_modal的返回值。

dialog_set_title 函数


  • 函数功能:

设置对话框的标题文本。

  • 函数原型:
ret_t dialog_set_title (widget_t* widget, char* title);
  • 参数说明:
参数 类型 说明
返回值 ret_t 返回RET_OK表示成功,否则表示失败。
widget widget_t* dialog对象。
title char* 标题。