Bodmer / TFT_eSPI

Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips
Other
3.69k stars 1.06k forks source link

Buttons from the previous page, on the new menu page. #3127

Closed Daevid8 closed 7 months ago

Daevid8 commented 7 months ago

Hello Bodmer. I have a problem with the TFT_eSPI library, more specifically with the menu display. Based on the example from the library, I wanted to create a menu. Everything went very well thanks to your library, for which I thank you very much, but I have a problem with reading the touch buttons on individual pages. More precisely, the point is that after switching to the next page in the menu, all buttons from previous pages can still be pressed as if in the background. They are not visible, but they can be pressed, which unfortunately causes a big problem because the menu buttons are in the same places. I hope you can help me, thank you in advance. My touch display is 2.8" TFT ST7789. Sorry for any language errors. I have to use a translator because English is not my language. Below is a fragment of the code.

void loop() {

  //uruchomienie akcja.attach
  akcja.process();

  // Pobierz dane z DS1302
  t = rtc.getTime();

  uint16_t t_x = 0, t_y = 0;              // współrzędne pulsacji
  bool pressed = tft.getTouch(&t_x, &t_y);  // prawda po naciśnięciu

  // Sprawdź, czy kliknąłeś obszar przycisku
  for (uint8_t b = 0; b < totalButtonNumber; b++) {
    if (pressed && key[b].contains(t_x, t_y)) {
      key[b].press(true);
      Serial.print(t_x);
      Serial.print(",");
      Serial.println(t_y);
    } else {
      key[b].press(false);
    }
  }

  // Akcja po naciśnięciu przycisku
  for (uint8_t b = 0; b < totalButtonNumber; b++) {

    if (key[b].justReleased()) {
      key[b].drawButton();  // przerysuj po wydaniu

      switch (b) {
        case 0:
          //ekran1
          break;
        case 1:
          //ekran2
          break;
        case 2:
          //ekran3
          break;
        case 3:
          //ekran4
          break;
        case 4:
          //
          break;
        case 5:
          //
          break;
        case 6:
          //
          break;
        case 7:
          //
          break;
        case 8:
          //
          break;
        default:
          delay(1);
          // sprawozdania
          return;
      }
    }
    if (key[b].justPressed()) {
      key[b].drawButton(true);  // zmienia kolor przycisku po naciśnięciu
      delay(10);                
    }
  }
}
Bodmer commented 7 months ago

You need to define buttons for each page or menu. The sketch must check which buttons to respond to depending on the page or menu currently on the screen. There are no functions in the library to do this and it must be managed by the sketch.