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
#[derive(Default)]
pub struct Measure<E: Out> {
_engine: PhantomData<E>,
pub struct Measure<O: Out> {
_engine: PhantomData<O>,
pub x: 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 {
self.x.load(Relaxed) == other.x.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
impl<E: Out> Draw<E> for Measure<E> {
fn draw (&self, to: &mut E) {
impl<O: Out> Draw<O> for Measure<O> {
fn draw (&self, to: &mut O) {
self.x.store(to.area().w().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 {
Self {
_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> {
f.debug_struct("Measure")
.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 {
Self {
_engine: PhantomData::default(),
@ -75,7 +77,7 @@ impl<E: Out> Measure<E> {
pub fn format (&self) -> Arc<str> {
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)
}
}