pub mod content;
pub mod content_data;
mod glyph;
mod render_data;
pub mod rich_text_render_data;
pub use glyph::Glyph;
pub use render_data::RenderData;
pub use rich_text_render_data::RichTextRenderData;
pub use content::{
BuilderLine, BuilderState, BuilderStateUpdate, Content, FragmentData, SpanStyle,
SpanStyleDecoration, UnderlineInfo, UnderlineShape, WordCache,
};
pub use content_data::{ContentData, ContentRenderData, ContentState};
pub use render_data::Run;
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Default, Debug)]
pub struct SpanId(pub usize);
impl SpanId {
pub fn to_usize(self) -> usize {
self.0
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Delta<T: Default> {
pub x: T,
pub top_y: T,
pub bottom_y: T,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct TextDimensions {
pub width: f32,
pub height: f32,
pub scale: f32,
}
impl Default for TextDimensions {
fn default() -> Self {
Self {
width: 8.0, height: 16.0, scale: 1.0,
}
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct TextLayout {
pub line_height: f32,
pub font_size: f32,
pub original_font_size: f32,
pub dimensions: TextDimensions,
}
impl TextLayout {
#[inline]
pub fn rescale(&mut self, scale_factor: f32) -> &mut Self {
self.dimensions.width *= scale_factor;
self.dimensions.height *= scale_factor;
self.dimensions.scale = scale_factor;
self
}
pub fn from_default_layout(default_layout: &RootStyle) -> Self {
Self {
line_height: default_layout.line_height,
font_size: default_layout.font_size,
original_font_size: default_layout.font_size,
dimensions: TextDimensions {
scale: default_layout.scale_factor,
..TextDimensions::default()
},
}
}
}
impl Default for TextLayout {
fn default() -> Self {
Self {
line_height: 1.0,
font_size: 0.0,
original_font_size: 0.0,
dimensions: TextDimensions::default(),
}
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct RichTextConfig {
pub position: Option<[f32; 2]>,
pub depth: f32,
}
impl Default for RichTextConfig {
fn default() -> Self {
Self {
position: None,
depth: 0.0,
}
}
}
impl RichTextConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_position(mut self, x: f32, y: f32) -> Self {
self.position = Some([x, y]);
self
}
pub fn with_depth(mut self, depth: f32) -> Self {
self.depth = depth;
self
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct RootStyle {
pub scale_factor: f32,
pub font_size: f32,
pub line_height: f32,
}
impl Default for RootStyle {
fn default() -> Self {
Self {
line_height: 1.0,
scale_factor: 1.0,
font_size: 14.,
}
}
}
impl RootStyle {
pub fn new(scale_factor: f32, font_size: f32, line_height: f32) -> RootStyle {
let line_height = if line_height <= 1.0 { 1.0 } else { line_height };
RootStyle {
scale_factor,
font_size,
line_height,
}
}
}