mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
add more widgets.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@291 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
1 parent
e0f0d6da6a
commit
5939b5f6ac
17 files changed
+1275
-14
No files matched your search
@@ -34,9 +34,13 @@ server/topwin.c
|
||||
widgets_src = Split("""
|
||||
widgets/box.c
|
||||
widgets/button.c
|
||||
widgets/checkbox.c
|
||||
widgets/container.c
|
||||
widgets/iconbox.c
|
||||
widgets/label.c
|
||||
widgets/progressbar.c
|
||||
widgets/slider.c
|
||||
widgets/staticline.c
|
||||
widgets/textbox.c
|
||||
widgets/title.c
|
||||
widgets/toplevel.c
|
||||
|
||||
+248
-1
File diff suppressed because it is too large.
Load diff
@@ -21,6 +21,10 @@
|
||||
#include <rtgui/widgets/button.h>
|
||||
#include <rtgui/widgets/textbox.h>
|
||||
#include <rtgui/widgets/iconbox.h>
|
||||
#include <rtgui/widgets/checkbox.h>
|
||||
#include <rtgui/widgets/slider.h>
|
||||
#include <rtgui/widgets/progressbar.h>
|
||||
#include <rtgui/widgets/staticline.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -33,6 +37,10 @@ void rtgui_theme_draw_button(rtgui_button_t* btn);
|
||||
void rtgui_theme_draw_label(rtgui_label_t* label);
|
||||
void rtgui_theme_draw_textbox(rtgui_textbox_t* box);
|
||||
void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox);
|
||||
void rtgui_theme_draw_checkbox(rtgui_checkbox_t* checkbox);
|
||||
void rtgui_theme_draw_slider(struct rtgui_slider* slider);
|
||||
void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar);
|
||||
void rtgui_theme_draw_staticline(struct rtgui_staticline* staticline);
|
||||
|
||||
rt_uint16_t rtgui_theme_get_selected_height(void);
|
||||
void rtgui_theme_draw_selected(struct rtgui_dc* dc, rtgui_rect_t *rect);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef __RTGUI_CHECKBOX_H__
|
||||
#define __RTGUI_CHECKBOX_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
#include <rtgui/widgets/label.h>
|
||||
|
||||
/** Gets the type of a button */
|
||||
#define RTGUI_CHECKBOX_TYPE (rtgui_checkbox_type_get())
|
||||
/** Casts the object to an rtgui_button */
|
||||
#define RTGUI_CHECKBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_CHECKBOX_TYPE, rtgui_checkbox))
|
||||
/** Checks if the object is an rtgui_button */
|
||||
#define RTGUI_IS_CHECKBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_CHECKBOX_TYPE))
|
||||
|
||||
#define RTGUI_CHECKBOX_STATUS_CHECKED 0
|
||||
#define RTGUI_CHECKBOX_STATUS_UNCHECKED 1
|
||||
|
||||
struct rtgui_checkbox
|
||||
{
|
||||
/* inherit from label */
|
||||
struct rtgui_label parent;
|
||||
|
||||
/* check box status */
|
||||
rt_uint8_t status_down;
|
||||
};
|
||||
typedef struct rtgui_checkbox rtgui_checkbox_t;
|
||||
|
||||
rtgui_type_t *rtgui_checkbox_type_get(void);
|
||||
|
||||
rtgui_checkbox_t* rtgui_checkbox_create(unsigned char* text);
|
||||
void rtgui_checkbox_destroy(rtgui_checkbox_t* checkbox);
|
||||
|
||||
void rtgui_checkbox_ondraw(rtgui_checkbox_t* checkbox);
|
||||
rt_bool_t rtgui_checkbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef __RTGUI_PROGRESSBAR_H__
|
||||
#define __RTGUI_PROGRESSBAR_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
|
||||
/** Gets the type of a progressbar */
|
||||
#define RTGUI_PROGRESSBAR_TYPE (rtgui_progressbar_type_get())
|
||||
/** Casts the object to a rtgui_progressbar */
|
||||
#define RTGUI_PROGRESSBAR(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_PROGRESSBAR_TYPE, rtgui_progressbar_t))
|
||||
/** Checks if the object is a rtgui_progressbar */
|
||||
#define RTGUI_IS_PROGRESSBAR(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_PROGRESSBAR_TYPE))
|
||||
|
||||
#define DEFAULT_WIDTH 100
|
||||
#define DEFAULT_HEIGHT 20
|
||||
|
||||
struct rtgui_progressbar
|
||||
{
|
||||
struct rtgui_widget parent;
|
||||
|
||||
int orientation;
|
||||
|
||||
int range;
|
||||
int position;
|
||||
};
|
||||
typedef struct rtgui_progressbar rtgui_progressbar_t;
|
||||
|
||||
rtgui_type_t *rtgui_progressbar_type_get(void);
|
||||
|
||||
struct rtgui_progressbar* rtgui_progressbar_create(int orientation, int range, rtgui_rect_t* r);
|
||||
void rtgui_progressbar_destroy(struct rtgui_progressbar* p_bar);
|
||||
|
||||
rt_bool_t rtgui_progressbar_event_handler(struct rtgui_widget* widget,
|
||||
struct rtgui_event* event);
|
||||
|
||||
void rtgui_progressbar_set_value(struct rtgui_progressbar *p_bar, int value);
|
||||
int rtgui_progressbar_get_value(struct rtgui_progressbar *p_bar);
|
||||
void rtgui_progressbar_set_range(struct rtgui_progressbar *p_bar, int range);
|
||||
int rtgui_progressbar_get_range(struct rtgui_progressbar *p_bar);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef __RTGUI_RADIOBOX_H__
|
||||
#define __RTGUI_RADIOBOX_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
|
||||
/** Gets the type of a radiobox */
|
||||
#define RTGUI_RADIOBOX_TYPE (rtgui_radiobox_type_get())
|
||||
/** Casts the object to an rtgui_radiobox */
|
||||
#define RTGUI_SLIDER(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_RADIOBOX_TYPE, rtgui_radiobox_t))
|
||||
/** Checks if the object is an rtgui_radiobox */
|
||||
#define RTGUI_IS_SLIDER(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_RADIOBOX_TYPE))
|
||||
|
||||
struct rtgui_radiobox
|
||||
{
|
||||
struct rtgui_widget parent;
|
||||
|
||||
/* widget private data */
|
||||
int orient;
|
||||
|
||||
char* items;
|
||||
int item_count, item_selection;
|
||||
};
|
||||
typedef struct rtgui_radiobox rtgui_radiobox_t;
|
||||
|
||||
rtgui_type_t *rtgui_radiobox_type_get(void);
|
||||
|
||||
struct rtgui_radiobox* rtgui_radiobox_create(int orient, char** radio_items, int number);
|
||||
void rtgui_radiobox_destroy(struct rtgui_radiobox* radiobox);
|
||||
|
||||
void rtgui_radiobox_set_selection(struct rtgui_radiobox* radiobox, int selection);
|
||||
int rtgui_radiobox_get_selection(struct rtgui_radiobox* radiobox);
|
||||
|
||||
rt_bool_t rtgui_radiobox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef __RTGUI_SLIDER_H__
|
||||
#define __RTGUI_SLIDER_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
|
||||
/** Gets the type of a slider */
|
||||
#define RTGUI_SLIDER_TYPE (rtgui_slider_type_get())
|
||||
/** Casts the object to an rtgui_slider */
|
||||
#define RTGUI_SLIDER(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_SLIDER_TYPE, rtgui_slider_t))
|
||||
/** Checks if the object is an rtgui_slider */
|
||||
#define RTGUI_IS_SLIDER(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_SLIDER_TYPE))
|
||||
|
||||
struct rtgui_slider
|
||||
{
|
||||
struct rtgui_widget parent;
|
||||
|
||||
/* widget private data */
|
||||
rt_size_t min, max, value, ticks;
|
||||
rt_size_t thumb_width;
|
||||
|
||||
int orient;
|
||||
};
|
||||
typedef struct rtgui_slider rtgui_slider_t;
|
||||
|
||||
rtgui_type_t *rtgui_slider_type_get(void);
|
||||
|
||||
struct rtgui_slider* rtgui_slider_create(rt_size_t min, rt_size_t max, int orient);
|
||||
void rtgui_slider_destroy(struct rtgui_slider* slider);
|
||||
|
||||
rt_bool_t rtgui_slider_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
|
||||
void rtgui_slider_set_range(struct rtgui_slider* slider, rt_size_t min, rt_size_t max);
|
||||
void rtgui_slider_set_value(struct rtgui_slider* slider, rt_size_t value);
|
||||
void rtgui_slider_set_orientation(struct rtgui_slider* slider, int orientation);
|
||||
|
||||
rt_size_t rtgui_slider_get_value(struct rtgui_slider* slider);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef __RTGUI_STATICLINE__H__
|
||||
#define __RTGUI_STATICLINE__H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
|
||||
/*
|
||||
* the static line widget
|
||||
*/
|
||||
|
||||
/** Gets the type of a staticline */
|
||||
#define RTGUI_STATICLINE_TYPE (rtgui_staticline_type_get())
|
||||
/** Casts the object to an rtgui_staticline */
|
||||
#define RTGUI_STATICLINE(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_STATICLINE_TYPE, rtgui_staticline_t))
|
||||
/** Checks if the object is an rtgui_staticline */
|
||||
#define RTGUI_IS_STATICLINE(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_STATICLINE_TYPE))
|
||||
|
||||
struct rtgui_staticline
|
||||
{
|
||||
/* inherit from widget */
|
||||
struct rtgui_widget parent;
|
||||
|
||||
int orientation;
|
||||
};
|
||||
typedef struct rtgui_staticline rtgui_staticline_t;
|
||||
|
||||
rtgui_staticline_t *rtgui_staticline_create(int orientation);
|
||||
void rtgui_staticline_destroy(rtgui_staticline_t* staticline);
|
||||
|
||||
rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,8 +27,10 @@
|
||||
#define RTGUI_TEXTBOX_DEFAULT_WIDTH 80
|
||||
#define RTGUI_TEXTBOX_DEFAULT_HEIGHT 20
|
||||
|
||||
#define RTGUI_TEXTBOX_SINGLE 0x00
|
||||
#define RTGUI_TEXTBOX_MULTI 0x00
|
||||
#define RTGUI_TEXTBOX_SINGLE 0x00
|
||||
#define RTGUI_TEXTBOX_MULTI 0x01
|
||||
#define RTGUI_TEXTBOX_CARET_SHOW 0x10
|
||||
#define RTGUI_TEXTBOX_CARET_HIDE 0x00
|
||||
|
||||
struct rtgui_textbox_line
|
||||
{
|
||||
@@ -42,11 +44,11 @@ struct rtgui_textbox
|
||||
/* inherit from widget */
|
||||
struct rtgui_widget parent;
|
||||
|
||||
/* text box type */
|
||||
rt_ubase_t type;
|
||||
/* text box flag */
|
||||
rt_uint8_t flag;
|
||||
|
||||
/* current line and position */
|
||||
rt_size_t line, line_begin, position, line_length;
|
||||
rt_uint16_t line, line_begin, position, line_length;
|
||||
|
||||
rt_uint8_t* text;
|
||||
rt_size_t font_width;
|
||||
|
||||
@@ -42,7 +42,7 @@ extern "C" {
|
||||
|
||||
#define RTGUI_WIDGET_UNFOCUS(w) (w)->flag &= ~RTGUI_WIDGET_FLAG_FOCUS
|
||||
#define RTGUI_WIDGET_FOCUS(w) (w)->flag |= RTGUI_WIDGET_FLAG_FOCUS
|
||||
#define RTGUI_WIDGET_IS_FOCUS(w) ((w)->flag & RTGUI_WIDGET_FLAG_FOCUS)
|
||||
#define RTGUI_WIDGET_IS_FOCUSED(w) ((w)->flag & RTGUI_WIDGET_FLAG_FOCUS)
|
||||
|
||||
#define RTGUI_WIDGET_IS_FOCUSABLE(w) ((w)->flag & RTGUI_WIDGET_FLAG_FOCUSABLE)
|
||||
|
||||
@@ -195,6 +195,10 @@ void rtgui_widget_show(rtgui_widget_t* widget);
|
||||
void rtgui_widget_hide(rtgui_widget_t* widget);
|
||||
void rtgui_widget_update(rtgui_widget_t* widget);
|
||||
|
||||
/* get parent color */
|
||||
rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget);
|
||||
rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget);
|
||||
|
||||
/* get the next sibling of widget */
|
||||
rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget);
|
||||
/* get the prev sibling of widget */
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_theme.h>
|
||||
#include <rtgui/widgets/checkbox.h>
|
||||
|
||||
static void _rtgui_checkbox_constructor(rtgui_checkbox_t *box)
|
||||
{
|
||||
/* init widget and set event handler */
|
||||
RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_checkbox_event_handler);
|
||||
|
||||
/* set status */
|
||||
box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
|
||||
|
||||
/* set default gc */
|
||||
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
|
||||
}
|
||||
|
||||
rtgui_type_t *rtgui_checkbox_type_get(void)
|
||||
{
|
||||
static rtgui_type_t *checkbox_type = RT_NULL;
|
||||
|
||||
if (!checkbox_type)
|
||||
{
|
||||
checkbox_type = rtgui_type_create("checkbox", RTGUI_LABEL_TYPE,
|
||||
sizeof(rtgui_checkbox_t), RTGUI_CONSTRUCTOR(_rtgui_checkbox_constructor), RT_NULL);
|
||||
}
|
||||
|
||||
return checkbox_type;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_checkbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_checkbox* box = (struct rtgui_checkbox*)widget;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (widget->on_draw != RT_NULL)
|
||||
{
|
||||
return widget->on_draw(widget, event);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
rtgui_theme_draw_checkbox(box);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
{
|
||||
if (RTGUI_WIDGET_IS_ENABLE(widget) && !RTGUI_WIDGET_IS_HIDE(widget))
|
||||
{
|
||||
struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
|
||||
if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT &&
|
||||
emouse->button & RTGUI_MOUSE_BUTTON_UP)
|
||||
{
|
||||
/* set focus */
|
||||
RTGUI_WIDGET_FOCUS(widget);
|
||||
|
||||
if (box->status_down & RTGUI_CHECKBOX_STATUS_UNCHECKED)
|
||||
{
|
||||
/* check it */
|
||||
box->status_down = RTGUI_CHECKBOX_STATUS_CHECKED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* un-check it */
|
||||
box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
|
||||
}
|
||||
}
|
||||
|
||||
/* draw checkbox */
|
||||
rtgui_theme_draw_checkbox(box);
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
/* call user callback */
|
||||
if (widget->on_mouseclick != RT_NULL)
|
||||
{
|
||||
return widget->on_mouseclick(widget, event);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
struct rtgui_checkbox* rtgui_checkbox_create(unsigned char* text)
|
||||
{
|
||||
struct rtgui_checkbox* box;
|
||||
|
||||
box = (struct rtgui_checkbox*) rtgui_widget_create (RTGUI_CHECKBOX_TYPE);
|
||||
if (box != RT_NULL)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* set default rect */
|
||||
rtgui_font_get_metrics(rtgui_font_default(), text, &rect);
|
||||
rect.x2 += RTGUI_BORDER_DEFAULT_WIDTH + 5 + (RTGUI_BORDER_DEFAULT_WIDTH << 1);
|
||||
rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
|
||||
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
|
||||
rtgui_label_set_text(RTGUI_LABEL(box), text);
|
||||
}
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
void rtgui_checkbox_destroy(rtgui_checkbox_t* box)
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(box));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_theme.h>
|
||||
#include <rtgui/widgets/progressbar.h>
|
||||
|
||||
#define RTGUI_PROGRESSBAR_DEFAULT_RANGE 100
|
||||
|
||||
static void _rtgui_progressbar_constructor(rtgui_progressbar_t *bar)
|
||||
{
|
||||
rtgui_rect_t rect = {0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT};
|
||||
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(bar), rtgui_progressbar_event_handler);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
|
||||
|
||||
bar->orientation = RTGUI_HORIZONTAL;
|
||||
bar->range = RTGUI_PROGRESSBAR_DEFAULT_RANGE;
|
||||
bar->position = 0;
|
||||
|
||||
/* set gc */
|
||||
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(bar)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
|
||||
}
|
||||
|
||||
rtgui_type_t *rtgui_progressbar_type_get(void)
|
||||
{
|
||||
static rtgui_type_t *progressbar_type = RT_NULL;
|
||||
|
||||
if (!progressbar_type)
|
||||
{
|
||||
progressbar_type = rtgui_type_create("progressbar", RTGUI_WIDGET_TYPE,
|
||||
sizeof(rtgui_progressbar_t), RTGUI_CONSTRUCTOR(_rtgui_progressbar_constructor), RT_NULL);
|
||||
}
|
||||
|
||||
return progressbar_type;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_progressbar_event_handler(struct rtgui_widget* widget,
|
||||
struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_progressbar* bar = (struct rtgui_progressbar*)widget;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
rtgui_theme_draw_progressbar(bar);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
struct rtgui_progressbar* rtgui_progressbar_create(int orientation, int range,
|
||||
rtgui_rect_t* r)
|
||||
{
|
||||
struct rtgui_progressbar* bar;
|
||||
|
||||
bar = (struct rtgui_progressbar*) rtgui_widget_create (RTGUI_PROGRESSBAR_TYPE);
|
||||
if (bar != RT_NULL)
|
||||
{
|
||||
if (r != RT_NULL)
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);
|
||||
|
||||
bar->orientation = orientation;
|
||||
bar->range = range;
|
||||
}
|
||||
|
||||
return bar;
|
||||
}
|
||||
|
||||
void rtgui_progressbar_destroy(struct rtgui_progressbar* bar)
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(bar));
|
||||
}
|
||||
|
||||
|
||||
void rtgui_progressbar_set_value(struct rtgui_progressbar *bar, int value)
|
||||
{
|
||||
RT_ASSERT(bar != RT_NULL);
|
||||
|
||||
bar->position = value;
|
||||
|
||||
rtgui_theme_draw_progressbar(bar);
|
||||
return;
|
||||
}
|
||||
|
||||
int rtgui_progressbar_get_value(struct rtgui_progressbar *bar)
|
||||
{
|
||||
RT_ASSERT(bar != RT_NULL);
|
||||
|
||||
return bar->position;
|
||||
}
|
||||
|
||||
void rtgui_progressbar_set_range(struct rtgui_progressbar *bar, int range)
|
||||
{
|
||||
RT_ASSERT(bar != RT_NULL);
|
||||
|
||||
bar->range = range;
|
||||
|
||||
rtgui_theme_draw_progressbar(bar);
|
||||
return;
|
||||
}
|
||||
|
||||
int rtgui_progressbar_get_range(struct rtgui_progressbar *bar)
|
||||
{
|
||||
RT_ASSERT(bar != RT_NULL);
|
||||
|
||||
return bar->range;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,89 @@
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_theme.h>
|
||||
#include <rtgui/widgets/staticline.h>
|
||||
|
||||
static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
|
||||
{
|
||||
/* init widget and set event handler */
|
||||
rtgui_rect_t rect = {0, 0, 100, 2};
|
||||
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
|
||||
staticline->orientation= RTGUI_HORIZONTAL;
|
||||
|
||||
/* set background color */
|
||||
RTGUI_WIDGET(staticline)->gc.background = RTGUI_RGB(64, 64, 64);
|
||||
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(staticline), rtgui_staticline_event_handler);
|
||||
}
|
||||
|
||||
rtgui_type_t *rtgui_staticline_type_get(void)
|
||||
{
|
||||
static rtgui_type_t *staticline_type = RT_NULL;
|
||||
|
||||
if (!staticline_type)
|
||||
{
|
||||
staticline_type = rtgui_type_create("staticline", RTGUI_WIDGET_TYPE,
|
||||
sizeof(rtgui_staticline_t), RTGUI_CONSTRUCTOR(_rtgui_staticline_constructor), RT_NULL);
|
||||
}
|
||||
|
||||
return staticline_type;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_staticline* staticline;
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
staticline = (struct rtgui_staticline*) widget;
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
|
||||
else
|
||||
#endif
|
||||
rtgui_theme_draw_staticline(staticline);
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_staticline_t * rtgui_staticline_create(int orientation)
|
||||
{
|
||||
rtgui_staticline_t* staticline;
|
||||
|
||||
staticline = (struct rtgui_staticline*) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
|
||||
if (staticline!= RT_NULL)
|
||||
{
|
||||
rtgui_staticline_set_orientation(staticline, orientation);
|
||||
}
|
||||
|
||||
return staticline;
|
||||
}
|
||||
|
||||
void rtgui_staticline_destroy(rtgui_staticline_t* staticline)
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(staticline));
|
||||
}
|
||||
|
||||
void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation)
|
||||
{
|
||||
RT_ASSERT(staticline != RT_NULL);
|
||||
|
||||
staticline->orientation = orientation;
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (orientation == RTGUI_HORIZONTAL)
|
||||
{
|
||||
/* HORIZONTAL */
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
|
||||
rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* VERTICAL */
|
||||
rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
|
||||
rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+16
-6
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_theme.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/textbox.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
@@ -30,9 +30,17 @@ static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtg
|
||||
static void _rtgui_textbox_caret_timeout(struct rtgui_timer* timer, void* parameter)
|
||||
{
|
||||
rtgui_textbox_t* box;
|
||||
|
||||
box = (rtgui_textbox_t*)parameter;
|
||||
|
||||
box = (rtgui_textbox_t*)parameter;
|
||||
/* set caret flag */
|
||||
if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
|
||||
box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
|
||||
else
|
||||
box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
|
||||
|
||||
/* re-darw textbox */
|
||||
rtgui_theme_draw_textbox(box);
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
@@ -54,7 +62,7 @@ static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
|
||||
_rtgui_textbox_caret_timeout, box);
|
||||
|
||||
box->line = box->line_begin = box->position = 0;
|
||||
box->type = RTGUI_TEXTBOX_SINGLE;
|
||||
box->flag = RTGUI_TEXTBOX_SINGLE;
|
||||
|
||||
/* allocate default line buffer */
|
||||
box->text = RT_NULL;
|
||||
@@ -131,7 +139,7 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb
|
||||
RT_ASSERT(box != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
if (event->type != RTGUI_KEYDOWN)
|
||||
if (event->type != RTGUI_KEYUP)
|
||||
return ;
|
||||
|
||||
length = rt_strlen((const char*)box->text);
|
||||
@@ -217,6 +225,9 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb
|
||||
}
|
||||
}
|
||||
|
||||
/* set caret to show */
|
||||
box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
|
||||
|
||||
/* re-draw text box */
|
||||
rtgui_theme_draw_textbox(box);
|
||||
}
|
||||
@@ -289,7 +300,6 @@ struct rtgui_textbox* rtgui_textbox_create(const char* text)
|
||||
rtgui_textbox_set_value(box, text);
|
||||
|
||||
rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect);
|
||||
box->font_width = rtgui_rect_width(rect);
|
||||
}
|
||||
|
||||
return box;
|
||||
|
||||
+33
-1
@@ -293,7 +293,7 @@ void rtgui_widget_unfocus(rtgui_widget_t *widget)
|
||||
|
||||
widget->flag &= ~RTGUI_WIDGET_FLAG_FOCUS;
|
||||
|
||||
if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUS(widget))
|
||||
if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUSED(widget))
|
||||
return;
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
@@ -480,6 +480,38 @@ void rtgui_widget_hide(rtgui_widget_t* widget)
|
||||
rtgui_widget_update_clip(widget->parent);
|
||||
}
|
||||
|
||||
rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget)
|
||||
{
|
||||
rtgui_widget_t* parent;
|
||||
|
||||
/* get parent widget */
|
||||
parent = widget->parent;
|
||||
while (parent->parent != RT_NULL && (RTGUI_WIDGET_FLAG(parent) & RTGUI_WIDGET_FLAG_TRANSPARENT))
|
||||
parent = parent->parent;
|
||||
|
||||
/* get parent's color */
|
||||
if (parent != RT_NULL)
|
||||
return RTGUI_WIDGET_FOREGROUND(parent);
|
||||
|
||||
return RTGUI_WIDGET_FOREGROUND(widget);
|
||||
}
|
||||
|
||||
rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget)
|
||||
{
|
||||
rtgui_widget_t* parent;
|
||||
|
||||
/* get parent widget */
|
||||
parent = widget->parent;
|
||||
while (parent->parent != RT_NULL && (RTGUI_WIDGET_FLAG(parent) & RTGUI_WIDGET_FLAG_TRANSPARENT))
|
||||
parent = parent->parent;
|
||||
|
||||
/* get parent's color */
|
||||
if (parent != RT_NULL)
|
||||
return RTGUI_WIDGET_BACKGROUND(parent);
|
||||
|
||||
return RTGUI_WIDGET_BACKGROUND(widget);
|
||||
}
|
||||
|
||||
void rtgui_widget_update(rtgui_widget_t* widget)
|
||||
{
|
||||
struct rtgui_event_paint paint;
|
||||
|
||||
Reference in new issue
Block a user