Help Shortening "Display" code (n00b help)

I’ve purchased a TTGO to get familiar with the Display settings for ESPHOME which is very useful has it has some integrated buttons too.

Couple of things I’m trying to get better at

  1. Avoid “repeating” the same code (as I use same for each screen, just amendments)
  2. Screen a little more “pleasant” (a lot of overlapping etc)

The first thing is, I have the button action dependant on which screen I’m on…
Is there a better way to do this? Rather than having an ‘IF’ for each screen?

  - platform: gpio
    pin:
      number: GPIO35
      inverted: true
    name: "T-Display Button Input 1"
    id: tdisplay_button_input_1
    on_press:
    - if:
        condition:
          display.is_displaying_page:
            id: my_display
            page_id: page3
        then:
          - homeassistant.service:
              service: light.toggle
              data:
                entity_id: light.j_office
    - if:
        condition:
          display.is_displaying_page:
            id: my_display
            page_id: page4
        then:
          - homeassistant.service:
              service: light.toggle
              data:
                entity_id: light.office_2

Now the horrible part. Obviously I got one screen working, then just copied the code and edited for each page.
Surely there is a better way to reference the whole thing and return it once?
Just not sure how the service to toggle the lights will be handled…

      - id: page3
        lambda: |-
          it.rectangle(0,  0, it.get_width(), it.get_height(), id(my_blue));
          it.rectangle(0, 40, it.get_width(), it.get_height(), id(my_blue));   // header bar
          it.rectangle(0, 80, it.get_width(), it.get_height(), id(my_blue));   // header bar          

          it.rectangle(0, 40, it.get_width(), 40, id(my_red));
          
          
          it.print(5, 15, id(helvetica_12), "Light automations running...");
          if (id(light_auto_running).state) {
            it.image(140, 5, id(lamp_on));
          }
          else {
            it.image(140, 5, id(lamp_off));
          }
          
          it.print(5, 45, id(helvetica_12), "J Light...");
          if (id(jbedroom_light).state) {
            it.image(140, 45, id(lamp_on));
          }
          else {
            it.image(140, 45, id(lamp_off));
          }
          
          it.print(5, 85, id(helvetica_12), "Landing Light...");
          if (id(landing_light).state) {
            it.image(140, 85, id(lamp_on));
          }
          else {
            it.image(140, 85, id(lamp_off));
          }
      - id: page4
        lambda: |-
          it.rectangle(0,  0, it.get_width(), it.get_height(), id(my_blue));
          it.rectangle(0, 40, it.get_width(), it.get_height(), id(my_blue));   // header bar
          it.rectangle(0, 80, it.get_width(), it.get_height(), id(my_blue));   // header bar          

          it.rectangle(0, 80, it.get_width(), 40, id(my_red));
          
          
          it.print(5, 15, id(helvetica_12), "Light automations running...");
          if (id(light_auto_running).state) {
            it.image(140, 5, id(lamp_on));
          }
          else {
            it.image(140, 5, id(lamp_off));
          }
          
          it.print(5, 45, id(helvetica_12), "J Light...");
          if (id(jbedroom_light).state) {
            it.image(140, 45, id(lamp_on));
          }
          else {
            it.image(140, 45, id(lamp_off));
          }
          
          it.print(5, 85, id(helvetica_12), "Landing Light...");
          if (id(landing_light).state) {
            it.image(140, 85, id(lamp_on));
          }
          else {
            it.image(140, 85, id(lamp_off));
          }