epd-waveshare icon indicating copy to clipboard operation
epd-waveshare copied to clipboard

When rotating displays dimensions are not getting updated

Open riskable opened this issue 2 years ago • 4 comments

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.

riskable avatar Apr 04 '22 17:04 riskable

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

riskable avatar Apr 04 '22 17:04 riskable

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:

PXL_20220404_163738183

After:

PXL_20220404_184400585

riskable avatar Apr 04 '22 18:04 riskable

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..)

eflukx avatar Apr 16 '22 12:04 eflukx

CAme here for the same thing!

jquesada2016 avatar May 12 '22 20:05 jquesada2016