Skip to main content

egui/atomics/
sized_atom_kind.rs

1use crate::{Image, SizedAtomLayout};
2use emath::Vec2;
3use epaint::Galley;
4use std::sync::Arc;
5
6/// A sized [`crate::AtomKind`].
7#[derive(Clone, Debug)]
8pub enum SizedAtomKind<'a> {
9    Empty { size: Option<Vec2> },
10    Text(Arc<Galley>),
11    Image { image: Image<'a>, size: Vec2 },
12    Layout(Box<SizedAtomLayout<'a>>),
13}
14
15impl Default for SizedAtomKind<'_> {
16    fn default() -> Self {
17        Self::Empty { size: None }
18    }
19}
20
21impl SizedAtomKind<'_> {
22    /// Get the calculated size.
23    pub fn size(&self) -> Vec2 {
24        match self {
25            SizedAtomKind::Text(galley) => galley.size(),
26            SizedAtomKind::Image { image: _, size } => *size,
27            SizedAtomKind::Empty { size } => size.unwrap_or_default(),
28            SizedAtomKind::Layout(layout) => layout.outer_size,
29        }
30    }
31}