2022-10-06 12:13:43 -04:00
|
|
|
use etagere::AllocId;
|
2022-05-09 08:49:10 -04:00
|
|
|
|
2022-10-06 12:13:43 -04:00
|
|
|
mod error;
|
|
|
|
mod recently_used;
|
|
|
|
mod text_atlas;
|
|
|
|
mod text_render;
|
2022-05-09 08:49:10 -04:00
|
|
|
|
2022-10-06 12:13:43 -04:00
|
|
|
pub use error::{PrepareError, RenderError};
|
2022-05-09 10:22:38 -04:00
|
|
|
pub use fontdue;
|
2022-10-06 12:13:43 -04:00
|
|
|
use recently_used::RecentlyUsedMap;
|
|
|
|
pub use text_atlas::TextAtlas;
|
|
|
|
pub use text_render::TextRenderer;
|
2022-05-16 07:53:13 -04:00
|
|
|
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The color to use when rendering text.
|
2022-05-09 21:23:09 -04:00
|
|
|
#[repr(C)]
|
|
|
|
pub struct Color {
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The red component of the color.
|
2022-05-09 21:23:09 -04:00
|
|
|
pub r: u8,
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The green component of the color.
|
2022-05-09 21:23:09 -04:00
|
|
|
pub g: u8,
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The blue component of the color.
|
2022-05-09 21:23:09 -04:00
|
|
|
pub b: u8,
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The alpha component of the color.
|
2022-05-09 21:23:09 -04:00
|
|
|
pub a: u8,
|
|
|
|
}
|
|
|
|
|
2022-10-18 11:47:35 -04:00
|
|
|
/// Allows text to be colored during rendering.
|
2022-05-09 21:23:09 -04:00
|
|
|
pub trait HasColor: Copy {
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The color to use when rendering text.
|
2022-05-09 21:23:09 -04:00
|
|
|
fn color(&self) -> Color;
|
2022-05-09 21:10:00 -04:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:13:43 -04:00
|
|
|
pub(crate) enum GpuCache {
|
2022-05-09 08:49:10 -04:00
|
|
|
InAtlas { x: u16, y: u16 },
|
|
|
|
SkipRasterization,
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:13:43 -04:00
|
|
|
pub(crate) struct GlyphDetails {
|
2022-05-09 10:22:38 -04:00
|
|
|
width: u16,
|
|
|
|
height: u16,
|
2022-05-09 08:49:10 -04:00
|
|
|
gpu_cache: GpuCache,
|
|
|
|
atlas_id: Option<AllocId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
2022-10-06 12:13:43 -04:00
|
|
|
pub(crate) struct GlyphToRender {
|
2022-05-09 10:22:38 -04:00
|
|
|
pos: [u32; 2],
|
|
|
|
dim: [u16; 2],
|
|
|
|
uv: [u16; 2],
|
2022-05-09 08:49:10 -04:00
|
|
|
color: [u8; 4],
|
|
|
|
}
|
|
|
|
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The screen resolution to use when rendering text.
|
2022-05-09 08:49:10 -04:00
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
pub struct Resolution {
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The width of the screen in pixels.
|
2022-05-09 08:49:10 -04:00
|
|
|
pub width: u32,
|
2022-10-18 11:47:35 -04:00
|
|
|
/// The height of the screen in pixels.
|
2022-05-09 08:49:10 -04:00
|
|
|
pub height: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
2022-10-18 11:47:35 -04:00
|
|
|
pub(crate) struct Params {
|
2022-05-09 08:49:10 -04:00
|
|
|
screen_resolution: Resolution,
|
2022-06-06 13:39:14 -04:00
|
|
|
_pad: [u32; 2],
|
2022-05-09 08:49:10 -04:00
|
|
|
}
|
|
|
|
|
2022-09-13 15:05:20 -04:00
|
|
|
/// Controls the overflow behavior of any glyphs that are outside of the layout bounds.
|
|
|
|
pub enum TextOverflow {
|
|
|
|
/// Glyphs can overflow the bounds.
|
|
|
|
Overflow,
|
|
|
|
/// Hide any glyphs outside the bounds. If a glyph is partially outside the bounds, it will be
|
|
|
|
/// clipped to the bounds.
|
|
|
|
Hide,
|
|
|
|
}
|