From 5556d2ea6d69b1b00783925b5f4aa30ac7823ab5 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Mon, 8 Jan 2024 09:06:49 -0800 Subject: [PATCH] FlexibleDimension now implements Zero --- CHANGELOG.md | 3 +++ src/styles.rs | 12 +++++++++--- src/widgets/align.rs | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c93d82..cd4fd6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Dynamic::wrap` has been renamed to `into_wrap` for consistency. - Cushy now has its own `KeyEvent` type, as winit's has private fields. This prevented simulating input in a `VirtualWindow`. +- `FlexibleDimension::ZERO` has been removed, and now `FlexibleDimension` + implements `Zero` which defines an associated constant of the same name and + purpose. ### Fixed diff --git a/src/styles.rs b/src/styles.rs index ccd8b63..3e0a4aa 100644 --- a/src/styles.rs +++ b/src/styles.rs @@ -649,9 +649,15 @@ pub enum FlexibleDimension { Dimension(Dimension), } -impl FlexibleDimension { - /// A dimension of 0 pixels. - pub const ZERO: Self = Self::Dimension(Dimension::ZERO); +impl Zero for FlexibleDimension { + const ZERO: Self = Self::Dimension(Dimension::ZERO); + + fn is_zero(&self) -> bool { + match self { + FlexibleDimension::Auto => false, + FlexibleDimension::Dimension(dim) => dim.is_zero(), + } + } } impl Debug for FlexibleDimension { diff --git a/src/widgets/align.rs b/src/widgets/align.rs index 34c51da..28e2cad 100644 --- a/src/widgets/align.rs +++ b/src/widgets/align.rs @@ -1,7 +1,7 @@ use std::fmt::Debug; use figures::units::UPx; -use figures::{Fraction, IntoSigned, Point, Rect, ScreenScale, Size}; +use figures::{Fraction, IntoSigned, Point, Rect, ScreenScale, Size, Zero}; use crate::context::{AsEventContext, EventContext, LayoutContext}; use crate::styles::{Edges, FlexibleDimension};