S&B Volcano vaporizer remote control with Pi Pico W
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * textbox.c
  3. *
  4. * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include <string.h>
  19. #include "config.h"
  20. #include "lcd.h"
  21. #include "text.h"
  22. #include "textbox.h"
  23. int16_t text_box(const char *s, bool centered,
  24. const char *fontname,
  25. uint16_t x_off, uint16_t width,
  26. uint16_t y_off, uint16_t height,
  27. int16_t y_text_off) {
  28. static struct text_font font = {
  29. .fontname = "",
  30. .font = NULL,
  31. };
  32. if ((font.font == NULL) || (strcmp(font.fontname, fontname) != 0)) {
  33. font.fontname = fontname;
  34. text_prepare_font(&font);
  35. }
  36. struct text_conf text = {
  37. .text = s,
  38. .x = x_off,
  39. .y = y_off,
  40. .y_text_off = y_text_off,
  41. .justify = false,
  42. .alignment = centered ? MF_ALIGN_CENTER : MF_ALIGN_LEFT,
  43. .width = width,
  44. .height = height,
  45. .margin = 2,
  46. .fg = LCD_WHITE,
  47. .bg = TEXT_BG_NONE,
  48. .font = &font,
  49. };
  50. lcd_write_rect(x_off, y_off,
  51. x_off + width - 1,
  52. y_off + height - 1,
  53. LCD_BLACK);
  54. return text_draw(&text);
  55. }