demo_view_label.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "demo_view.h"
  2. #include <rtgui/widgets/label.h>
  3. rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
  4. {
  5. rtgui_rect_t rect;
  6. rtgui_view_t* view;
  7. rtgui_label_t* label;
  8. rtgui_font_t* font;
  9. /* create a demo view */
  10. view = demo_view(workbench, "Label View");
  11. demo_view_get_rect(view, &rect);
  12. rect.x1 += 5; rect.x2 -= 5;
  13. rect.y1 += 5; rect.y2 = rect.y1 + 20;
  14. label = rtgui_label_create("Red Left");
  15. RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_LEFT;
  16. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = red;
  17. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  18. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  19. demo_view_get_rect(view, &rect);
  20. rect.x1 += 5; rect.x2 -= 5;
  21. rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20;
  22. label = rtgui_label_create("Blue Right");
  23. RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_RIGHT;
  24. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue;
  25. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  26. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  27. demo_view_get_rect(view, &rect);
  28. rect.x1 += 5; rect.x2 -= 5;
  29. rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20;
  30. label = rtgui_label_create("Green Center");
  31. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = green;
  32. RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL;
  33. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  34. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  35. demo_view_get_rect(view, &rect);
  36. rect.x1 += 5; rect.x2 -= 5;
  37. rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
  38. label = rtgui_label_create("12 font");
  39. font = rtgui_font_refer("asc", 12);
  40. RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
  41. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  42. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  43. demo_view_get_rect(view, &rect);
  44. rect.x1 += 5;
  45. rect.y1 += 5 + 25 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
  46. label = rtgui_label_create("16 font");
  47. font = rtgui_font_refer("asc", 16);
  48. RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
  49. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  50. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  51. return view;
  52. }