epd-waveshare
epd-waveshare copied to clipboard
When rotating displays dimensions are not getting updated
If you call display.set_rotation(DisplayRotation::Rotate90);
or display.set_rotation(DisplayRotation::Rotate270);
the display's dimensions (WIDTH/HEIGHT) should be swapped so that embedded-graphics
text alignment features can work properly. As things are right now, if you rotate the display 90° or 270° only left-aligned text will display properly.
Example of how another embedded-graphics
crate handles dimensions after rotation:
https://github.com/jamwaffles/ssd1306/blob/master/src/lib.rs#L279
...and:
https://github.com/jamwaffles/ssd1306/blob/master/src/mode/buffered_graphics.rs#L237
Turns out it was pretty easy to fix this... Just a bit tedious (had to make small changes to graphics.rs
for every supported display). Here's the confirmation that it works (this display has: display.set_rotation(DisplayRotation::Rotate270);
applied)
Before:
After:
Yep just wanted to create this exact same issue.. and found this one.. :)
Fixed it for my display as follows: (and works fine now with 'embedded graphics' and 'embedded layout')
impl OriginDimensions for Display2in13 {
fn size(&self) -> Size {
match self.rotation() {
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => Size::new(WIDTH, HEIGHT),
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => Size::new(HEIGHT, WIDTH),
}
}
}
~If needed/wanted I could make a PR for this change~ (missed the already outstanding PR)
Ps. I see there's quite some code duplication in this library, also the screen/controller code is not very well separated either. I'd say some major (probably API-breaking) refactoring are in order.. (maybe even an name change, as this is really not about supporting Waveshare EPD's only..)
CAme here for the same thing!