iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
24.26k stars 1.13k forks source link

Error when setting a font in the settings of my application #2157

Closed JustANormalProgramm3r closed 9 months ago

JustANormalProgramm3r commented 9 months ago

Is there an existing issue for this?

Is this issue related to iced?

What happened?

I'm trying to set a default font for my application but i'm getting the error: expected `Font`, found `Option<&[u8; 289624]> This is the code causing the error:

let setting = Setting {
    window: window::Settings {
        size: (800,600),
        resizable: true,
        ..window::Settings::default()
    },
    default_font: Some(include_bytes!("../fonts/FiraCode-Regular.ttf")), <-- error here
    antialiasing: true,
    ..Settings::default()
};

### What is the expected behavior?

No error should occur

### Version

crates.io release

### Operating System

Linux

### Do you have any log output?

```shell
Compiling notes-app v0.1.0 (/home/gksx/Desktop/notes-app)
error[E0308]: mismatched types
  --> src/main.rs:11:23
   |
11 |         default_font: Some(include_bytes!("../fonts/FiraCode-Regular.ttf")),
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Font`, found `Option<&[u8; 289624]>`
   |
   = note: expected struct `Font`
                found enum `Option<&[u8; 289624]>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `notes-app` (bin "notes-app") due to previous error
hecrj commented 9 months ago

This is a compiler error, not a bug!

The compiler is telling you that Settings expects a Font, not an Option of bytes.

Load your font with font::load and provide Font::with_name("Fira Code") as the default_font.