adafruit / Adafruit-ST7735-Library

This is a library for the Adafruit 1.8" SPI display http://www.adafruit.com/products/358 and http://www.adafruit.com/products/618
https://learn.adafruit.com/1-8-tft-display
565 stars 305 forks source link

Added constructor to supply screen resolution #108

Closed bfiset closed 4 years ago

bfiset commented 4 years ago

We are working with a LCD of 240x240 that uses ST7789 controller.

ladyada commented 4 years ago

wont merge use https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/examples/graphicstest_hallowing_m4/graphicstest_hallowing_m4.ino

bfiset commented 4 years ago

wont merge use https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/examples/graphicstest_hallowing_m4/graphicstest_hallowing_m4.ino

I don't think this example is 100% working. Problem is that 'HEIGHT' and 'WIDTH' members of Adafruit_GFX are only assigned on construction and are used throughout the library to do screen rotation and boundary checking.

By using any supplied Adafruit_ST7789 constructors, which invariably set WIDTH and HEIGHT to 320 and 240 respectively, many functions will reference the WIDTH member and with it being 320, it will result in unexpected behaviour, even when calling the init() method with the correct resolution.

I have been having this exact issue, hence why the pull request. I am writing a very long string and with text wrap enabled and with WIDTH being set to 320, there are 80 pixels that are drawn at the left side of the screen , one line below because the lib expect 320 pixels wide but the LCD controller just jumps to the line below when it reaches 240 pixels. It suspect a similar result would happen when drawing a primitive that is partially out of bound of the screen, width-wise. Also, using any method that draws on the entire screen (like fillRect) would result in performance penalty due to more pixel being sent than what's required.

In any case, not having this constructor means I will create my own ST7789 interface class as the one supplied in this repo is mostly unusable for a screen that is of a different resolution than 320x240.

ladyada commented 4 years ago

hi we use this repo for 240x240 screens all the time so it is usable. you could call width() to get the true width - any bug fixes like those are appreciated.