Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix width and height returned by size() when displays are rotated 90° and 270° #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

riskable
Copy link

@riskable riskable commented Apr 4, 2022

This PR fixes #104 where embedded-graphics text alignment features were not working because the size() method wasn't taking display rotation into account.

…d) when rotating displays 90 and 270 degrees.
@auto-assign auto-assign bot requested a review from caemor April 4, 2022 18:54
@@ -39,7 +39,8 @@ impl DrawTarget for Display1in54 {

impl OriginDimensions for Display1in54 {
fn size(&self) -> Size {
Size::new(WIDTH, HEIGHT)
let (w, h) = self.dimensions();
Size::new(w.into(), h.into())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intos are not needed since w and h are already u32.

@caemor
Copy link
Owner

caemor commented Apr 5, 2022

Thanks for the PR.

If you have the time and interest, this could be improved even more by adding a default implementation for the get_dimensions which the help of associated constants (https://dev-doc.rust-lang.org/beta/edition-guide/rust-2018/trait-system/associated-constants.html) similar to what you have linked in the ssd1306 display.

@riskable
Copy link
Author

riskable commented Apr 6, 2022

@caemor Should I also change functions like update_partial_frame() to take the rotation into account so that the x and y variables get swapped if it's 270° or 90°?

@caemor
Copy link
Owner

caemor commented Apr 10, 2022

Sure that would be great!

@caemor caemor assigned riskable and unassigned caemor Aug 1, 2022
@caemor caemor mentioned this pull request Dec 7, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When rotating displays dimensions are not getting updated
2 participants