mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-20 17:44:20 +08:00
sync with RTGUI c074ff2898b9e
Full log is in GitHub. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2222 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -36,6 +36,7 @@ demo_view_combobox.c
|
||||
demo_view_slider.c
|
||||
demo_view_notebook.c
|
||||
demo_view_mywidget.c
|
||||
demo_view_box.c
|
||||
mywidget.c
|
||||
""")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/notebook.h>
|
||||
@@ -11,7 +11,7 @@ static rt_bool_t demo_handle_key(struct rtgui_object* object, struct rtgui_event
|
||||
{
|
||||
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
|
||||
|
||||
if (ekbd->type == RTGUI_KEYDOWN)
|
||||
if (ekbd->type == RTGUI_KEYUP)
|
||||
{
|
||||
if (ekbd->key == RTGUIK_RIGHT)
|
||||
{
|
||||
@@ -30,10 +30,10 @@ static rt_bool_t demo_handle_key(struct rtgui_object* object, struct rtgui_event
|
||||
struct rtgui_win *main_win;
|
||||
static void application_entry(void* parameter)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
struct rtgui_app *app;
|
||||
struct rtgui_rect rect;
|
||||
|
||||
app = rtgui_application_create(rt_thread_self(), "gui_demo");
|
||||
app = rtgui_app_create(rt_thread_self(), "gui_demo");
|
||||
if (app == RT_NULL)
|
||||
return;
|
||||
|
||||
@@ -41,11 +41,10 @@ static void application_entry(void* parameter)
|
||||
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
|
||||
|
||||
main_win = rtgui_win_create(RT_NULL, "demo_win", &rect,
|
||||
/*RTGUI_WIN_STYLE_DESKTOP_DEFAULT);*/
|
||||
RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
|
||||
RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
|
||||
if (main_win == RT_NULL)
|
||||
{
|
||||
rtgui_application_destroy(app);
|
||||
rtgui_app_destroy(app);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,12 +55,14 @@ static void application_entry(void* parameter)
|
||||
if (the_notebook == RT_NULL)
|
||||
{
|
||||
rtgui_win_destroy(main_win);
|
||||
rtgui_application_destroy(app);
|
||||
rtgui_app_destroy(app);
|
||||
return;
|
||||
}
|
||||
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(the_notebook));
|
||||
|
||||
demo_view_box();
|
||||
|
||||
/* 初始化各个例子的视图 */
|
||||
demo_view_benchmark();
|
||||
|
||||
@@ -112,12 +113,12 @@ static void application_entry(void* parameter)
|
||||
rtgui_win_show(main_win, RT_FALSE);
|
||||
|
||||
/* 执行工作台事件循环 */
|
||||
rtgui_application_run(app);
|
||||
rtgui_app_run(app);
|
||||
|
||||
rtgui_application_destroy(app);
|
||||
rtgui_app_destroy(app);
|
||||
}
|
||||
|
||||
void application_init(void)
|
||||
void application_init()
|
||||
{
|
||||
static rt_bool_t inited = RT_FALSE;
|
||||
|
||||
@@ -138,7 +139,7 @@ void application_init(void)
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
void application(void)
|
||||
void application()
|
||||
{
|
||||
application_init();
|
||||
}
|
||||
|
||||
@@ -45,11 +45,7 @@ static void listitem_action(rtgui_widget_t* widget, void* parameter)
|
||||
}
|
||||
|
||||
/* 返回功能的动作函数 */
|
||||
#if RT_VERSION == 4
|
||||
static void return_action(rtgui_widget_t* widget, void* parameter)
|
||||
#else
|
||||
static void return_action(void* parameter)
|
||||
#endif
|
||||
{
|
||||
/* 退出模态显示 */
|
||||
rtgui_container_end_modal(RTGUI_CONTAINER(_view), RTGUI_MODAL_OK);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/notebook.h>
|
||||
#include <rtgui/widgets/button.h>
|
||||
#include <rtgui/widgets/staticline.h>
|
||||
#include <rtgui/widgets/box.h>
|
||||
|
||||
extern struct rtgui_notebook *the_notebook;
|
||||
|
||||
@@ -130,7 +131,6 @@ void demo_view_get_logic_rect(rtgui_container_t* container, rtgui_rect_t *rect)
|
||||
|
||||
/* 当是标准版本时,这个函数用于返回自动布局引擎box控件 */
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
#include <rtgui/widgets/box.h>
|
||||
struct rtgui_box* demo_view_create_box(struct rtgui_container *container, int orient)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
@@ -142,7 +142,7 @@ struct rtgui_box* demo_view_create_box(struct rtgui_container *container, int or
|
||||
rect.y2 -= 25;
|
||||
|
||||
/* 创建一个自动布局引擎 */
|
||||
box = rtgui_box_create(orient, &rect);
|
||||
box = rtgui_box_create(orient, 5);
|
||||
/* 添加box控件到视图中 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(box));
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#define __DEMO_VIEW_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
|
||||
/* 如果是标准版本,可以启用box自动布局引擎 */
|
||||
|
||||
@@ -74,18 +74,21 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev
|
||||
{
|
||||
struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd*)event;
|
||||
|
||||
if (kbd->key == RTGUIK_LEFT || kbd->key == RTGUIK_RIGHT)
|
||||
return RT_FALSE;
|
||||
|
||||
if (RTGUI_KBD_IS_UP(kbd))
|
||||
{
|
||||
if (running)
|
||||
{
|
||||
/* stop */
|
||||
rtgui_application_set_onidle(RT_NULL);
|
||||
rtgui_app_set_onidle(RT_NULL);
|
||||
_draw_default(object, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* run */
|
||||
rtgui_application_set_onidle(_onidle);
|
||||
rtgui_app_set_onidle(_onidle);
|
||||
}
|
||||
|
||||
running = !running;
|
||||
@@ -101,11 +104,19 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
static rt_bool_t _benchmark_onshow(struct rtgui_object *obj, struct rtgui_event* ev)
|
||||
{
|
||||
rtgui_widget_focus(RTGUI_WIDGET(obj));
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rtgui_container_t *demo_view_benchmark(void)
|
||||
{
|
||||
srand(100);
|
||||
container = demo_view("绘图测试");
|
||||
RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler);
|
||||
rtgui_widget_set_onshow(RTGUI_WIDGET(container), _benchmark_onshow);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,44 @@
|
||||
#include "demo_view.h"
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
#include <rtgui/widgets/box.h>
|
||||
#include <rtgui/widgets/panel.h>
|
||||
#include <rtgui/widgets/label.h>
|
||||
#include <rtgui/widgets/button.h>
|
||||
|
||||
rtgui_container_t* demo_view_box(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_box(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_container_t* view;
|
||||
struct rtgui_panel *panel;
|
||||
struct rtgui_box *box;
|
||||
|
||||
view = demo_view(workbench, "Box View");
|
||||
struct rtgui_label *label;
|
||||
struct rtgui_button *button;
|
||||
|
||||
view = demo_view("Box View");
|
||||
demo_view_get_rect(view, &rect);
|
||||
|
||||
panel = rtgui_panel_create(RTGUI_BORDER_NONE);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(panel), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(panel));
|
||||
|
||||
box = rtgui_box_create(RTGUI_VERTICAL, 5);
|
||||
rtgui_container_set_box(RTGUI_CONTAINER(panel), box);
|
||||
|
||||
label = rtgui_label_create("label 1");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label));
|
||||
label = rtgui_label_create("label 2");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label));
|
||||
|
||||
button = rtgui_button_create("button 1");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button));
|
||||
|
||||
button = rtgui_button_create("button 2");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button));
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(button), 25);
|
||||
RTGUI_WIDGET_ALIGN(button) = RTGUI_ALIGN_EXPAND;
|
||||
|
||||
rtgui_container_layout(RTGUI_CONTAINER(panel));
|
||||
|
||||
return view;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
||||
filelist = rtgui_filelist_view_create("/", "*.*", &rect);
|
||||
#endif
|
||||
/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
|
||||
if (rtgui_container_show(RTGUI_CONTAINER(filelist), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
if (rtgui_widget_show(RTGUI_WIDGET(filelist), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
{
|
||||
char path[32], image_type[8];
|
||||
|
||||
|
||||
@@ -141,14 +141,16 @@ static struct rtgui_listbox_item items[] =
|
||||
{"list #3", RT_NULL},
|
||||
};
|
||||
|
||||
static void on_items(rtgui_widget_t* widget, struct rtgui_event* event)
|
||||
static rt_bool_t on_items(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
rtgui_listbox_t* box;
|
||||
/* get listbox */
|
||||
box = RTGUI_LISTBOX(widget);
|
||||
box = RTGUI_LISTBOX(object);
|
||||
|
||||
/* 打印当前的项 */
|
||||
rt_kprintf("current item: %d\n", box->current_item);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/* 创建用于演示label控件的视图 */
|
||||
|
||||
@@ -204,14 +204,16 @@ void _rtgui_listctrl_item_draw(struct rtgui_listctrl *list,
|
||||
}
|
||||
}
|
||||
|
||||
static void on_items(rtgui_widget_t* widget, struct rtgui_event* event)
|
||||
static rt_bool_t on_items(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
rtgui_listctrl_t* ctrl;
|
||||
/* get listctrl */
|
||||
ctrl = RTGUI_LISTCTRL(widget);
|
||||
ctrl = RTGUI_LISTCTRL(object);
|
||||
|
||||
/* 打印当前的项 */
|
||||
rt_kprintf("current item: %d\n", ctrl->current_item);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/* 创建用于演示label控件的视图 */
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <rtgui/widgets/menu.h>
|
||||
#include <rtgui/widgets/button.h>
|
||||
|
||||
static rt_bool_t _onmenuitem(struct rtgui_widget *widget, struct rtgui_event* event)
|
||||
static rt_bool_t _onmenuitem(struct rtgui_object *object, struct rtgui_event* event)
|
||||
{
|
||||
rt_kprintf("menu action!!\n");
|
||||
return RT_TRUE;
|
||||
@@ -31,15 +31,17 @@ static const rtgui_menu_item_t items[] =
|
||||
};
|
||||
static rtgui_menu_t* menu;
|
||||
|
||||
static _onmenu(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
static rt_bool_t _onmenu(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
|
||||
rtgui_widget_get_rect(widget, &rect);
|
||||
rtgui_widget_rect_to_device(widget, &rect);
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(object), &rect);
|
||||
|
||||
if (menu != RT_NULL)
|
||||
rtgui_menu_pop(menu, rect.x1, rect.y2 + 5);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/* 创建用于演示menu控件的视图 */
|
||||
|
||||
@@ -57,14 +57,16 @@ static void create_normal_win(void)
|
||||
}
|
||||
|
||||
/* 触发正常窗口显示 */
|
||||
static void demo_normal_window_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
static void demo_normal_window_onbutton(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
rt_sprintf(normal_window_label_text,
|
||||
"第 %d 次显示", normal_window_show_count);
|
||||
rtgui_label_set_text(normal_window_label,
|
||||
normal_window_label_text);
|
||||
/* 非模态显示窗口 */
|
||||
rtgui_win_show(normal_window, RT_FALSE);
|
||||
if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(normal_window)))
|
||||
rtgui_win_show(normal_window, RT_FALSE);
|
||||
else
|
||||
rtgui_win_activate(normal_window);
|
||||
}
|
||||
|
||||
/* 获取一个递增的窗口标题 */
|
||||
@@ -91,10 +93,6 @@ void diag_close(struct rtgui_timer* timer, void* parameter)
|
||||
{
|
||||
/* 超时,关闭对话框 */
|
||||
rtgui_win_destroy(msgbox);
|
||||
|
||||
/* 停止并删除定时器 */
|
||||
rtgui_timer_stop(timer);
|
||||
rtgui_timer_destory(timer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +115,7 @@ static rt_uint16_t delta_x = 20;
|
||||
static rt_uint16_t delta_y = 40;
|
||||
|
||||
/* 触发自动窗口显示 */
|
||||
static void demo_autowin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
static void demo_autowin_onbutton(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
struct rtgui_rect rect ={50, 50, 200, 200};
|
||||
|
||||
@@ -147,7 +145,7 @@ static void demo_autowin_onbutton(struct rtgui_widget* widget, rtgui_event_t* ev
|
||||
}
|
||||
|
||||
/* 触发模态窗口显示 */
|
||||
static void demo_modalwin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
static void demo_modalwin_onbutton(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_win_t *win;
|
||||
rtgui_label_t *label;
|
||||
@@ -177,19 +175,19 @@ static void demo_modalwin_onbutton(struct rtgui_widget* widget, rtgui_event_t* e
|
||||
rtgui_win_destroy(win);
|
||||
}
|
||||
|
||||
static void demo_close_ntitle_window(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
static void demo_close_ntitle_window(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_win_t* win;
|
||||
|
||||
/* 获得最顶层控件 */
|
||||
win = RTGUI_WIN(rtgui_widget_get_toplevel(widget));
|
||||
win = RTGUI_WIN(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
|
||||
|
||||
/* 销毁窗口 */
|
||||
rtgui_win_destroy(win);
|
||||
}
|
||||
|
||||
/* 触发无标题窗口显示 */
|
||||
static void demo_ntitlewin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
static void demo_ntitlewin_onbutton(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_win_t *win;
|
||||
rtgui_label_t *label;
|
||||
|
||||
@@ -71,10 +71,10 @@ static void rtgui_mywidget_onmouse(struct rtgui_mywidget* me, struct rtgui_event
|
||||
}
|
||||
|
||||
/* mywidget控件的事件处�函�*/
|
||||
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
/* 调用事件处�函数时,widget指针指�控件本身,所以先获得相应控件对象的指�*/
|
||||
struct rtgui_mywidget* me = RTGUI_MYWIDGET(widget);
|
||||
struct rtgui_mywidget* me = RTGUI_MYWIDGET(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
@@ -90,7 +90,7 @@ rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui
|
||||
|
||||
/* 其他事件调用父类的事件处�函�*/
|
||||
default:
|
||||
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
|
||||
return rtgui_widget_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
|
||||
@@ -45,6 +45,6 @@ void rtgui_mywidget_destroy(struct rtgui_mywidget* me);
|
||||
* 对一个控件而言,如果派生自它的å�控件很å�¯èƒ½ä¼šè°ƒç”¨çˆ¶æŽ§ä»¶çš„事件处ç�†å‡½æ•°ï¼Œ
|
||||
* 所以这里采用公开声明的方��
|
||||
*/
|
||||
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object* object, struct rtgui_event* event);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user