#![warn(missing_docs)]
extern crate alloc;
use crate::SharedString;
use alloc::boxed::Box;
pub use euclid;
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 IntSize = euclid::default::Size2D<u32>;
pub type Transform = euclid::default::Transform2D<f32>;
pub(crate) mod color;
pub use color::*;
#[cfg(feature = "std")]
mod path;
#[cfg(feature = "std")]
pub use path::*;
mod brush;
pub use brush::*;
pub(crate) mod image;
pub use self::image::*;
#[cfg(feature = "std")]
mod fps_counter;
#[cfg(feature = "std")]
pub use fps_counter::*;
pub struct CachedGraphicsData<T> {
pub data: T,
pub dependency_tracker: Option<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: Some(dependency_tracker) }
}
}
pub struct RenderingCache<T> {
slab: slab::Slab<CachedGraphicsData<T>>,
generation: usize,
}
impl<T> Default for RenderingCache<T> {
fn default() -> Self {
Self { slab: Default::default(), generation: 1 }
}
}
impl<T> RenderingCache<T> {
pub fn generation(&self) -> usize {
self.generation
}
pub fn get_mut(&mut self, index: usize) -> Option<&mut CachedGraphicsData<T>> {
self.slab.get_mut(index)
}
pub fn contains(&self, index: usize) -> bool {
self.slab.contains(index)
}
pub fn insert(&mut self, data: CachedGraphicsData<T>) -> usize {
self.slab.insert(data)
}
pub fn get(&self, index: usize) -> Option<&CachedGraphicsData<T>> {
self.slab.get(index)
}
pub fn remove(&mut self, index: usize) -> CachedGraphicsData<T> {
self.slab.remove(index)
}
pub fn clear(&mut self) {
self.slab.clear();
self.generation += 1;
}
}
#[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 {
#[must_use]
pub fn merge(self, other: &FontRequest) -> Self {
Self {
family: self.family.or_else(|| other.family.clone()),
weight: self.weight.or(other.weight),
pixel_size: self.pixel_size.or(other.pixel_size),
letter_spacing: self.letter_spacing.or(other.letter_spacing),
}
}
}
#[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,
}
#[cfg(cbindgen)]
#[repr(C)]
struct IntSize {
width: u32,
height: u32,
}
pub use super::path::ffi::*;
}