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. /** Gets the type of a list box */
  26. #define RTGUI_LISTBOX_TYPE (rtgui_listbox_type_get())
  27. /** Casts the object to a filelist */
  28. #define RTGUI_LISTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LISTBOX_TYPE, rtgui_listbox_t))
  29. /** Checks if the object is a filelist box */
  30. #define RTGUI_IS_LISTBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_LISTBOX_TYPE))
  31. struct rtgui_listbox
  32. {
  33. struct rtgui_widget parent;
  34. /* widget private data */
  35. /* listbox item */
  36. const struct rtgui_listbox_item* items;
  37. /* item event handler */
  38. void (*on_item)(rtgui_widget_t *widgets, struct rtgui_event* event);
  39. /* total number of items */
  40. rt_uint16_t items_count;
  41. /* the number of item in a page */
  42. rt_uint16_t page_items;
  43. /* current item */
  44. rt_int16_t current_item;
  45. };
  46. typedef struct rtgui_listbox rtgui_listbox_t;
  47. typedef void (*rtgui_onitem_func_t)(struct rtgui_widget* widget, rtgui_event_t *event);
  48. rtgui_type_t *rtgui_listbox_type_get(void);
  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. #endif