Display SSD1306 for ESP32
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.

58 lines
2.6 KiB

  1. class Option{
  2. private:
  3. int sizex; //Defines the size it will occupy in the x axis (width), this value is gotten from the menu
  4. int sizey; //Defines the height of the option (this value is gotten from the menu it belongs to)
  5. String content; //Text of the option
  6. int pos; //Defines the position it has in the menu
  7. int textSpacing; //According to the height, defines the space for the text, so that it's vertically centered
  8. bool fill = false; //In case an option is not selected this should be false
  9. bool disp = false; //In case an option is not configured, it should be false and, thus hidden
  10. int destinationType; //Defines what the option leads to (another menu, graph, something else)
  11. int destinationIndex; //Defines where the option leads to (index of the destination)
  12. public:
  13. //Option(){}
  14. //Method to configure an option, all attributes are assigned, and disp is true, so the option can be displayed
  15. void configure(String content, int sizex, int sizey, int pos, int destinationType, int destinationIndex){
  16. this->sizex = sizex;
  17. this->sizey = sizey;
  18. this->content = content;
  19. this->pos = pos;
  20. this->destinationType = destinationType;
  21. this->destinationIndex = destinationIndex;
  22. this->disp = true;
  23. this->textSpacing = ((sizey - 7)/2) + 7;
  24. }
  25. int getDestinationType(){
  26. int destinationType = this->destinationType;
  27. return destinationType;
  28. }
  29. int getDestinationIndex(){
  30. int destinationIndex = this->destinationIndex;
  31. return destinationIndex;
  32. }
  33. //This method draws each option
  34. void drawopt(int page, int pos, int optPPage){
  35. if(this->disp){ //Checks if the option was configured and, as a result, is displayable
  36. if(this->pos == pos){ //If the position of the option corresponds to the position passed to the function, then it should be selected
  37. display.fillRect(0, (this->sizey)*(this->pos) + 1 - (page*optPPage*this->sizey), this->sizex, this->sizey, WHITE);
  38. display.setTextColor(SSD1306_BLACK);
  39. display.setCursor(5, (this->sizey)*(this->pos + 1) - (page*optPPage*this->sizey) - this->textSpacing);
  40. display.print(this->content);
  41. display.setTextColor(SSD1306_WHITE);
  42. }
  43. else{ //If the option is not selected, the rectangle containing it shouldn't be filled
  44. display.drawRect(0, (this->sizey)*(this->pos) + 1 - (page*optPPage*this->sizey), this->sizex, this->sizey, WHITE);
  45. display.setCursor(5, (this->sizey)*(this->pos + 1) - (page*optPPage*this->sizey) - this->textSpacing);
  46. display.print(this->content);
  47. }
  48. }
  49. }
  50. };