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.

85 lines
2.7 KiB

  1. class Menu{ //ContentType (0)
  2. private:
  3. int sizex; //X size for each option in the menu
  4. int sizey; //Y size of each option in the menu
  5. int options = 0; //This indicates the number of options created
  6. int pos = 0; //This indicates the position of the cursor
  7. int page = 0; //If the menu is too long, this indicates the page that is being displayed
  8. Option opt[MAX_OPTIONS];
  9. int optPPage;
  10. int previousScreen = 0;
  11. int previousContentType = 0;
  12. public:
  13. void configure(int sizex, int sizey){ //This method configures the menu created from Screen
  14. this->sizex = sizex;
  15. this->sizey = sizey;
  16. this->optPPage = DISP_HEIGHT / this->sizey;
  17. }
  18. //The following method is used to created an option for the menu
  19. void createOption(String content, int destinationType, int destinationIndex){
  20. //The option takes the place in the array defined by the options number variable (options), which is later increased.
  21. this->opt[this->options].configure(content, this->sizex, this->sizey, this->options++, destinationType, destinationIndex);
  22. }
  23. int extractDestinationType(){
  24. int destinationType = this->opt[this->pos].getDestinationType();
  25. return destinationType;
  26. }
  27. int extractDestinationIndex(){
  28. int destinationIndex = this->opt[this->pos].getDestinationIndex();
  29. return destinationIndex;
  30. }
  31. //The following method draws the whole menu by drawing every option configured within it
  32. void drawMenu(){
  33. display.clearDisplay();
  34. this->page = pos/this->optPPage; //The current page is obtained by dividing the position by the number of options per page (only integer)
  35. for(int i = 0; i < options; i++){
  36. this->opt[i].drawopt(this->page, this->pos, this->optPPage);
  37. }
  38. display.display();
  39. }
  40. //Methods used by Screen
  41. int extractPos(){ //Gets the current position of the cursor
  42. return(this->pos);
  43. }
  44. int extractOptNumber(){ //Gets the number of options in the menu
  45. return(this->options);
  46. }
  47. void increasePos(){ //Increases the position of the cursor
  48. this->pos++;
  49. }
  50. void decreasePos(){ //Decreases the position of the cursor
  51. this->pos--;
  52. }
  53. //Both of the following methods store the values of the previous screen passed as parameters by Screen
  54. void setPreviousScreen(int prev){
  55. this->previousScreen = prev;
  56. }
  57. void setPreviousContentType(int prev){
  58. this->previousContentType = prev;
  59. }
  60. //Both of the following methods retrieve the values of the screen previous to the menu containing these data.
  61. int getPreviousScreen(){
  62. int prev = this->previousScreen;
  63. return prev;
  64. }
  65. int getPreviousContentType(){
  66. int prev = this->previousContentType;
  67. return prev;
  68. }
  69. };