pub mod color;
#[allow(clippy::module_inception)] mod draw;
mod draw_rounded;
mod draw_shared;
use crate::cast::Cast;
use crate::geom::{Quad, Size};
#[allow(unused)] use crate::theme::DrawCx;
pub use draw::{Draw, DrawIface, DrawImpl};
pub use draw_rounded::{DrawRounded, DrawRoundedImpl};
pub use draw_shared::{AllocError, ImageFormat, ImageHandle, ImageId, UploadError};
pub use draw_shared::{DrawShared, DrawSharedImpl, SharedState};
use std::time::{Duration, Instant};
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(docsrs, doc(cfg(internal_doc)))]
#[derive(Debug)]
pub struct Allocation {
pub atlas: u32,
pub alloc: u32,
pub origin: (u32, u32),
pub tex_quad: Quad,
}
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(docsrs, doc(cfg(internal_doc)))]
pub trait Allocator {
fn allocate(&mut self, size: Size) -> Result<Allocation, AllocError>;
fn deallocate(&mut self, atlas: u32, alloc: u32);
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[crate::impl_default(AnimationState::None)]
pub(crate) enum AnimationState {
None,
Animate,
Timed(Instant),
}
impl AnimationState {
fn merge_in(&mut self, rhs: AnimationState) {
use AnimationState::*;
*self = match (*self, rhs) {
(Animate, _) | (_, Animate) => Animate,
(Timed(t1), Timed(t2)) => Timed(t1.min(t2)),
(Timed(t), _) | (_, Timed(t)) => Timed(t),
(None, None) => None,
}
}
}
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(docsrs, doc(cfg(internal_doc)))]
#[derive(Debug, Default)]
pub struct WindowCommon {
pub(crate) anim: AnimationState,
pub(crate) dur_text: std::time::Duration,
}
impl WindowCommon {
pub fn report_dur_text(&mut self, dur: Duration) {
self.dur_text += dur;
}
pub fn immediate_redraw(&mut self) -> bool {
match self.anim {
AnimationState::None => return false,
AnimationState::Timed(when) if when > Instant::now() => return false,
_ => (),
}
self.anim = AnimationState::None;
true
}
pub fn next_resume(&self) -> Option<Instant> {
match self.anim {
AnimationState::Timed(when) => Some(when),
_ => None,
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct PassId(u32);
impl PassId {
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(docsrs, doc(cfg(internal_doc)))]
#[inline]
pub const fn new(n: u32) -> Self {
PassId(n)
}
#[inline]
pub fn pass(self) -> usize {
self.0.cast()
}
#[inline]
pub fn depth(self) -> f32 {
0.0
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum PassType {
Clip,
Overlay,
}