ropg / M5Core2

M5Core2 Arduino Library
MIT License
7 stars 1 forks source link

One last (trivial) feature request #65

Closed vkichline closed 3 years ago

vkichline commented 3 years ago

If you add an unused userData field to the Zone class the size of a void* or int32, users could utilize it for all kinds of things. Examples:

If there's a userData field, you can build all kinds of things without subclassing every single button. It makes it easy, and I've availed myself of this technique in old MacOS programs countless times. That OS often included user fields like this.

ropg commented 3 years ago

uint16_t ?

vkichline commented 3 years ago

Well, a larger variable would allow you to store a pointer. Then you can use the 32 bits for small data, or allocate a block of memory and store its pointer in userData. I found I would often start with the first approach and later change to the second as my needs grew. In MacOS, Windows had a userData where you could store a handle to all kinds of context. It made programming really easy. Of course, that was before OOP; now the purists would say "Subclass everything!" but Arduino is a beginner-rich environment, and it seems like the "keep a pointer" (or a reference) gist would be super handy. This could be highlighted in an example program, but the clock has probably run out on that...

ropg commented 3 years ago

Things can always be added, but I'd like to get M5Stack to take it on board before adding too much.For the next day or so, let's concentrate on getting what we have rock-solid, and then I'll write the PR sometime tomorrow or early day after.

As for pointers: One could make a struct with whatever auxiliary data and have this be the index in an array of those. (That would be easier to explain than storing a pointer, IMHO). Unless anyone needs more than 64k buttons. uint16_t I say...

I was also thinking (and rejected until this gets some actual use with all the complexity it has already, to make a ButtonGroup class, that you can add buttons to. And then you could have that have an addHandler as well, getting all events for that group of buttons. All that would be needed is one more pointer.

But then it hit me... Dude... This is a device with a 2 inch screen. Stop already! For now ... anyway ... :)

(I'd love for some other TFT_eSPI users to use M5Button on their hardware. Made it easy enough..)

vkichline commented 3 years ago

I discussed it briefly with UT2UH but he replied:

Hi! The touch interface is not for my use cases - I need backlit buttons etc. so Core2 is not the priority but ESP-IDF is. That is why I am looking at LovyanGFX and Chimera-Core. It would be nice to have M5ez under IDF as well. Another reason to look at Chimera as an example are dirty cheap K210 boards and modules to build M5Stack-like but more powerful devices. Of course using M5ez UI. ) Chimera-Core looks very interesting to unjail M5ez from ESP32 and Arduino Core.