diff --git a/composable-views/src/layout/spacing.rs b/composable-views/src/layout/spacing.rs index 0b0a249..8a1c8c6 100644 --- a/composable-views/src/layout/spacing.rs +++ b/composable-views/src/layout/spacing.rs @@ -1,20 +1,18 @@ -use std::cell::OnceCell; +use std::cell::Cell; use crate::{Bounds, Output, Size, View}; -pub struct Spacer(pub(crate) OnceCell); +pub struct Spacer(Cell); impl Spacer { #[inline(always)] pub fn fill() -> Self { - Spacer(OnceCell::new()) // a flexible spacer has no size (yet) + Spacer(Cell::new(Size::new(f32::INFINITY, f32::INFINITY))) // a flexible spacer has no size (yet) } #[inline(always)] pub fn fixed(width: f32, height: f32) -> Self { - let spacer = Self::fill(); - spacer.0.set(Size::new(width, height)).ok(); - spacer + Spacer(Cell::new(Size::new(width, height))) } #[inline(always)] @@ -37,7 +35,10 @@ impl Spacer { impl View for Spacer { #[inline] fn size(&self) -> Size { - self.0.get().cloned().unwrap_or_default() + match self.0.get() { + size if size.is_finite() => size, + _ => Size::zero(), + } } #[inline(always)] @@ -45,11 +46,11 @@ impl View for Spacer { #[inline(always)] fn needs_layout(&self) -> bool { - self.0.get().is_none() + self.0.get().is_finite() } #[inline] fn update_layout(&self, size: Size, _bounds: Bounds) { - self.0.set(size).ok(); + self.0.set(size); } } diff --git a/composable-views/src/text/font.rs b/composable-views/src/text/font.rs index 22aed36..fd7d501 100644 --- a/composable-views/src/text/font.rs +++ b/composable-views/src/text/font.rs @@ -60,11 +60,13 @@ impl<'a> Font<'a> { } /// Horizontal face ascender. + #[inline] pub fn ascender(&self) -> f32 { self.face.ascender() as f32 } /// Horizontal face descender, + #[inline] pub fn descender(&self) -> f32 { self.face.descender() as f32 }