fix: impl Layout for Measure
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-09-09 20:59:07 +03:00
parent 90fc869e14
commit 41fa55fa6c

View file

@ -2,28 +2,30 @@ use crate::*;
/// A widget that tracks its render width and height /// A widget that tracks its render width and height
#[derive(Default)] #[derive(Default)]
pub struct Measure<E: Out> { pub struct Measure<O: Out> {
_engine: PhantomData<E>, _engine: PhantomData<O>,
pub x: Arc<AtomicUsize>, pub x: Arc<AtomicUsize>,
pub y: Arc<AtomicUsize>, pub y: Arc<AtomicUsize>,
} }
impl<E: Out> PartialEq for Measure<E> { impl<O: Out> PartialEq for Measure<O> {
fn eq (&self, other: &Self) -> bool { fn eq (&self, other: &Self) -> bool {
self.x.load(Relaxed) == other.x.load(Relaxed) && self.x.load(Relaxed) == other.x.load(Relaxed) &&
self.y.load(Relaxed) == other.y.load(Relaxed) self.y.load(Relaxed) == other.y.load(Relaxed)
} }
} }
impl<O: Out> Layout<O> for Measure<O> {}
// TODO: 🡘 🡙 ←🡙→ indicator to expand window when too small // TODO: 🡘 🡙 ←🡙→ indicator to expand window when too small
impl<E: Out> Draw<E> for Measure<E> { impl<O: Out> Draw<O> for Measure<O> {
fn draw (&self, to: &mut E) { fn draw (&self, to: &mut O) {
self.x.store(to.area().w().into(), Relaxed); self.x.store(to.area().w().into(), Relaxed);
self.y.store(to.area().h().into(), Relaxed); self.y.store(to.area().h().into(), Relaxed);
} }
} }
impl<E: Out> Clone for Measure<E> { impl<O: Out> Clone for Measure<O> {
fn clone (&self) -> Self { fn clone (&self) -> Self {
Self { Self {
_engine: Default::default(), _engine: Default::default(),
@ -33,7 +35,7 @@ impl<E: Out> Clone for Measure<E> {
} }
} }
impl<E: Out> std::fmt::Debug for Measure<E> { impl<O: Out> std::fmt::Debug for Measure<O> {
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
f.debug_struct("Measure") f.debug_struct("Measure")
.field("width", &self.x) .field("width", &self.x)
@ -42,7 +44,7 @@ impl<E: Out> std::fmt::Debug for Measure<E> {
} }
} }
impl<E: Out> Measure<E> { impl<O: Out> Measure<O> {
pub fn new () -> Self { pub fn new () -> Self {
Self { Self {
_engine: PhantomData::default(), _engine: PhantomData::default(),
@ -75,7 +77,7 @@ impl<E: Out> Measure<E> {
pub fn format (&self) -> Arc<str> { pub fn format (&self) -> Arc<str> {
format!("{}x{}", self.w(), self.h()).into() format!("{}x{}", self.w(), self.h()).into()
} }
pub fn of <T: Draw<E>> (&self, item: T) -> Bsp<Fill<&Self>, T> { pub fn of <T: Draw<O>> (&self, item: T) -> Bsp<Fill<&Self>, T> {
Bsp::b(Fill::XY(self), item) Bsp::b(Fill::XY(self), item)
} }
} }