inlyne 0.2.1

Introducing Inlyne, a GPU powered yet browsless tool to help you quickly view markdown files in the blink of an eye.
use std::{
    collections::HashMap,
    sync::{Arc, Mutex},
};

use wgpu_glyph::ab_glyph;
use winit::window::CursorIcon;

use crate::image::ImageData;

pub type Line = ((f32, f32), (f32, f32));
pub type Selection = ((f32, f32), (f32, f32));
pub type Point = (f32, f32);
pub type Size = (f32, f32);
pub type MaybeImageData = Arc<Mutex<Option<ImageData>>>;
pub type ImageCache = Arc<Mutex<HashMap<String, MaybeImageData>>>;

#[derive(Debug, Clone)]
pub struct Rect {
    pub pos: Point,
    pub size: Point,
}

impl Rect {
    pub fn new(pos: Point, size: Point) -> Rect {
        Rect { pos, size }
    }

    pub fn from_min_max(min: Point, max: Point) -> Rect {
        Rect {
            pos: min,
            size: (max.0 - min.0, max.1 - min.1),
        }
    }

    pub fn max(&self) -> Point {
        (self.pos.0 + self.size.0, self.pos.1 + self.size.1)
    }

    pub fn contains(&self, loc: Point) -> bool {
        self.pos.0 <= loc.0 && loc.0 <= self.max().0 && self.pos.1 <= loc.1 && loc.1 <= self.max().1
    }
}

impl From<ab_glyph::Rect> for Rect {
    fn from(other_rect: ab_glyph::Rect) -> Self {
        let ab_glyph::Rect {
            min: ab_glyph::Point { x: min_x, y: min_y },
            max: ab_glyph::Point { x: max_x, y: max_y },
        } = other_rect;
        Self::from_min_max((min_x, min_y), (max_x, max_y))
    }
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum Align {
    #[default]
    Left,
    Center,
    Right,
}

#[derive(Default)]
pub struct HoverInfo {
    pub cursor_icon: CursorIcon,
    pub jump: Option<f32>,
}

impl From<CursorIcon> for HoverInfo {
    fn from(cursor_icon: CursorIcon) -> Self {
        Self {
            cursor_icon,
            ..Default::default()
        }
    }
}