rt-thread-official/examples/gui/mywidget.h

53 lines
1.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 程序清单:自定义控件
*
* 这个例子是要实现一个自定义控件,外观大致如
* |
* --o--
* |
* 的形状中间的o色彩表示了当前的状态ON状态时是绿色OFF状态时是红色。
* 并且这个o位置接受鼠标点击点击下切换下相应的状态。
*/
#ifndef __MY_WIDGET_H__
#define __MY_WIDGET_H__
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
/* 自定义控件的状态值定义 */
#define MYWIDGET_STATUS_ON 1
#define MYWIDGET_STATUS_OFF 0
/** 每个控件会有一个类型,通过如下的宏获得控件相应的类型信息 */
#define RTGUI_MYWIDGET_TYPE (rtgui_mywidget_type_get())
/** 对一个对象实例,可以通过下面的宏实现类型转换 */
#define RTGUI_MYWIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MYWIDGET_TYPE, rtgui_mywidget_t))
/** 可以通过下面的宏以决定一个具体实例是否是自定义控件类型 */
#define RTGUI_IS_MYWIDGET(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MYWIDGET_TYPE))
/* 个性化控件类定义 */
struct rtgui_mywidget
{
/* 这个控件是继承自rtgui_widget控件 */
struct rtgui_widget parent;
/* 状态ON、OFF */
rt_uint8_t status;
};
typedef struct rtgui_mywidget rtgui_mywidget_t;
/* 这个函数用于获得自定义控件的类型 */
rtgui_type_t *rtgui_mywidget_type_get(void);
/* 控件的创建和删除 */
struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r);
void rtgui_mywidget_destroy(struct rtgui_mywidget* me);
/* 控件的默认事件处理函数。
* 对一个控件而言,如果派生自它的子控件很可能会调用父控件的事件处理函数,
* 所以这里采用公开声明的方式。
*/
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
#endif