rtgui/widgets/notebook.c: use RTGUI_NOTEBOOK_TAB_WIDTH instead of magic number

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1812 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
chaos.proton@gmail.com 2011-11-28 06:47:15 +00:00
parent bff77ee86b
commit 41c6c37bc7
1 changed files with 10 additions and 5 deletions

View File

@ -3,6 +3,8 @@
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#include <rtgui/widgets/notebook.h> #include <rtgui/widgets/notebook.h>
#define RTGUI_NOTEBOOK_TAB_WIDTH 80
static void _rtgui_notebook_get_bar_rect(rtgui_notebook_t *notebook, struct rtgui_rect* rect); static void _rtgui_notebook_get_bar_rect(rtgui_notebook_t *notebook, struct rtgui_rect* rect);
static void _rtgui_notebook_get_page_rect(rtgui_notebook_t *notebook, struct rtgui_rect* rect); static void _rtgui_notebook_get_page_rect(rtgui_notebook_t *notebook, struct rtgui_rect* rect);
@ -55,7 +57,7 @@ static void _rtgui_notebook_ondraw(rtgui_notebook_t *notebook)
_rtgui_notebook_get_bar_rect(notebook, &rect); _rtgui_notebook_get_bar_rect(notebook, &rect);
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
rect.x2 = rect.x1 + 80; rect.x2 = rect.x1 + RTGUI_NOTEBOOK_TAB_WIDTH;
/* draw tab bar */ /* draw tab bar */
for (index = 0; index < notebook->count; index ++) for (index = 0; index < notebook->count; index ++)
{ {
@ -63,8 +65,10 @@ static void _rtgui_notebook_ondraw(rtgui_notebook_t *notebook)
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN); rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
else else
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX); rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
rtgui_dc_draw_text(dc, notebook->childs[index].title, &rect); rtgui_dc_draw_text(dc, notebook->childs[index].title, &rect);
rect.x1 += 80; rect.x2 += 80; rect.x1 += RTGUI_NOTEBOOK_TAB_WIDTH;
rect.x2 += RTGUI_NOTEBOOK_TAB_WIDTH;
} }
/* draw current tab */ /* draw current tab */
@ -85,7 +89,7 @@ static void _rtgui_notebook_onmouse(rtgui_notebook_t *notebook, struct rtgui_eve
int index; int index;
struct rtgui_dc* dc; struct rtgui_dc* dc;
index = (emouse->x - rect.x1) / 80; index = (emouse->x - rect.x1) / RTGUI_NOTEBOOK_TAB_WIDTH;
if (index < notebook->count) if (index < notebook->count)
{ {
/* update tab bar */ /* update tab bar */
@ -96,7 +100,7 @@ static void _rtgui_notebook_onmouse(rtgui_notebook_t *notebook, struct rtgui_eve
_rtgui_notebook_get_bar_rect(notebook, &rect); _rtgui_notebook_get_bar_rect(notebook, &rect);
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
rect.x2 = rect.x1 + 80; rect.x2 = rect.x1 + RTGUI_NOTEBOOK_TAB_WIDTH;
/* draw tab bar */ /* draw tab bar */
for (index = 0; index < notebook->count; index ++) for (index = 0; index < notebook->count; index ++)
{ {
@ -105,7 +109,8 @@ static void _rtgui_notebook_onmouse(rtgui_notebook_t *notebook, struct rtgui_eve
else else
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX); rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
rtgui_dc_draw_text(dc, notebook->childs[index].title, &rect); rtgui_dc_draw_text(dc, notebook->childs[index].title, &rect);
rect.x1 += 80; rect.x2 += 80; rect.x1 += RTGUI_NOTEBOOK_TAB_WIDTH;
rect.x2 += RTGUI_NOTEBOOK_TAB_WIDTH;
} }
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);