#![warn(missing_docs)]
extern crate alloc;
#[cfg(feature = "rtti")]
use crate::rtti::*;
use crate::SharedString;
use auto_enums::auto_enum;
pub type Rect = euclid::default::Rect<f32>;
pub type IntRect = euclid::default::Rect<i32>;
pub type Point = euclid::default::Point2D<f32>;
pub type Size = euclid::default::Size2D<f32>;
pub type Transform = euclid::default::Transform2D<f32>;
pub(crate) mod color;
pub use color::*;
mod path;
pub use path::*;
mod brush;
pub use brush::*;
#[derive(Clone, PartialEq, Debug)]
#[repr(u8)]
pub enum ImageReference {
None,
AbsoluteFilePath(crate::SharedString),
EmbeddedData(super::slice::Slice<'static, u8>),
#[allow(missing_docs)]
EmbeddedRgbaImage { width: u32, height: u32, data: super::sharedvector::SharedVector<u32> },
}
impl Default for ImageReference {
fn default() -> Self {
ImageReference::None
}
}
pub struct CachedGraphicsData<T> {
pub data: T,
pub dependency_tracker: core::pin::Pin<Box<crate::properties::PropertyTracker>>,
}
impl<T> CachedGraphicsData<T> {
pub fn new(update_fn: impl FnOnce() -> T) -> Self {
let dependency_tracker = Box::pin(crate::properties::PropertyTracker::default());
let data = dependency_tracker.as_ref().evaluate(update_fn);
Self { data, dependency_tracker }
}
}
pub type RenderingCache<T> = vec_arena::Arena<CachedGraphicsData<T>>;
#[derive(Debug, Clone, PartialEq, Default)]
pub struct FontRequest {
pub family: Option<SharedString>,
pub weight: Option<i32>,
pub pixel_size: Option<f32>,
pub letter_spacing: Option<f32>,
}
impl FontRequest {
pub fn merge(self, other: &FontRequest) -> Self {
Self {
family: self.family.or_else(|| other.family.clone()),
weight: self.weight.or_else(|| other.weight.clone()),
pixel_size: self.pixel_size.or_else(|| other.pixel_size.clone()),
letter_spacing: self.letter_spacing.or_else(|| other.letter_spacing.clone()),
}
}
}
pub trait FontMetrics {
fn text_size(&self, text: &str) -> Size;
fn text_offset_for_x_position<'a>(&self, text: &'a str, x: f32) -> usize;
}
#[cfg(feature = "ffi")]
pub(crate) mod ffi {
#![allow(unsafe_code)]
#[cfg(cbindgen)]
#[repr(C)]
struct Rect {
x: f32,
y: f32,
width: f32,
height: f32,
}
#[cfg(cbindgen)]
#[repr(C)]
struct IntRect {
x: i32,
y: i32,
width: i32,
height: i32,
}
#[cfg(cbindgen)]
#[repr(C)]
struct Point {
x: f32,
y: f32,
}
#[cfg(cbindgen)]
#[repr(C)]
struct Size {
width: f32,
height: f32,
}
pub use super::path::ffi::*;
}