mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 12:08:16 +08:00
merge master
This commit is contained in:
commit
0750f8194f
@ -242,4 +242,20 @@ typedef struct _widget_vtable_t widget_vtable_t;
|
||||
|
||||
#define TK_LONG_PRESS_TIME 1000
|
||||
|
||||
#ifdef WITH_SDL
|
||||
#define WITH_WIDGET_TYPE_CHECK 1
|
||||
#endif /*WITH_SDL*/
|
||||
|
||||
#ifdef WITH_WIDGET_TYPE_CHECK
|
||||
#define TK_REF_VTABLE(vt) &(g_##vt##_vtable)
|
||||
#define TK_PARENT_VTABLE(vt) TK_REF_VTABLE(vt)
|
||||
#define TK_DECL_VTABLE(vt) const widget_vtable_t g_##vt##_vtable
|
||||
#define TK_EXTERN_VTABLE(vt) extern const widget_vtable_t g_##vt##_vtable
|
||||
#else
|
||||
#define TK_REF_VTABLE(vt) &(s_##vt##_vtable)
|
||||
#define TK_PARENT_VTABLE(vt) NULL
|
||||
#define TK_DECL_VTABLE(vt) static const widget_vtable_t s_##vt##_vtable
|
||||
#define TK_EXTERN_VTABLE(vt)
|
||||
#endif /*WITH_WIDGET_TYPE_CHECK*/
|
||||
|
||||
#endif /*TK_TYPES_DEF_H*/
|
||||
|
@ -99,7 +99,7 @@ struct _widget_vtable_t {
|
||||
/**
|
||||
* parent class vtable
|
||||
*/
|
||||
struct _widget_vtable_t* parent;
|
||||
const struct _widget_vtable_t* parent;
|
||||
|
||||
widget_create_t create;
|
||||
widget_get_prop_t get_prop;
|
||||
@ -1706,6 +1706,7 @@ ret_t widget_on_paint_end(widget_t* widget, canvas_t* c);
|
||||
const char** widget_get_persistent_props(void);
|
||||
|
||||
bool_t widget_is_instance_of(widget_t* widget, const widget_vtable_t* vt);
|
||||
#define WIDGET_IS_INSTANCE_OF(widget, name) widget_is_instance_of(widget, TK_REF_VTABLE(app_bar))
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
@ -169,23 +169,23 @@ ret_t widget_on_paint_null(widget_t* widget, canvas_t* c) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
const widget_vtable_t g_widget_vtable = {.size = sizeof(widget_t),
|
||||
.type = WIDGET_TYPE_NONE,
|
||||
.parent = NULL,
|
||||
.invalidate = widget_invalidate_default,
|
||||
.on_event = widget_on_event_default,
|
||||
.on_paint_self = widget_on_paint_self_default,
|
||||
.on_paint_children = widget_on_paint_children_default,
|
||||
.on_keydown = widget_on_keydown_default,
|
||||
.on_keyup = widget_on_keyup_default,
|
||||
.on_pointer_down = widget_on_pointer_down_default,
|
||||
.on_pointer_move = widget_on_pointer_move_default,
|
||||
.on_pointer_up = widget_on_pointer_up_default,
|
||||
.get_prop = widget_get_prop_default,
|
||||
.set_prop = widget_set_prop_default,
|
||||
.find_target = widget_find_target_default,
|
||||
.on_destroy = widget_on_destroy_default};
|
||||
TK_DECL_VTABLE(widget) = {.size = sizeof(widget_t),
|
||||
.type = WIDGET_TYPE_NONE,
|
||||
.parent = NULL,
|
||||
.invalidate = widget_invalidate_default,
|
||||
.on_event = widget_on_event_default,
|
||||
.on_paint_self = widget_on_paint_self_default,
|
||||
.on_paint_children = widget_on_paint_children_default,
|
||||
.on_keydown = widget_on_keydown_default,
|
||||
.on_keyup = widget_on_keyup_default,
|
||||
.on_pointer_down = widget_on_pointer_down_default,
|
||||
.on_pointer_move = widget_on_pointer_move_default,
|
||||
.on_pointer_up = widget_on_pointer_up_default,
|
||||
.get_prop = widget_get_prop_default,
|
||||
.set_prop = widget_set_prop_default,
|
||||
.find_target = widget_find_target_default,
|
||||
.on_destroy = widget_on_destroy_default};
|
||||
|
||||
const widget_vtable_t* widget_vtable_default() {
|
||||
return &g_widget_vtable;
|
||||
return TK_REF_VTABLE(widget);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ ret_t widget_destroy_default(widget_t* widget);
|
||||
ret_t widget_on_paint_null(widget_t* widget, canvas_t* c);
|
||||
|
||||
/*public for subclass*/
|
||||
extern const widget_vtable_t g_widget_vtable;
|
||||
TK_EXTERN_VTABLE(widget);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
11
src/widgets/app_bar.c
Executable file → Normal file
11
src/widgets/app_bar.c
Executable file → Normal file
@ -21,16 +21,19 @@
|
||||
|
||||
#include "tkc/mem.h"
|
||||
#include "widgets/app_bar.h"
|
||||
#include "base/widget_vtable.h"
|
||||
|
||||
static const widget_vtable_t s_app_bar_vtable = {
|
||||
.size = sizeof(app_bar_t), .type = WIDGET_TYPE_APP_BAR, .create = app_bar_create};
|
||||
TK_DECL_VTABLE(app_bar) = {.size = sizeof(app_bar_t),
|
||||
.type = WIDGET_TYPE_APP_BAR,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = app_bar_create};
|
||||
|
||||
widget_t* app_bar_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
return widget_create(parent, &s_app_bar_vtable, x, y, w, h);
|
||||
return widget_create(parent, TK_REF_VTABLE(app_bar), x, y, w, h);
|
||||
}
|
||||
|
||||
widget_t* app_bar_cast(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL && widget->vt == &s_app_bar_vtable, NULL);
|
||||
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, app_bar), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -91,6 +91,11 @@ widget_t* app_bar_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
|
||||
*/
|
||||
widget_t* app_bar_cast(widget_t* widget);
|
||||
|
||||
#define APP_BAR(w) ((app_bar_t*)(app_bar_cast(w))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(app_bar);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_APP_BAR_H*/
|
||||
|
@ -191,22 +191,22 @@ static ret_t button_on_destroy(widget_t* widget) {
|
||||
|
||||
static const char* s_button_properties[] = {WIDGET_PROP_REPEAT, NULL};
|
||||
|
||||
const widget_vtable_t g_button_vtable = {.size = sizeof(button_t),
|
||||
.type = WIDGET_TYPE_BUTTON,
|
||||
.enable_pool = TRUE,
|
||||
.parent = &g_widget_vtable,
|
||||
.create = button_create,
|
||||
.clone_properties = s_button_properties,
|
||||
.persistent_properties = s_button_properties,
|
||||
.on_event = button_on_event,
|
||||
.set_prop = button_set_prop,
|
||||
.get_prop = button_get_prop,
|
||||
.get_prop_default_value = button_get_prop_default_value,
|
||||
.on_destroy = button_on_destroy,
|
||||
.on_paint_self = widget_on_paint_self_default};
|
||||
TK_DECL_VTABLE(button) = {.size = sizeof(button_t),
|
||||
.type = WIDGET_TYPE_BUTTON,
|
||||
.enable_pool = TRUE,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = button_create,
|
||||
.clone_properties = s_button_properties,
|
||||
.persistent_properties = s_button_properties,
|
||||
.on_event = button_on_event,
|
||||
.set_prop = button_set_prop,
|
||||
.get_prop = button_get_prop,
|
||||
.get_prop_default_value = button_get_prop_default_value,
|
||||
.on_destroy = button_on_destroy,
|
||||
.on_paint_self = widget_on_paint_self_default};
|
||||
|
||||
widget_t* button_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
widget_t* widget = widget_create(parent, &g_button_vtable, x, y, w, h);
|
||||
widget_t* widget = widget_create(parent, TK_REF_VTABLE(button), x, y, w, h);
|
||||
button_t* button = BUTTON(widget);
|
||||
return_value_if_fail(button != NULL, NULL);
|
||||
|
||||
@ -220,7 +220,7 @@ widget_t* button_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
}
|
||||
|
||||
widget_t* button_cast(widget_t* widget) {
|
||||
return_value_if_fail(widget_is_instance_of(widget, &g_button_vtable), NULL);
|
||||
return_value_if_fail(widget_is_instance_of(widget, TK_REF_VTABLE(button)), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
/**
|
||||
* File: button.h
|
||||
* Author: AWTK Develop Team
|
||||
@ -167,3 +168,151 @@ extern const widget_vtable_t g_button_vtable;
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_BUTTON_H*/
|
||||
=======
|
||||
/**
|
||||
* File: button.h
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: button
|
||||
*
|
||||
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* License file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* History:
|
||||
* ================================================================
|
||||
* 2018-01-28 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TK_BUTTON_H
|
||||
#define TK_BUTTON_H
|
||||
|
||||
#include "base/widget.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* @class button_t
|
||||
* @parent widget_t
|
||||
* @annotation ["scriptable"]
|
||||
* 按钮控件。
|
||||
*
|
||||
* 点击按钮之后会触发EVT\_CLICK事件,注册EVT\_CLICK事件以执行特定操作。
|
||||
*
|
||||
* 按钮控件也可以作为容器使用,使用图片和文本作为其子控件,可以实现很多有趣的效果。
|
||||
*
|
||||
* button\_t是[widget\_t](widget_t.md)的子类控件,widget\_t的函数均适用于button\_t控件。
|
||||
*
|
||||
* 在xml中使用"button"标签创建按钮控件。如:
|
||||
*
|
||||
* ```xml
|
||||
* <button x="c" y="m" w="80" h="30" text="OK"/>
|
||||
* ```
|
||||
*
|
||||
* > 更多用法请参考:[button.xml](
|
||||
* https://github.com/zlgopen/awtk/blob/master/demos/assets/raw/ui/button.xml)
|
||||
*
|
||||
* 在c代码中使用函数button\_create创建按钮控件。如:
|
||||
*
|
||||
* ```c
|
||||
* widget_t* button = button_create(win, 10, 10, 128, 30);
|
||||
* widget_set_text(button, L"OK");
|
||||
* widget_on(button, EVT_CLICK, on_click, NULL);
|
||||
* ```
|
||||
*
|
||||
* > 创建之后,需要用widget\_set\_text或widget\_set\_text\_utf8设置文本内容。
|
||||
*
|
||||
* > 完整示例请参考:[button demo](
|
||||
* https://github.com/zlgopen/awtk-c-demos/blob/master/demos/button.c)
|
||||
*
|
||||
* 可用通过style来设置控件的显示风格,如字体的大小和颜色等等。如:
|
||||
*
|
||||
* ```xml
|
||||
* <style name="default" border_color="#a0a0a0" text_color="black">
|
||||
* <normal bg_color="#f0f0f0" />
|
||||
* <pressed bg_color="#c0c0c0" x_offset="1" y_offset="1"/>
|
||||
* <over bg_color="#e0e0e0" />
|
||||
* <disable bg_color="gray" text_color="#d0d0d0" />
|
||||
* </style>
|
||||
* ```
|
||||
*
|
||||
* > 更多用法请参考:[theme default](
|
||||
* https://github.com/zlgopen/awtk/blob/master/demos/assets/raw/styles/default.xml#L31)
|
||||
*
|
||||
*/
|
||||
typedef struct _button_t {
|
||||
widget_t widget;
|
||||
/**
|
||||
* @property {int32_t} repeat
|
||||
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
|
||||
* 重复触发EVT\_CLICK事件的时间间隔。
|
||||
* 为0则不重复触发EVT\_CLICK事件。
|
||||
*/
|
||||
int32_t repeat;
|
||||
|
||||
/*private*/
|
||||
int32_t timer_id;
|
||||
int32_t repeat_nr;
|
||||
bool_t pressed;
|
||||
} button_t;
|
||||
|
||||
/**
|
||||
* @event {pointer_event_t} EVT_CLICK
|
||||
* 点击事件。
|
||||
*/
|
||||
|
||||
/**
|
||||
* @event {pointer_event_t} EVT_LONG_PRESS
|
||||
* 长按事件。
|
||||
*/
|
||||
|
||||
/**
|
||||
* @method button_create
|
||||
* 创建button对象
|
||||
* @annotation ["constructor", "scriptable"]
|
||||
* @param {widget_t*} parent 父控件
|
||||
* @param {xy_t} x x坐标
|
||||
* @param {xy_t} y y坐标
|
||||
* @param {wh_t} w 宽度
|
||||
* @param {wh_t} h 高度
|
||||
*
|
||||
* @return {widget_t*} 对象。
|
||||
*/
|
||||
widget_t* button_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
|
||||
|
||||
/**
|
||||
* @method button_cast
|
||||
* 转换为button对象(供脚本语言使用)。
|
||||
* @annotation ["cast", "scriptable"]
|
||||
* @param {widget_t*} widget button对象。
|
||||
*
|
||||
* @return {widget_t*} button对象。
|
||||
*/
|
||||
widget_t* button_cast(widget_t* widget);
|
||||
|
||||
/**
|
||||
* @method button_set_repeat
|
||||
* 设置触发EVT\_CLICK事件的时间间隔。为0则不重复触发EVT\_CLICK事件。
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {int32_t} repeat 触发EVT_CLICK事件的时间间隔(毫秒)。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t button_set_repeat(widget_t* widget, int32_t repeat);
|
||||
|
||||
#define BUTTON(widget) ((button_t*)(button_cast(widget)))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(button);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_BUTTON_H*/
|
||||
>>>>>>> 8fa037f34c318d102f4d29963a3e95c5fc439be8
|
||||
|
Loading…
Reference in New Issue
Block a user