elements.c 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #include "elements.h"
  2. void elements_scrollbar(CanvasApi* canvas, uint8_t pos, uint8_t total) {
  3. uint8_t width = canvas->width(canvas);
  4. uint8_t height = canvas->height(canvas);
  5. // prevent overflows
  6. canvas->set_color(canvas, ColorWhite);
  7. canvas->draw_box(canvas, width - 3, 0, 3, height);
  8. // dot line
  9. canvas->set_color(canvas, ColorBlack);
  10. for(uint8_t i = 0; i < height; i += 2) {
  11. canvas->draw_dot(canvas, width - 2, i);
  12. }
  13. // Position block
  14. if(total) {
  15. uint8_t block_h = ((float)height) / total;
  16. canvas->draw_box(canvas, width - 3, block_h * pos, 3, block_h);
  17. }
  18. }
  19. void elements_frame(CanvasApi* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
  20. canvas->draw_line(canvas, x + 2, y, x + width - 2, y);
  21. canvas->draw_line(canvas, x + 1, y + height - 1, x + width, y + height - 1);
  22. canvas->draw_line(canvas, x + 2, y + height, x + width - 1, y + height);
  23. canvas->draw_line(canvas, x, y + 2, x, y + height - 2);
  24. canvas->draw_line(canvas, x + width - 1, y + 1, x + width - 1, y + height - 2);
  25. canvas->draw_line(canvas, x + width, y + 2, x + width, y + height - 2);
  26. canvas->draw_dot(canvas, x + 1, y + 1);
  27. }