widget_element_frame.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "widget_element_i.h"
  2. typedef struct {
  3. uint8_t x;
  4. uint8_t y;
  5. uint8_t width;
  6. uint8_t height;
  7. uint8_t radius;
  8. } GuiFrameModel;
  9. static void gui_frame_draw(Canvas* canvas, WidgetElement* element) {
  10. furi_assert(canvas);
  11. furi_assert(element);
  12. GuiFrameModel* model = element->model;
  13. canvas_draw_rframe(canvas, model->x, model->y, model->width, model->height, model->radius);
  14. }
  15. static void gui_frame_free(WidgetElement* gui_frame) {
  16. furi_assert(gui_frame);
  17. free(gui_frame->model);
  18. free(gui_frame);
  19. }
  20. WidgetElement* widget_element_frame_create(
  21. uint8_t x,
  22. uint8_t y,
  23. uint8_t width,
  24. uint8_t height,
  25. uint8_t radius) {
  26. // Allocate and init model
  27. GuiFrameModel* model = malloc(sizeof(GuiFrameModel));
  28. model->x = x;
  29. model->y = y;
  30. model->width = width;
  31. model->height = height;
  32. model->radius = radius;
  33. // Allocate and init Element
  34. WidgetElement* gui_frame = malloc(sizeof(WidgetElement));
  35. gui_frame->parent = NULL;
  36. gui_frame->input = NULL;
  37. gui_frame->draw = gui_frame_draw;
  38. gui_frame->free = gui_frame_free;
  39. gui_frame->model = model;
  40. return gui_frame;
  41. }