listbox.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * File : listbox.h
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2010, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-01-06 Bernard first version
  13. */
  14. #ifndef __RTGUI_LISTBOX_H__
  15. #define __RTGUI_LISTBOX_H__
  16. #include <rtgui/rtgui.h>
  17. #include <rtgui/image.h>
  18. #include <rtgui/rtgui_system.h>
  19. #include <rtgui/widgets/widget.h>
  20. struct rtgui_listbox_item
  21. {
  22. char* name;
  23. rtgui_image_t *image;
  24. };
  25. DECLARE_CLASS_TYPE(listbox);
  26. /** Gets the type of a list box */
  27. #define RTGUI_LISTBOX_TYPE (RTGUI_TYPE(listbox))
  28. /** Casts the object to a filelist */
  29. #define RTGUI_LISTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LISTBOX_TYPE, rtgui_listbox_t))
  30. /** Checks if the object is a filelist box */
  31. #define RTGUI_IS_LISTBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_LISTBOX_TYPE))
  32. struct rtgui_listbox
  33. {
  34. struct rtgui_widget parent;
  35. /* widget private data */
  36. /* listbox item */
  37. const struct rtgui_listbox_item* items;
  38. /* item event handler */
  39. void (*on_item)(rtgui_widget_t *widgets, struct rtgui_event* event);
  40. /* total number of items */
  41. rt_uint16_t items_count;
  42. /* the number of item in a page */
  43. rt_uint16_t page_items;
  44. /* current item */
  45. rt_int16_t current_item;
  46. };
  47. typedef struct rtgui_listbox rtgui_listbox_t;
  48. typedef void (*rtgui_onitem_func_t)(struct rtgui_widget* widget, rtgui_event_t *event);
  49. rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt_uint16_t count,
  50. rtgui_rect_t *rect);
  51. void rtgui_listbox_destroy(rtgui_listbox_t* box);
  52. rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
  53. void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_onitem_func_t func);
  54. void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* items, rt_uint16_t count);
  55. void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index);
  56. #endif