#![allow(unused_must_use)]

use iced::{
    Center, Element, Font, Length, Task, font,
    widget::{column, row, text},
};
use iced_fonts::generate_icon_functions;

// Generated by the macro below.
use iced_aw_font::{COUNT, cancel, down_open, left_open, ok, right_open, up_open};

// What we need to bootstrap the library to generate and use the font.
pub const ICED_AW_FONT_BYTES: &[u8] = include_bytes!("../fonts/iced_aw.ttf");
pub const ICED_AW_FONT: Font = Font::with_name("iced_aw");
// 1st parameter &str font path
// 2nd parameter literal name for the module the macro creates.
// 3rd parameter literal name of the font created one line above.
// 4th parameter literal name of the type of iced's text shaping you need. If unsure set to basic to avoid
// the cost of advanced shaping.
// 5th Optional parameter &str of where documenation exists for this font.
generate_icon_functions!("fonts/iced_aw.ttf", iced_aw_font, ICED_AW_FONT, "basic");

pub fn main() -> iced::Result {
    iced::application(App::new, App::update, App::view)
        .title("Custom Font")
        .run()
}

#[derive(Default)]
struct App {}

#[derive(Debug, Clone, Copy)]
enum Message {
    FontLoaded(Result<(), font::Error>),
}

impl App {
    fn new() -> (Self, Task<Message>) {
        (
            Self {},
            Task::batch(vec![
                font::load(ICED_AW_FONT_BYTES).map(Message::FontLoaded),
            ]),
        )
    }

    fn update(&mut self, message: Message) {
        match message {
            Message::FontLoaded(result) => {
                dbg!(result);
            }
        }
    }

    fn view(&self) -> Element<Message> {
        let s = format!("We have {} icons in this custom font!", COUNT);

        column![
            text(s),
            row![
                cancel(),
                down_open(),
                left_open(),
                ok(),
                right_open(),
                up_open()
            ]
            .padding(12)
            .spacing(20)
            .width(Length::Fill)
            .align_y(Center),
        ]
        .into()
    }
}
