ThingPulse / esp8266-oled-ssd1306

Driver for the SSD1306 and SH1106 based 128x64, 128x32, 64x48 pixel OLED display running on ESP8266/ESP32
https://thingpulse.com
Other
2.02k stars 640 forks source link

OverLays are written on top of each other #59

Closed nicof38 closed 8 years ago

nicof38 commented 8 years ago

While using the SSD1306UiDemo, I've modified this one in order to have:

`void msOverlay1(OLEDDisplay display, OLEDDisplayUiState state) { display->setTextAlignment(TEXT_ALIGN_RIGHT); display->setFont(ArialMT_Plain_10); display->drawString(128, 0, String(millis())); }

void msOverlay2(OLEDDisplay display, OLEDDisplayUiState state) { display->setTextAlignment(TEXT_ALIGN_RIGHT); display->setFont(ArialMT_Plain_10); display->drawString(128, 0, String("TESTTESTTEST")); }`

Then:

// Overlays are statically drawn on top of a frame eg. a clock OverlayCallback overlays[] = { msOverlay1,msOverlay2 }; int overlaysCount = 2;

Running the example with these modifications, and you can see that "TESTTESTTEST" is written on top of the current milliseconds.

FWeinb commented 8 years ago

That is the expected behaviour. What is your expectations with doing this? A overlay is a way to define frame independent data on the display (like a clock). If you draw to the same pixels they sure overwrite what is currently there.

nicof38 commented 8 years ago

So in this case what is the aim of having multiple overlay defined? It does not work the same way as frames? Frames does not overwrite on each others so I was expecting to have the same behavior for multiple overlays.

One overlay should only overlay frames but I would not expect each overlay to overlay any others.

Anyway if it is the way it is designed, how should we use the multiple overlays callback in order to have something readable?

Thanks

FWeinb commented 8 years ago

In an overlay you can draw anywhere on the display. You can do something like this:

void msOverlay2(OLEDDisplay display, OLEDDisplayUiState state) {
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(0, 0, String("TESTTESTTEST"));
}

That would draw the string "TESTTESTTEST" in the upper left corner

nicof38 commented 8 years ago

Yes, this is what I've done next. Anyway still surprised that 2 overlays callback can overwrite on each others whereas frames clear everything between.

What should be the best option to update information on an overlay area (with different information type, not a timestamp for example)? Should I add a third overlay in order to clear the selected area ? Should i use an empty graphic to do so ?

FWeinb commented 8 years ago

Sorry but I don't understand what you would like to achieve. Maybe @squix78 can help? Overlays are information that are rendered always (even in a frame transition) so they can be used for status indicators like wifi signals or time, we choose to implement the ability to add more overlays so one can separate different aspects of the ui (not everyone want's to e.g. display an wifi signal indicator).

nicof38 commented 8 years ago

OK, so based on your latest explanation, I think I get it.

Adding more overlays does not behave like adding multiple frames. Every defined overlays are rendered all the time, and that is why they can interfere on each others.

Maybe you should add the way it has to be used with multiple overlays in the UI demo code ?

FWeinb commented 8 years ago

Yeah, we could really improve on example code for this library.

hallard commented 8 years ago

Moved to #69