From db9e590b90fc8f01d708f7f67190c114fb1ef6ac Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Sun, 5 Jun 2011 15:19:19 +0000 Subject: add multi-text view widget. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1455 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/rtgui/include/rtgui/image.h | 4 + components/rtgui/include/rtgui/list.h | 130 +++++++++++----------- components/rtgui/include/rtgui/widgets/textview.h | 67 +++++++++++ 3 files changed, 136 insertions(+), 65 deletions(-) create mode 100644 components/rtgui/include/rtgui/widgets/textview.h (limited to 'components/rtgui/include') diff --git a/components/rtgui/include/rtgui/image.h b/components/rtgui/include/rtgui/image.h index 99e3348de7..45030dec40 100644 --- a/components/rtgui/include/rtgui/image.h +++ b/components/rtgui/include/rtgui/image.h @@ -66,6 +66,9 @@ struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load); struct rtgui_image* rtgui_image_create_from_mem(const char* type, const rt_uint8_t* data, rt_size_t length, rt_bool_t load); void rtgui_image_destroy(struct rtgui_image* image); +/* get image's rect */ +void rtgui_image_get_rect(struct rtgui_image* image, struct rtgui_rect* rect); + /* register an image engine */ void rtgui_image_register_engine(struct rtgui_image_engine* engine); @@ -74,3 +77,4 @@ void rtgui_image_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtg struct rtgui_image_palette* rtgui_image_palette_create(rt_uint32_t ncolors); #endif + diff --git a/components/rtgui/include/rtgui/list.h b/components/rtgui/include/rtgui/list.h index 4b3cf951e6..a58f689984 100644 --- a/components/rtgui/include/rtgui/list.h +++ b/components/rtgui/include/rtgui/list.h @@ -1,66 +1,66 @@ -/* - * File : list.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#ifndef __RTGUI_LIST_H__ -#define __RTGUI_LIST_H__ - -#include - -struct rtgui_list_node -{ - struct rtgui_list_node* next; -}; -typedef struct rtgui_list_node rtgui_list_t; - -rt_inline void rtgui_list_init(rtgui_list_t *l) -{ - l->next = (struct rtgui_list_node *)0; -} +/* + * File : list.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#ifndef __RTGUI_LIST_H__ +#define __RTGUI_LIST_H__ -rt_inline void rtgui_list_append(rtgui_list_t *l, rtgui_list_t *n) -{ - struct rtgui_list_node* node; - - node = l; - while (node->next) node = node->next; - - /* append the node to the tail */ - node->next = n; - n->next = (struct rtgui_list_node*) 0; -} - -rt_inline void rtgui_list_insert(rtgui_list_t *l, rtgui_list_t *n) -{ - n->next = l->next; - l->next = n; -} - -rt_inline rtgui_list_t* rtgui_list_remove(rtgui_list_t *l, rtgui_list_t *n) -{ - /* remove slist head */ - struct rtgui_list_node* node = l; - while (node->next && node->next != n) node = node->next; - - /* remove node */ - if (node->next != (rtgui_list_t *)0) node->next = node->next->next; - - return l; -} - -#define rtgui_list_entry(node, type, member) \ - ((type *)((char*)(node)-(unsigned long)(&((type *)0)->member))) - -#define rtgui_list_foreach(node, list) \ - for ((node) = (list)->next; (node) != RT_NULL; (node) = (node)->next) - -#endif +#include + +struct rtgui_list_node +{ + struct rtgui_list_node* next; +}; +typedef struct rtgui_list_node rtgui_list_t; + +rt_inline void rtgui_list_init(rtgui_list_t *l) +{ + l->next = (struct rtgui_list_node *)0; +} + +rt_inline void rtgui_list_append(rtgui_list_t *l, rtgui_list_t *n) +{ + struct rtgui_list_node* node; + + node = l; + while (node->next) node = node->next; + + /* append the node to the tail */ + node->next = n; + n->next = (struct rtgui_list_node*) 0; +} + +rt_inline void rtgui_list_insert(rtgui_list_t *l, rtgui_list_t *n) +{ + n->next = l->next; + l->next = n; +} + +rt_inline rtgui_list_t* rtgui_list_remove(rtgui_list_t *l, rtgui_list_t *n) +{ + /* remove slist head */ + struct rtgui_list_node* node = l; + while (node->next && node->next != n) node = node->next; + + /* remove node */ + if (node->next != (rtgui_list_t *)0) node->next = node->next->next; + + return l; +} + +#define rtgui_list_entry(node, type, member) \ + ((type *)((char*)(node)-(unsigned long)(&((type *)0)->member))) + +#define rtgui_list_foreach(node, list) \ + for ((node) = (list)->next; (node) != RT_NULL; (node) = (node)->next) + +#endif diff --git a/components/rtgui/include/rtgui/widgets/textview.h b/components/rtgui/include/rtgui/widgets/textview.h new file mode 100644 index 0000000000..523b5ee9c1 --- /dev/null +++ b/components/rtgui/include/rtgui/widgets/textview.h @@ -0,0 +1,67 @@ +/* + * File : textview.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2011-03-05 Bernard first version + */ +#ifndef __RTGUI_TEXTVIEW_H__ +#define __RTGUI_TEXTVIEW_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup rtgui_textview + * @{ + */ + +DECLARE_CLASS_TYPE(textview); + +/** Gets the type of a textview */ +#define RTGUI_TEXTVIEW_TYPE (RTGUI_TYPE(textview)) +/** Casts the object to an rtgui_textview */ +#define RTGUI_TEXTVIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_TEXTVIEW_TYPE, rtgui_textview_t)) +/** Checks if the object is an rtgui_textview */ +#define RTGUI_IS_TEXTVIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_TEXTVIEW_TYPE)) + +/* + * the textview widget + */ +struct rtgui_textview +{ + /* inherit from widget */ + struct rtgui_widget parent; + + rt_uint16_t line_width; + rt_uint16_t line_count; + + char* lines; + + rt_int16_t line_current; + rt_uint16_t line_page_count; +}; +typedef struct rtgui_textview rtgui_textview_t; + +rtgui_textview_t* rtgui_textview_create(const char* text, const rtgui_rect_t *rect); +void rtgui_textview_destroy(rtgui_textview_t* textview); + +rt_bool_t rtgui_textview_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); +void rtgui_textview_set_text(rtgui_textview_t* textview, const char* text); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.3.1