caemor / epd-waveshare

Drivers for various EPDs from Waveshare
ISC License
221 stars 131 forks source link

Cannot render with MonoTextStyle #194

Open abergmeier opened 7 months ago

abergmeier commented 7 months ago

I have the following code:


    let display = Display7in5::default();
    let char_style = MonoTextStyleBuilder::new()
        .font(&embedded_graphics::mono_font::ascii::FONT_10X20)
        .text_color(BinaryColor::On)
        .background_color(BinaryColor::Off)
        .build();

    let text = Text::new("Foo", (10, 10).into(), char_style);
    text.draw(&mut display).unwrap();

which does not compile due to a BinaryColor <> Color mismatch.

diajowe commented 4 months ago

Can confirm, it does not compile with the following error:

error[E0277]: the trait bound `epd_waveshare::epd7in5_v2::Display7in5: DrawTarget` is not satisfied
   --> src/main.rs:107:11
    |
107 | text.draw(&mut display).unwrap();
    |      ---- ^^^^^^^^^^^^ the trait `DrawTarget` is not implemented for `epd_waveshare::epd7in5_v2::Display7in5`
    |      |
    |      required by a bound introduced by this call
    |
    = help: the following other types implement trait `DrawTarget`:
              mono_font::draw_target::MonoFontDrawTarget<'_, T, mono_font::draw_target::Foreground<<T as DrawTarget>::Color>>
              mono_font::draw_target::MonoFontDrawTarget<'_, T, mono_font::draw_target::Background<<T as DrawTarget>::Color>>
              mono_font::draw_target::MonoFontDrawTarget<'_, T, mono_font::draw_target::Both<<T as DrawTarget>::Color>>
              Clipped<'_, T>
              ColorConverted<'_, T, C>
              Cropped<'_, T>
              embedded_graphics::draw_target::Translated<'_, T>
              Framebuffer<C, RawU1, BO, WIDTH, HEIGHT, N>
            and 10 others
note: required by a bound in `embedded_graphics::Drawable::draw`
   --> /home/jowe/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embedded-graphics-core-0.4.0/src/drawable.rs:106:12
    |
104 |     fn draw<D>(&self, target: &mut D) -> Result<Self::Output, D::Error>
    |        ---- required by a bound in this associated function
105 |     where
106 |         D: DrawTarget<Color = Self::Color>;
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Drawable::draw`

In generally, I've tried this with Display4in2, and does not compile either. The relevant crates I used are:

epd-waveshare = {version="0.5.0", features=["graphics"]}
embedded-hal = "0.2.4"
embedded-hal-compat = "0.13.0"
embedded-graphics = "0.8.1"
diajowe commented 4 months ago

By digging a bit, I found PR #196 which seems to fix this problem. One can add .color_converted() to the parameter in the draw()-function. This function seems to exist in version 0.5.0 already, but is still not working in this case outside of that PR.