diff options
Diffstat (limited to 'components/rtgui/widgets')
| -rw-r--r-- | components/rtgui/widgets/listbox.c | 18 | ||||
| -rw-r--r-- | components/rtgui/widgets/listctrl.c | 2 | ||||
| -rw-r--r-- | components/rtgui/widgets/widget.c | 1 |
3 files changed, 14 insertions, 7 deletions
diff --git a/components/rtgui/widgets/listbox.c b/components/rtgui/widgets/listbox.c index 53921d9032..29fd16a9b5 100644 --- a/components/rtgui/widgets/listbox.c +++ b/components/rtgui/widgets/listbox.c @@ -24,7 +24,7 @@ static void _rtgui_listbox_constructor(struct rtgui_listbox *box) RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- box->current_item = 0;
+ box->current_item = -1;
box->items_count = 0;
box->page_items = 1;
box->on_item = 0;
@@ -71,7 +71,11 @@ void rtgui_listbox_ondraw(struct rtgui_listbox* box) item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
/* get current page */
- page_index = (box->current_item / box->page_items) * box->page_items;
+ if (box->current_item == -1)
+ page_index = 0;
+ else
+ page_index = (box->current_item / box->page_items) * box->page_items;
+
for (index = 0; index < box->page_items; index ++)
{
if (page_index + index >= box->items_count) break;
@@ -103,13 +107,13 @@ void rtgui_listbox_ondraw(struct rtgui_listbox* box) rtgui_dc_end_drawing(dc);
}
-void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_uint16_t old_item)
+static void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_int16_t old_item)
{
struct rtgui_dc* dc;
const struct rtgui_listbox_item* item;
rtgui_rect_t rect, item_rect;
- if (old_item/box->page_items != box->current_item/box->page_items)
+ if ((old_item == -1) || (old_item/box->page_items != box->current_item/box->page_items))
{
/* it's not a same page, update all */
rtgui_widget_update(RTGUI_WIDGET(box));
@@ -258,9 +262,11 @@ rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_ struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if ((ekbd->type == RTGUI_KEYDOWN) && (box->items_count > 0))
{
- rt_uint16_t old_item;
+ rt_int16_t old_item;
+ if (box->current_item == -1) return RT_FALSE;
old_item = box->current_item;
+
switch (ekbd->key)
{
case RTGUIK_LEFT:
@@ -343,7 +349,7 @@ void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* it box->items = items;
box->items_count = count;
- box->current_item = 0;
+ box->current_item = -1;
rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
box->page_items = rtgui_rect_height(rect) / (2 + rtgui_theme_get_selected_height());
diff --git a/components/rtgui/widgets/listctrl.c b/components/rtgui/widgets/listctrl.c index 10087dc8d1..29b7fca013 100644 --- a/components/rtgui/widgets/listctrl.c +++ b/components/rtgui/widgets/listctrl.c @@ -24,7 +24,7 @@ static void _rtgui_listctrl_constructor(struct rtgui_listctrl *ctrl) RTGUI_WIDGET(ctrl)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- ctrl->current_item = 0;
+ ctrl->current_item = -1;
ctrl->items_count = 0;
ctrl->page_items = 0;
ctrl->on_item = 0;
diff --git a/components/rtgui/widgets/widget.c b/components/rtgui/widgets/widget.c index ecdabf5bdc..304e59b86c 100644 --- a/components/rtgui/widgets/widget.c +++ b/components/rtgui/widgets/widget.c @@ -32,6 +32,7 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget) widget->gc.foreground = default_foreground; widget->gc.background = default_background; widget->gc.font = rtgui_font_default(); + widget->gc.textstyle = RTGUI_TEXTSTYLE_NORMAL; widget->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP; #ifndef RTGUI_USING_SMALL_SIZE widget->align = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP; |
