elements.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "elements.h"
  2. #include "canvas_i.h"
  3. #include <furi.h>
  4. #include <string.h>
  5. #include <m-string.h>
  6. void elements_scrollbar(Canvas* canvas, uint8_t pos, uint8_t total) {
  7. furi_assert(canvas);
  8. uint8_t width = canvas_width(canvas);
  9. uint8_t height = canvas_height(canvas);
  10. // prevent overflows
  11. canvas_set_color(canvas, ColorWhite);
  12. canvas_draw_box(canvas, width - 3, 0, 3, height);
  13. // dot line
  14. canvas_set_color(canvas, ColorBlack);
  15. for(uint8_t i = 0; i < height; i += 2) {
  16. canvas_draw_dot(canvas, width - 2, i);
  17. }
  18. // Position block
  19. if(total) {
  20. uint8_t block_h = ((float)height) / total;
  21. canvas_draw_box(canvas, width - 3, block_h * pos, 3, block_h);
  22. }
  23. }
  24. void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
  25. furi_assert(canvas);
  26. canvas_draw_line(canvas, x + 2, y, x + width - 2, y);
  27. canvas_draw_line(canvas, x + 1, y + height - 1, x + width, y + height - 1);
  28. canvas_draw_line(canvas, x + 2, y + height, x + width - 1, y + height);
  29. canvas_draw_line(canvas, x, y + 2, x, y + height - 2);
  30. canvas_draw_line(canvas, x + width - 1, y + 1, x + width - 1, y + height - 2);
  31. canvas_draw_line(canvas, x + width, y + 2, x + width, y + height - 2);
  32. canvas_draw_dot(canvas, x + 1, y + 1);
  33. }
  34. void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, char* text) {
  35. furi_assert(canvas);
  36. furi_assert(text);
  37. uint8_t font_height = canvas_current_font_height(canvas);
  38. string_t str;
  39. string_init(str);
  40. char* start = text;
  41. char* end;
  42. do {
  43. end = strchr(start, '\n');
  44. if(end) {
  45. string_set_strn(str, start, end - start);
  46. } else {
  47. string_set_str(str, start);
  48. }
  49. canvas_draw_str(canvas, x, y, string_get_cstr(str));
  50. start = end + 1;
  51. y += font_height;
  52. } while(end);
  53. string_clear(str);
  54. }