test.rs

   1#![feature(prelude_import)]
   2#![allow(dead_code, unused_variables)]
   3#[prelude_import]
   4use std::prelude::rust_2021::*;
   5#[macro_use]
   6extern crate std;
   7use color::black;
   8use components::button;
   9use element::Element;
  10use frame::frame;
  11use gpui::{
  12    geometry::{rect::RectF, vector::vec2f},
  13    platform::WindowOptions,
  14};
  15use log::LevelFilter;
  16use simplelog::SimpleLogger;
  17use themes::{rose_pine, ThemeColors};
  18use view::view;
  19mod adapter {
  20    use crate::element::{LayoutContext, PaintContext};
  21    use gpui::{geometry::rect::RectF, LayoutEngine};
  22    use util::ResultExt;
  23    use crate::element::AnyElement;
  24    pub struct Adapter<V>(pub(crate) AnyElement<V>);
  25    impl<V: 'static> gpui::Element<V> for Adapter<V> {
  26        type LayoutState = Option<LayoutEngine>;
  27        type PaintState = ();
  28        fn layout(
  29            &mut self,
  30            constraint: gpui::SizeConstraint,
  31            view: &mut V,
  32            cx: &mut LayoutContext<V>,
  33        ) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
  34            cx.push_layout_engine(LayoutEngine::new());
  35            let node = self.0.layout(view, cx).log_err();
  36            if let Some(node) = node {
  37                let layout_engine = cx.layout_engine().unwrap();
  38                layout_engine.compute_layout(node, constraint.max).log_err();
  39            }
  40            let layout_engine = cx.pop_layout_engine();
  41            if true {
  42                if !layout_engine.is_some() {
  43                    ::core::panicking::panic("assertion failed: layout_engine.is_some()")
  44                }
  45            }
  46            (constraint.max, layout_engine)
  47        }
  48        fn paint(
  49            &mut self,
  50            scene: &mut gpui::SceneBuilder,
  51            bounds: RectF,
  52            visible_bounds: RectF,
  53            layout_engine: &mut Option<LayoutEngine>,
  54            view: &mut V,
  55            legacy_cx: &mut gpui::PaintContext<V>,
  56        ) -> Self::PaintState {
  57            legacy_cx.push_layout_engine(layout_engine.take().unwrap());
  58            let mut cx = PaintContext::new(legacy_cx, scene);
  59            self.0.paint(view, &mut cx).log_err();
  60            *layout_engine = legacy_cx.pop_layout_engine();
  61            if true {
  62                if !layout_engine.is_some() {
  63                    ::core::panicking::panic("assertion failed: layout_engine.is_some()")
  64                }
  65            }
  66        }
  67        fn rect_for_text_range(
  68            &self,
  69            range_utf16: std::ops::Range<usize>,
  70            bounds: RectF,
  71            visible_bounds: RectF,
  72            layout: &Self::LayoutState,
  73            paint: &Self::PaintState,
  74            view: &V,
  75            cx: &gpui::ViewContext<V>,
  76        ) -> Option<RectF> {
  77            ::core::panicking::panic("not yet implemented")
  78        }
  79        fn debug(
  80            &self,
  81            bounds: RectF,
  82            layout: &Self::LayoutState,
  83            paint: &Self::PaintState,
  84            view: &V,
  85            cx: &gpui::ViewContext<V>,
  86        ) -> gpui::serde_json::Value {
  87            ::core::panicking::panic("not yet implemented")
  88        }
  89    }
  90}
  91mod color {
  92    #![allow(dead_code)]
  93    use std::{num::ParseIntError, ops::Range};
  94    use smallvec::SmallVec;
  95    pub fn rgb<C: From<Rgba>>(hex: u32) -> C {
  96        let r = ((hex >> 16) & 0xFF) as f32 / 255.0;
  97        let g = ((hex >> 8) & 0xFF) as f32 / 255.0;
  98        let b = (hex & 0xFF) as f32 / 255.0;
  99        Rgba { r, g, b, a: 1.0 }.into()
 100    }
 101    pub struct Rgba {
 102        pub r: f32,
 103        pub g: f32,
 104        pub b: f32,
 105        pub a: f32,
 106    }
 107    #[automatically_derived]
 108    impl ::core::clone::Clone for Rgba {
 109        #[inline]
 110        fn clone(&self) -> Rgba {
 111            let _: ::core::clone::AssertParamIsClone<f32>;
 112            *self
 113        }
 114    }
 115    #[automatically_derived]
 116    impl ::core::marker::Copy for Rgba {}
 117    #[automatically_derived]
 118    impl ::core::default::Default for Rgba {
 119        #[inline]
 120        fn default() -> Rgba {
 121            Rgba {
 122                r: ::core::default::Default::default(),
 123                g: ::core::default::Default::default(),
 124                b: ::core::default::Default::default(),
 125                a: ::core::default::Default::default(),
 126            }
 127        }
 128    }
 129    #[automatically_derived]
 130    impl ::core::fmt::Debug for Rgba {
 131        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
 132            ::core::fmt::Formatter::debug_struct_field4_finish(
 133                f,
 134                "Rgba",
 135                "r",
 136                &self.r,
 137                "g",
 138                &self.g,
 139                "b",
 140                &self.b,
 141                "a",
 142                &&self.a,
 143            )
 144        }
 145    }
 146    pub trait Lerp {
 147        fn lerp(&self, level: f32) -> Hsla;
 148    }
 149    impl Lerp for Range<Hsla> {
 150        fn lerp(&self, level: f32) -> Hsla {
 151            let level = level.clamp(0., 1.);
 152            Hsla {
 153                h: self.start.h + (level * (self.end.h - self.start.h)),
 154                s: self.start.s + (level * (self.end.s - self.start.s)),
 155                l: self.start.l + (level * (self.end.l - self.start.l)),
 156                a: self.start.a + (level * (self.end.a - self.start.a)),
 157            }
 158        }
 159    }
 160    impl From<gpui::color::Color> for Rgba {
 161        fn from(value: gpui::color::Color) -> Self {
 162            Self {
 163                r: value.0.r as f32 / 255.0,
 164                g: value.0.g as f32 / 255.0,
 165                b: value.0.b as f32 / 255.0,
 166                a: value.0.a as f32 / 255.0,
 167            }
 168        }
 169    }
 170    impl From<Hsla> for Rgba {
 171        fn from(color: Hsla) -> Self {
 172            let h = color.h;
 173            let s = color.s;
 174            let l = color.l;
 175            let c = (1.0 - (2.0 * l - 1.0).abs()) * s;
 176            let x = c * (1.0 - ((h * 6.0) % 2.0 - 1.0).abs());
 177            let m = l - c / 2.0;
 178            let cm = c + m;
 179            let xm = x + m;
 180            let (r, g, b) = match (h * 6.0).floor() as i32 {
 181                0 | 6 => (cm, xm, m),
 182                1 => (xm, cm, m),
 183                2 => (m, cm, xm),
 184                3 => (m, xm, cm),
 185                4 => (xm, m, cm),
 186                _ => (cm, m, xm),
 187            };
 188            Rgba { r, g, b, a: color.a }
 189        }
 190    }
 191    impl TryFrom<&'_ str> for Rgba {
 192        type Error = ParseIntError;
 193        fn try_from(value: &'_ str) -> Result<Self, Self::Error> {
 194            let r = u8::from_str_radix(&value[1..3], 16)? as f32 / 255.0;
 195            let g = u8::from_str_radix(&value[3..5], 16)? as f32 / 255.0;
 196            let b = u8::from_str_radix(&value[5..7], 16)? as f32 / 255.0;
 197            let a = if value.len() > 7 {
 198                u8::from_str_radix(&value[7..9], 16)? as f32 / 255.0
 199            } else {
 200                1.0
 201            };
 202            Ok(Rgba { r, g, b, a })
 203        }
 204    }
 205    impl Into<gpui::color::Color> for Rgba {
 206        fn into(self) -> gpui::color::Color {
 207            gpui::color::rgba(self.r, self.g, self.b, self.a)
 208        }
 209    }
 210    pub struct Hsla {
 211        pub h: f32,
 212        pub s: f32,
 213        pub l: f32,
 214        pub a: f32,
 215    }
 216    #[automatically_derived]
 217    impl ::core::default::Default for Hsla {
 218        #[inline]
 219        fn default() -> Hsla {
 220            Hsla {
 221                h: ::core::default::Default::default(),
 222                s: ::core::default::Default::default(),
 223                l: ::core::default::Default::default(),
 224                a: ::core::default::Default::default(),
 225            }
 226        }
 227    }
 228    #[automatically_derived]
 229    impl ::core::marker::Copy for Hsla {}
 230    #[automatically_derived]
 231    impl ::core::clone::Clone for Hsla {
 232        #[inline]
 233        fn clone(&self) -> Hsla {
 234            let _: ::core::clone::AssertParamIsClone<f32>;
 235            *self
 236        }
 237    }
 238    #[automatically_derived]
 239    impl ::core::fmt::Debug for Hsla {
 240        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
 241            ::core::fmt::Formatter::debug_struct_field4_finish(
 242                f,
 243                "Hsla",
 244                "h",
 245                &self.h,
 246                "s",
 247                &self.s,
 248                "l",
 249                &self.l,
 250                "a",
 251                &&self.a,
 252            )
 253        }
 254    }
 255    #[automatically_derived]
 256    impl ::core::marker::StructuralPartialEq for Hsla {}
 257    #[automatically_derived]
 258    impl ::core::cmp::PartialEq for Hsla {
 259        #[inline]
 260        fn eq(&self, other: &Hsla) -> bool {
 261            self.h == other.h && self.s == other.s && self.l == other.l
 262                && self.a == other.a
 263        }
 264    }
 265    pub fn hsla(h: f32, s: f32, l: f32, a: f32) -> Hsla {
 266        Hsla {
 267            h: h.clamp(0., 1.),
 268            s: s.clamp(0., 1.),
 269            l: l.clamp(0., 1.),
 270            a: a.clamp(0., 1.),
 271        }
 272    }
 273    pub fn black() -> Hsla {
 274        Hsla { h: 0., s: 0., l: 0., a: 1. }
 275    }
 276    impl From<Rgba> for Hsla {
 277        fn from(color: Rgba) -> Self {
 278            let r = color.r;
 279            let g = color.g;
 280            let b = color.b;
 281            let max = r.max(g.max(b));
 282            let min = r.min(g.min(b));
 283            let delta = max - min;
 284            let l = (max + min) / 2.0;
 285            let s = if l == 0.0 || l == 1.0 {
 286                0.0
 287            } else if l < 0.5 {
 288                delta / (2.0 * l)
 289            } else {
 290                delta / (2.0 - 2.0 * l)
 291            };
 292            let h = if delta == 0.0 {
 293                0.0
 294            } else if max == r {
 295                ((g - b) / delta).rem_euclid(6.0) / 6.0
 296            } else if max == g {
 297                ((b - r) / delta + 2.0) / 6.0
 298            } else {
 299                ((r - g) / delta + 4.0) / 6.0
 300            };
 301            Hsla { h, s, l, a: color.a }
 302        }
 303    }
 304    impl Hsla {
 305        /// Scales the saturation and lightness by the given values, clamping at 1.0.
 306        pub fn scale_sl(mut self, s: f32, l: f32) -> Self {
 307            self.s = (self.s * s).clamp(0., 1.);
 308            self.l = (self.l * l).clamp(0., 1.);
 309            self
 310        }
 311        /// Increases the saturation of the color by a certain amount, with a max
 312        /// value of 1.0.
 313        pub fn saturate(mut self, amount: f32) -> Self {
 314            self.s += amount;
 315            self.s = self.s.clamp(0.0, 1.0);
 316            self
 317        }
 318        /// Decreases the saturation of the color by a certain amount, with a min
 319        /// value of 0.0.
 320        pub fn desaturate(mut self, amount: f32) -> Self {
 321            self.s -= amount;
 322            self.s = self.s.max(0.0);
 323            if self.s < 0.0 {
 324                self.s = 0.0;
 325            }
 326            self
 327        }
 328        /// Brightens the color by increasing the lightness by a certain amount,
 329        /// with a max value of 1.0.
 330        pub fn brighten(mut self, amount: f32) -> Self {
 331            self.l += amount;
 332            self.l = self.l.clamp(0.0, 1.0);
 333            self
 334        }
 335        /// Darkens the color by decreasing the lightness by a certain amount,
 336        /// with a max value of 0.0.
 337        pub fn darken(mut self, amount: f32) -> Self {
 338            self.l -= amount;
 339            self.l = self.l.clamp(0.0, 1.0);
 340            self
 341        }
 342    }
 343    impl From<gpui::color::Color> for Hsla {
 344        fn from(value: gpui::color::Color) -> Self {
 345            Rgba::from(value).into()
 346        }
 347    }
 348    impl Into<gpui::color::Color> for Hsla {
 349        fn into(self) -> gpui::color::Color {
 350            Rgba::from(self).into()
 351        }
 352    }
 353    pub struct ColorScale {
 354        colors: SmallVec<[Hsla; 2]>,
 355        positions: SmallVec<[f32; 2]>,
 356    }
 357    pub fn scale<I, C>(colors: I) -> ColorScale
 358    where
 359        I: IntoIterator<Item = C>,
 360        C: Into<Hsla>,
 361    {
 362        let mut scale = ColorScale {
 363            colors: colors.into_iter().map(Into::into).collect(),
 364            positions: SmallVec::new(),
 365        };
 366        let num_colors: f32 = scale.colors.len() as f32 - 1.0;
 367        scale
 368            .positions = (0..scale.colors.len())
 369            .map(|i| i as f32 / num_colors)
 370            .collect();
 371        scale
 372    }
 373    impl ColorScale {
 374        fn at(&self, t: f32) -> Hsla {
 375            if true {
 376                if !(0.0 <= t && t <= 1.0) {
 377                    {
 378                        ::core::panicking::panic_fmt(
 379                            format_args!(
 380                                "t value {0} is out of range. Expected value in range 0.0 to 1.0",
 381                                t,
 382                            ),
 383                        );
 384                    }
 385                }
 386            }
 387            let position = match self
 388                .positions
 389                .binary_search_by(|a| a.partial_cmp(&t).unwrap())
 390            {
 391                Ok(index) | Err(index) => index,
 392            };
 393            let lower_bound = position.saturating_sub(1);
 394            let upper_bound = position.min(self.colors.len() - 1);
 395            let lower_color = &self.colors[lower_bound];
 396            let upper_color = &self.colors[upper_bound];
 397            match upper_bound.checked_sub(lower_bound) {
 398                Some(0) | None => *lower_color,
 399                Some(_) => {
 400                    let interval_t = (t - self.positions[lower_bound])
 401                        / (self.positions[upper_bound] - self.positions[lower_bound]);
 402                    let h = lower_color.h + interval_t * (upper_color.h - lower_color.h);
 403                    let s = lower_color.s + interval_t * (upper_color.s - lower_color.s);
 404                    let l = lower_color.l + interval_t * (upper_color.l - lower_color.l);
 405                    let a = lower_color.a + interval_t * (upper_color.a - lower_color.a);
 406                    Hsla { h, s, l, a }
 407                }
 408            }
 409        }
 410    }
 411}
 412mod components {
 413    use crate::{
 414        element::{Element, ElementMetadata},
 415        frame, text::ArcCow, themes::rose_pine,
 416    };
 417    use gpui::{platform::MouseButton, ViewContext};
 418    use playground_macros::Element;
 419    use std::{marker::PhantomData, rc::Rc};
 420    struct ButtonHandlers<V, D> {
 421        click: Option<Rc<dyn Fn(&mut V, &D, &mut ViewContext<V>)>>,
 422    }
 423    impl<V, D> Default for ButtonHandlers<V, D> {
 424        fn default() -> Self {
 425            Self { click: None }
 426        }
 427    }
 428    #[element_crate = "crate"]
 429    pub struct Button<V: 'static, D: 'static> {
 430        metadata: ElementMetadata<V>,
 431        handlers: ButtonHandlers<V, D>,
 432        label: Option<ArcCow<'static, str>>,
 433        icon: Option<ArcCow<'static, str>>,
 434        data: Rc<D>,
 435        view_type: PhantomData<V>,
 436    }
 437    impl<V: 'static, D: 'static> crate::element::Element<V> for Button<V, D> {
 438        type Layout = crate::element::AnyElement<V>;
 439        fn declared_style(&mut self) -> &mut crate::style::OptionalStyle {
 440            &mut self.metadata.style
 441        }
 442        fn handlers_mut(&mut self) -> &mut Vec<crate::element::EventHandler<V>> {
 443            &mut self.metadata.handlers
 444        }
 445        fn layout(
 446            &mut self,
 447            view: &mut V,
 448            cx: &mut crate::element::LayoutContext<V>,
 449        ) -> anyhow::Result<(taffy::tree::NodeId, Self::Layout)> {
 450            let mut element = self.render(view, cx).into_any();
 451            let node_id = element.layout(view, cx)?;
 452            Ok((node_id, element))
 453        }
 454        fn paint<'a>(
 455            &mut self,
 456            layout: crate::element::Layout<'a, Self::Layout>,
 457            view: &mut V,
 458            cx: &mut crate::element::PaintContext<V>,
 459        ) -> anyhow::Result<()> {
 460            layout.from_element.paint(view, cx)?;
 461            Ok(())
 462        }
 463    }
 464    impl<V: 'static, D: 'static> crate::element::IntoElement<V> for Button<V, D> {
 465        type Element = Self;
 466        fn into_element(self) -> Self {
 467            self
 468        }
 469    }
 470    impl<V: 'static> Button<V, ()> {
 471        fn new() -> Self {
 472            Self {
 473                metadata: Default::default(),
 474                handlers: ButtonHandlers::default(),
 475                label: None,
 476                icon: None,
 477                data: Rc::new(()),
 478                view_type: PhantomData,
 479            }
 480        }
 481        pub fn data<D: 'static>(self, data: D) -> Button<V, D> {
 482            Button {
 483                metadata: Default::default(),
 484                handlers: ButtonHandlers::default(),
 485                label: self.label,
 486                icon: self.icon,
 487                data: Rc::new(data),
 488                view_type: PhantomData,
 489            }
 490        }
 491    }
 492    impl<V: 'static, D: 'static> Button<V, D> {
 493        pub fn label(mut self, label: impl Into<ArcCow<'static, str>>) -> Self {
 494            self.label = Some(label.into());
 495            self
 496        }
 497        pub fn icon(mut self, icon: impl Into<ArcCow<'static, str>>) -> Self {
 498            self.icon = Some(icon.into());
 499            self
 500        }
 501        pub fn click(
 502            self,
 503            handler: impl Fn(&mut V, &D, &mut ViewContext<V>) + 'static,
 504        ) -> Self {
 505            let data = self.data.clone();
 506            Element::click(
 507                self,
 508                MouseButton::Left,
 509                move |view, _, cx| {
 510                    handler(view, data.as_ref(), cx);
 511                },
 512            )
 513        }
 514    }
 515    pub fn button<V>() -> Button<V, ()> {
 516        Button::new()
 517    }
 518    impl<V: 'static, D: 'static> Button<V, D> {
 519        fn render(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
 520            let button = frame()
 521                .fill(rose_pine::dawn().error(0.5))
 522                .h_4()
 523                .children(self.label.clone());
 524            if let Some(handler) = self.handlers.click.clone() {
 525                let data = self.data.clone();
 526                button
 527                    .mouse_down(
 528                        MouseButton::Left,
 529                        move |view, event, cx| { handler(view, data.as_ref(), cx) },
 530                    )
 531            } else {
 532                button
 533            }
 534        }
 535    }
 536}
 537mod element {
 538    use crate::{
 539        adapter::Adapter, color::Hsla, hoverable::Hoverable,
 540        style::{Display, Fill, OptionalStyle, Overflow, Position},
 541    };
 542    use anyhow::Result;
 543    pub use gpui::LayoutContext;
 544    use gpui::{
 545        geometry::{DefinedLength, Length, OptionalPoint},
 546        platform::{MouseButton, MouseButtonEvent},
 547        EngineLayout, EventContext, RenderContext, ViewContext,
 548    };
 549    use playground_macros::tailwind_lengths;
 550    use std::{
 551        any::{Any, TypeId},
 552        cell::Cell, rc::Rc,
 553    };
 554    pub use crate::paint_context::PaintContext;
 555    pub use taffy::tree::NodeId;
 556    pub struct Layout<'a, E: ?Sized> {
 557        pub from_engine: EngineLayout,
 558        pub from_element: &'a mut E,
 559    }
 560    pub struct ElementMetadata<V> {
 561        pub style: OptionalStyle,
 562        pub handlers: Vec<EventHandler<V>>,
 563    }
 564    pub struct EventHandler<V> {
 565        handler: Rc<dyn Fn(&mut V, &dyn Any, &mut EventContext<V>)>,
 566        event_type: TypeId,
 567        outside_bounds: bool,
 568    }
 569    impl<V> Clone for EventHandler<V> {
 570        fn clone(&self) -> Self {
 571            Self {
 572                handler: self.handler.clone(),
 573                event_type: self.event_type,
 574                outside_bounds: self.outside_bounds,
 575            }
 576        }
 577    }
 578    impl<V> Default for ElementMetadata<V> {
 579        fn default() -> Self {
 580            Self {
 581                style: OptionalStyle::default(),
 582                handlers: Vec::new(),
 583            }
 584        }
 585    }
 586    pub trait Element<V: 'static>: 'static {
 587        type Layout: 'static;
 588        fn declared_style(&mut self) -> &mut OptionalStyle;
 589        fn computed_style(&mut self) -> &OptionalStyle {
 590            self.declared_style()
 591        }
 592        fn handlers_mut(&mut self) -> &mut Vec<EventHandler<V>>;
 593        fn layout(
 594            &mut self,
 595            view: &mut V,
 596            cx: &mut LayoutContext<V>,
 597        ) -> Result<(NodeId, Self::Layout)>;
 598        fn paint<'a>(
 599            &mut self,
 600            layout: Layout<Self::Layout>,
 601            view: &mut V,
 602            cx: &mut PaintContext<V>,
 603        ) -> Result<()>;
 604        /// Convert to a dynamically-typed element suitable for layout and paint.
 605        fn into_any(self) -> AnyElement<V>
 606        where
 607            Self: 'static + Sized,
 608        {
 609            AnyElement {
 610                element: Box::new(self) as Box<dyn ElementObject<V>>,
 611                layout: None,
 612            }
 613        }
 614        fn adapt(self) -> Adapter<V>
 615        where
 616            Self: Sized,
 617            Self: Element<V>,
 618        {
 619            Adapter(self.into_any())
 620        }
 621        fn click(
 622            self,
 623            button: MouseButton,
 624            handler: impl Fn(&mut V, &MouseButtonEvent, &mut ViewContext<V>) + 'static,
 625        ) -> Self
 626        where
 627            Self: Sized,
 628        {
 629            let pressed: Rc<Cell<bool>> = Default::default();
 630            self.mouse_down(
 631                    button,
 632                    {
 633                        let pressed = pressed.clone();
 634                        move |_, _, _| {
 635                            pressed.set(true);
 636                        }
 637                    },
 638                )
 639                .mouse_up_outside(
 640                    button,
 641                    {
 642                        let pressed = pressed.clone();
 643                        move |_, _, _| {
 644                            pressed.set(false);
 645                        }
 646                    },
 647                )
 648                .mouse_up(
 649                    button,
 650                    move |view, event, event_cx| {
 651                        if pressed.get() {
 652                            pressed.set(false);
 653                            handler(view, event, event_cx);
 654                        }
 655                    },
 656                )
 657        }
 658        fn mouse_down(
 659            mut self,
 660            button: MouseButton,
 661            handler: impl Fn(&mut V, &MouseButtonEvent, &mut EventContext<V>) + 'static,
 662        ) -> Self
 663        where
 664            Self: Sized,
 665        {
 666            self.handlers_mut()
 667                .push(EventHandler {
 668                    handler: Rc::new(move |view, event, event_cx| {
 669                        let event = event.downcast_ref::<MouseButtonEvent>().unwrap();
 670                        if event.button == button && event.is_down {
 671                            handler(view, event, event_cx);
 672                        }
 673                    }),
 674                    event_type: TypeId::of::<MouseButtonEvent>(),
 675                    outside_bounds: false,
 676                });
 677            self
 678        }
 679        fn mouse_down_outside(
 680            mut self,
 681            button: MouseButton,
 682            handler: impl Fn(&mut V, &MouseButtonEvent, &mut EventContext<V>) + 'static,
 683        ) -> Self
 684        where
 685            Self: Sized,
 686        {
 687            self.handlers_mut()
 688                .push(EventHandler {
 689                    handler: Rc::new(move |view, event, event_cx| {
 690                        let event = event.downcast_ref::<MouseButtonEvent>().unwrap();
 691                        if event.button == button && event.is_down {
 692                            handler(view, event, event_cx);
 693                        }
 694                    }),
 695                    event_type: TypeId::of::<MouseButtonEvent>(),
 696                    outside_bounds: true,
 697                });
 698            self
 699        }
 700        fn mouse_up(
 701            mut self,
 702            button: MouseButton,
 703            handler: impl Fn(&mut V, &MouseButtonEvent, &mut EventContext<V>) + 'static,
 704        ) -> Self
 705        where
 706            Self: Sized,
 707        {
 708            self.handlers_mut()
 709                .push(EventHandler {
 710                    handler: Rc::new(move |view, event, event_cx| {
 711                        let event = event.downcast_ref::<MouseButtonEvent>().unwrap();
 712                        if event.button == button && !event.is_down {
 713                            handler(view, event, event_cx);
 714                        }
 715                    }),
 716                    event_type: TypeId::of::<MouseButtonEvent>(),
 717                    outside_bounds: false,
 718                });
 719            self
 720        }
 721        fn mouse_up_outside(
 722            mut self,
 723            button: MouseButton,
 724            handler: impl Fn(&mut V, &MouseButtonEvent, &mut EventContext<V>) + 'static,
 725        ) -> Self
 726        where
 727            Self: Sized,
 728        {
 729            self.handlers_mut()
 730                .push(EventHandler {
 731                    handler: Rc::new(move |view, event, event_cx| {
 732                        let event = event.downcast_ref::<MouseButtonEvent>().unwrap();
 733                        if event.button == button && !event.is_down {
 734                            handler(view, event, event_cx);
 735                        }
 736                    }),
 737                    event_type: TypeId::of::<MouseButtonEvent>(),
 738                    outside_bounds: true,
 739                });
 740            self
 741        }
 742        fn block(mut self) -> Self
 743        where
 744            Self: Sized,
 745        {
 746            self.declared_style().display = Some(Display::Block);
 747            self
 748        }
 749        fn flex(mut self) -> Self
 750        where
 751            Self: Sized,
 752        {
 753            self.declared_style().display = Some(Display::Flex);
 754            self
 755        }
 756        fn grid(mut self) -> Self
 757        where
 758            Self: Sized,
 759        {
 760            self.declared_style().display = Some(Display::Grid);
 761            self
 762        }
 763        fn overflow_visible(mut self) -> Self
 764        where
 765            Self: Sized,
 766        {
 767            self
 768                .declared_style()
 769                .overflow = OptionalPoint {
 770                x: Some(Overflow::Visible),
 771                y: Some(Overflow::Visible),
 772            };
 773            self
 774        }
 775        fn overflow_hidden(mut self) -> Self
 776        where
 777            Self: Sized,
 778        {
 779            self
 780                .declared_style()
 781                .overflow = OptionalPoint {
 782                x: Some(Overflow::Hidden),
 783                y: Some(Overflow::Hidden),
 784            };
 785            self
 786        }
 787        fn overflow_scroll(mut self) -> Self
 788        where
 789            Self: Sized,
 790        {
 791            self
 792                .declared_style()
 793                .overflow = OptionalPoint {
 794                x: Some(Overflow::Scroll),
 795                y: Some(Overflow::Scroll),
 796            };
 797            self
 798        }
 799        fn overflow_x_visible(mut self) -> Self
 800        where
 801            Self: Sized,
 802        {
 803            self.declared_style().overflow.x = Some(Overflow::Visible);
 804            self
 805        }
 806        fn overflow_x_hidden(mut self) -> Self
 807        where
 808            Self: Sized,
 809        {
 810            self.declared_style().overflow.x = Some(Overflow::Hidden);
 811            self
 812        }
 813        fn overflow_x_scroll(mut self) -> Self
 814        where
 815            Self: Sized,
 816        {
 817            self.declared_style().overflow.x = Some(Overflow::Scroll);
 818            self
 819        }
 820        fn overflow_y_visible(mut self) -> Self
 821        where
 822            Self: Sized,
 823        {
 824            self.declared_style().overflow.y = Some(Overflow::Visible);
 825            self
 826        }
 827        fn overflow_y_hidden(mut self) -> Self
 828        where
 829            Self: Sized,
 830        {
 831            self.declared_style().overflow.y = Some(Overflow::Hidden);
 832            self
 833        }
 834        fn overflow_y_scroll(mut self) -> Self
 835        where
 836            Self: Sized,
 837        {
 838            self.declared_style().overflow.y = Some(Overflow::Scroll);
 839            self
 840        }
 841        fn relative(mut self) -> Self
 842        where
 843            Self: Sized,
 844        {
 845            self.declared_style().position = Some(Position::Relative);
 846            self
 847        }
 848        fn absolute(mut self) -> Self
 849        where
 850            Self: Sized,
 851        {
 852            self.declared_style().position = Some(Position::Absolute);
 853            self
 854        }
 855        fn inset_0(mut self) -> Self
 856        where
 857            Self: Sized,
 858        {
 859            let length = DefinedLength::Pixels(0.).into();
 860            {
 861                let inset = self
 862                    .computed_style()
 863                    .inset
 864                    .get_or_insert_with(Default::default);
 865                inset.top = length;
 866                inset.right = length;
 867                inset.bottom = length;
 868                inset.left = length;
 869                self
 870            }
 871        }
 872        fn inset_px(mut self) -> Self
 873        where
 874            Self: Sized,
 875        {
 876            let length = DefinedLength::Pixels(1.).into();
 877            {
 878                let inset = self
 879                    .computed_style()
 880                    .inset
 881                    .get_or_insert_with(Default::default);
 882                inset.top = length;
 883                inset.right = length;
 884                inset.bottom = length;
 885                inset.left = length;
 886                self
 887            }
 888        }
 889        fn inset_0_5(mut self) -> Self
 890        where
 891            Self: Sized,
 892        {
 893            let length = DefinedLength::Rems(0.125).into();
 894            {
 895                let inset = self
 896                    .computed_style()
 897                    .inset
 898                    .get_or_insert_with(Default::default);
 899                inset.top = length;
 900                inset.right = length;
 901                inset.bottom = length;
 902                inset.left = length;
 903                self
 904            }
 905        }
 906        fn inset_1(mut self) -> Self
 907        where
 908            Self: Sized,
 909        {
 910            let length = DefinedLength::Rems(0.25).into();
 911            {
 912                let inset = self
 913                    .computed_style()
 914                    .inset
 915                    .get_or_insert_with(Default::default);
 916                inset.top = length;
 917                inset.right = length;
 918                inset.bottom = length;
 919                inset.left = length;
 920                self
 921            }
 922        }
 923        fn inset_1_5(mut self) -> Self
 924        where
 925            Self: Sized,
 926        {
 927            let length = DefinedLength::Rems(0.375).into();
 928            {
 929                let inset = self
 930                    .computed_style()
 931                    .inset
 932                    .get_or_insert_with(Default::default);
 933                inset.top = length;
 934                inset.right = length;
 935                inset.bottom = length;
 936                inset.left = length;
 937                self
 938            }
 939        }
 940        fn inset_2(mut self) -> Self
 941        where
 942            Self: Sized,
 943        {
 944            let length = DefinedLength::Rems(0.5).into();
 945            {
 946                let inset = self
 947                    .computed_style()
 948                    .inset
 949                    .get_or_insert_with(Default::default);
 950                inset.top = length;
 951                inset.right = length;
 952                inset.bottom = length;
 953                inset.left = length;
 954                self
 955            }
 956        }
 957        fn inset_2_5(mut self) -> Self
 958        where
 959            Self: Sized,
 960        {
 961            let length = DefinedLength::Rems(0.625).into();
 962            {
 963                let inset = self
 964                    .computed_style()
 965                    .inset
 966                    .get_or_insert_with(Default::default);
 967                inset.top = length;
 968                inset.right = length;
 969                inset.bottom = length;
 970                inset.left = length;
 971                self
 972            }
 973        }
 974        fn inset_3(mut self) -> Self
 975        where
 976            Self: Sized,
 977        {
 978            let length = DefinedLength::Rems(0.75).into();
 979            {
 980                let inset = self
 981                    .computed_style()
 982                    .inset
 983                    .get_or_insert_with(Default::default);
 984                inset.top = length;
 985                inset.right = length;
 986                inset.bottom = length;
 987                inset.left = length;
 988                self
 989            }
 990        }
 991        fn inset_3_5(mut self) -> Self
 992        where
 993            Self: Sized,
 994        {
 995            let length = DefinedLength::Rems(0.875).into();
 996            {
 997                let inset = self
 998                    .computed_style()
 999                    .inset
1000                    .get_or_insert_with(Default::default);
1001                inset.top = length;
1002                inset.right = length;
1003                inset.bottom = length;
1004                inset.left = length;
1005                self
1006            }
1007        }
1008        fn inset_4(mut self) -> Self
1009        where
1010            Self: Sized,
1011        {
1012            let length = DefinedLength::Rems(1.).into();
1013            {
1014                let inset = self
1015                    .computed_style()
1016                    .inset
1017                    .get_or_insert_with(Default::default);
1018                inset.top = length;
1019                inset.right = length;
1020                inset.bottom = length;
1021                inset.left = length;
1022                self
1023            }
1024        }
1025        fn inset_5(mut self) -> Self
1026        where
1027            Self: Sized,
1028        {
1029            let length = DefinedLength::Rems(1.25).into();
1030            {
1031                let inset = self
1032                    .computed_style()
1033                    .inset
1034                    .get_or_insert_with(Default::default);
1035                inset.top = length;
1036                inset.right = length;
1037                inset.bottom = length;
1038                inset.left = length;
1039                self
1040            }
1041        }
1042        fn inset_6(mut self) -> Self
1043        where
1044            Self: Sized,
1045        {
1046            let length = DefinedLength::Rems(1.5).into();
1047            {
1048                let inset = self
1049                    .computed_style()
1050                    .inset
1051                    .get_or_insert_with(Default::default);
1052                inset.top = length;
1053                inset.right = length;
1054                inset.bottom = length;
1055                inset.left = length;
1056                self
1057            }
1058        }
1059        fn inset_7(mut self) -> Self
1060        where
1061            Self: Sized,
1062        {
1063            let length = DefinedLength::Rems(1.75).into();
1064            {
1065                let inset = self
1066                    .computed_style()
1067                    .inset
1068                    .get_or_insert_with(Default::default);
1069                inset.top = length;
1070                inset.right = length;
1071                inset.bottom = length;
1072                inset.left = length;
1073                self
1074            }
1075        }
1076        fn inset_8(mut self) -> Self
1077        where
1078            Self: Sized,
1079        {
1080            let length = DefinedLength::Rems(2.).into();
1081            {
1082                let inset = self
1083                    .computed_style()
1084                    .inset
1085                    .get_or_insert_with(Default::default);
1086                inset.top = length;
1087                inset.right = length;
1088                inset.bottom = length;
1089                inset.left = length;
1090                self
1091            }
1092        }
1093        fn inset_9(mut self) -> Self
1094        where
1095            Self: Sized,
1096        {
1097            let length = DefinedLength::Rems(2.25).into();
1098            {
1099                let inset = self
1100                    .computed_style()
1101                    .inset
1102                    .get_or_insert_with(Default::default);
1103                inset.top = length;
1104                inset.right = length;
1105                inset.bottom = length;
1106                inset.left = length;
1107                self
1108            }
1109        }
1110        fn inset_10(mut self) -> Self
1111        where
1112            Self: Sized,
1113        {
1114            let length = DefinedLength::Rems(2.5).into();
1115            {
1116                let inset = self
1117                    .computed_style()
1118                    .inset
1119                    .get_or_insert_with(Default::default);
1120                inset.top = length;
1121                inset.right = length;
1122                inset.bottom = length;
1123                inset.left = length;
1124                self
1125            }
1126        }
1127        fn inset_11(mut self) -> Self
1128        where
1129            Self: Sized,
1130        {
1131            let length = DefinedLength::Rems(2.75).into();
1132            {
1133                let inset = self
1134                    .computed_style()
1135                    .inset
1136                    .get_or_insert_with(Default::default);
1137                inset.top = length;
1138                inset.right = length;
1139                inset.bottom = length;
1140                inset.left = length;
1141                self
1142            }
1143        }
1144        fn inset_12(mut self) -> Self
1145        where
1146            Self: Sized,
1147        {
1148            let length = DefinedLength::Rems(3.).into();
1149            {
1150                let inset = self
1151                    .computed_style()
1152                    .inset
1153                    .get_or_insert_with(Default::default);
1154                inset.top = length;
1155                inset.right = length;
1156                inset.bottom = length;
1157                inset.left = length;
1158                self
1159            }
1160        }
1161        fn inset_14(mut self) -> Self
1162        where
1163            Self: Sized,
1164        {
1165            let length = DefinedLength::Rems(3.5).into();
1166            {
1167                let inset = self
1168                    .computed_style()
1169                    .inset
1170                    .get_or_insert_with(Default::default);
1171                inset.top = length;
1172                inset.right = length;
1173                inset.bottom = length;
1174                inset.left = length;
1175                self
1176            }
1177        }
1178        fn inset_16(mut self) -> Self
1179        where
1180            Self: Sized,
1181        {
1182            let length = DefinedLength::Rems(4.).into();
1183            {
1184                let inset = self
1185                    .computed_style()
1186                    .inset
1187                    .get_or_insert_with(Default::default);
1188                inset.top = length;
1189                inset.right = length;
1190                inset.bottom = length;
1191                inset.left = length;
1192                self
1193            }
1194        }
1195        fn inset_20(mut self) -> Self
1196        where
1197            Self: Sized,
1198        {
1199            let length = DefinedLength::Rems(5.).into();
1200            {
1201                let inset = self
1202                    .computed_style()
1203                    .inset
1204                    .get_or_insert_with(Default::default);
1205                inset.top = length;
1206                inset.right = length;
1207                inset.bottom = length;
1208                inset.left = length;
1209                self
1210            }
1211        }
1212        fn inset_24(mut self) -> Self
1213        where
1214            Self: Sized,
1215        {
1216            let length = DefinedLength::Rems(6.).into();
1217            {
1218                let inset = self
1219                    .computed_style()
1220                    .inset
1221                    .get_or_insert_with(Default::default);
1222                inset.top = length;
1223                inset.right = length;
1224                inset.bottom = length;
1225                inset.left = length;
1226                self
1227            }
1228        }
1229        fn inset_28(mut self) -> Self
1230        where
1231            Self: Sized,
1232        {
1233            let length = DefinedLength::Rems(7.).into();
1234            {
1235                let inset = self
1236                    .computed_style()
1237                    .inset
1238                    .get_or_insert_with(Default::default);
1239                inset.top = length;
1240                inset.right = length;
1241                inset.bottom = length;
1242                inset.left = length;
1243                self
1244            }
1245        }
1246        fn inset_32(mut self) -> Self
1247        where
1248            Self: Sized,
1249        {
1250            let length = DefinedLength::Rems(8.).into();
1251            {
1252                let inset = self
1253                    .computed_style()
1254                    .inset
1255                    .get_or_insert_with(Default::default);
1256                inset.top = length;
1257                inset.right = length;
1258                inset.bottom = length;
1259                inset.left = length;
1260                self
1261            }
1262        }
1263        fn inset_36(mut self) -> Self
1264        where
1265            Self: Sized,
1266        {
1267            let length = DefinedLength::Rems(9.).into();
1268            {
1269                let inset = self
1270                    .computed_style()
1271                    .inset
1272                    .get_or_insert_with(Default::default);
1273                inset.top = length;
1274                inset.right = length;
1275                inset.bottom = length;
1276                inset.left = length;
1277                self
1278            }
1279        }
1280        fn inset_40(mut self) -> Self
1281        where
1282            Self: Sized,
1283        {
1284            let length = DefinedLength::Rems(10.).into();
1285            {
1286                let inset = self
1287                    .computed_style()
1288                    .inset
1289                    .get_or_insert_with(Default::default);
1290                inset.top = length;
1291                inset.right = length;
1292                inset.bottom = length;
1293                inset.left = length;
1294                self
1295            }
1296        }
1297        fn inset_44(mut self) -> Self
1298        where
1299            Self: Sized,
1300        {
1301            let length = DefinedLength::Rems(11.).into();
1302            {
1303                let inset = self
1304                    .computed_style()
1305                    .inset
1306                    .get_or_insert_with(Default::default);
1307                inset.top = length;
1308                inset.right = length;
1309                inset.bottom = length;
1310                inset.left = length;
1311                self
1312            }
1313        }
1314        fn inset_48(mut self) -> Self
1315        where
1316            Self: Sized,
1317        {
1318            let length = DefinedLength::Rems(12.).into();
1319            {
1320                let inset = self
1321                    .computed_style()
1322                    .inset
1323                    .get_or_insert_with(Default::default);
1324                inset.top = length;
1325                inset.right = length;
1326                inset.bottom = length;
1327                inset.left = length;
1328                self
1329            }
1330        }
1331        fn inset_52(mut self) -> Self
1332        where
1333            Self: Sized,
1334        {
1335            let length = DefinedLength::Rems(13.).into();
1336            {
1337                let inset = self
1338                    .computed_style()
1339                    .inset
1340                    .get_or_insert_with(Default::default);
1341                inset.top = length;
1342                inset.right = length;
1343                inset.bottom = length;
1344                inset.left = length;
1345                self
1346            }
1347        }
1348        fn inset_56(mut self) -> Self
1349        where
1350            Self: Sized,
1351        {
1352            let length = DefinedLength::Rems(14.).into();
1353            {
1354                let inset = self
1355                    .computed_style()
1356                    .inset
1357                    .get_or_insert_with(Default::default);
1358                inset.top = length;
1359                inset.right = length;
1360                inset.bottom = length;
1361                inset.left = length;
1362                self
1363            }
1364        }
1365        fn inset_60(mut self) -> Self
1366        where
1367            Self: Sized,
1368        {
1369            let length = DefinedLength::Rems(15.).into();
1370            {
1371                let inset = self
1372                    .computed_style()
1373                    .inset
1374                    .get_or_insert_with(Default::default);
1375                inset.top = length;
1376                inset.right = length;
1377                inset.bottom = length;
1378                inset.left = length;
1379                self
1380            }
1381        }
1382        fn inset_64(mut self) -> Self
1383        where
1384            Self: Sized,
1385        {
1386            let length = DefinedLength::Rems(16.).into();
1387            {
1388                let inset = self
1389                    .computed_style()
1390                    .inset
1391                    .get_or_insert_with(Default::default);
1392                inset.top = length;
1393                inset.right = length;
1394                inset.bottom = length;
1395                inset.left = length;
1396                self
1397            }
1398        }
1399        fn inset_72(mut self) -> Self
1400        where
1401            Self: Sized,
1402        {
1403            let length = DefinedLength::Rems(18.).into();
1404            {
1405                let inset = self
1406                    .computed_style()
1407                    .inset
1408                    .get_or_insert_with(Default::default);
1409                inset.top = length;
1410                inset.right = length;
1411                inset.bottom = length;
1412                inset.left = length;
1413                self
1414            }
1415        }
1416        fn inset_80(mut self) -> Self
1417        where
1418            Self: Sized,
1419        {
1420            let length = DefinedLength::Rems(20.).into();
1421            {
1422                let inset = self
1423                    .computed_style()
1424                    .inset
1425                    .get_or_insert_with(Default::default);
1426                inset.top = length;
1427                inset.right = length;
1428                inset.bottom = length;
1429                inset.left = length;
1430                self
1431            }
1432        }
1433        fn inset_96(mut self) -> Self
1434        where
1435            Self: Sized,
1436        {
1437            let length = DefinedLength::Rems(24.).into();
1438            {
1439                let inset = self
1440                    .computed_style()
1441                    .inset
1442                    .get_or_insert_with(Default::default);
1443                inset.top = length;
1444                inset.right = length;
1445                inset.bottom = length;
1446                inset.left = length;
1447                self
1448            }
1449        }
1450        fn inset_half(mut self) -> Self
1451        where
1452            Self: Sized,
1453        {
1454            let length = DefinedLength::Percent(50.).into();
1455            {
1456                let inset = self
1457                    .computed_style()
1458                    .inset
1459                    .get_or_insert_with(Default::default);
1460                inset.top = length;
1461                inset.right = length;
1462                inset.bottom = length;
1463                inset.left = length;
1464                self
1465            }
1466        }
1467        fn inset_1_3rd(mut self) -> Self
1468        where
1469            Self: Sized,
1470        {
1471            let length = DefinedLength::Percent(33.333333).into();
1472            {
1473                let inset = self
1474                    .computed_style()
1475                    .inset
1476                    .get_or_insert_with(Default::default);
1477                inset.top = length;
1478                inset.right = length;
1479                inset.bottom = length;
1480                inset.left = length;
1481                self
1482            }
1483        }
1484        fn inset_2_3rd(mut self) -> Self
1485        where
1486            Self: Sized,
1487        {
1488            let length = DefinedLength::Percent(66.666667).into();
1489            {
1490                let inset = self
1491                    .computed_style()
1492                    .inset
1493                    .get_or_insert_with(Default::default);
1494                inset.top = length;
1495                inset.right = length;
1496                inset.bottom = length;
1497                inset.left = length;
1498                self
1499            }
1500        }
1501        fn inset_1_4th(mut self) -> Self
1502        where
1503            Self: Sized,
1504        {
1505            let length = DefinedLength::Percent(25.).into();
1506            {
1507                let inset = self
1508                    .computed_style()
1509                    .inset
1510                    .get_or_insert_with(Default::default);
1511                inset.top = length;
1512                inset.right = length;
1513                inset.bottom = length;
1514                inset.left = length;
1515                self
1516            }
1517        }
1518        fn inset_2_4th(mut self) -> Self
1519        where
1520            Self: Sized,
1521        {
1522            let length = DefinedLength::Percent(50.).into();
1523            {
1524                let inset = self
1525                    .computed_style()
1526                    .inset
1527                    .get_or_insert_with(Default::default);
1528                inset.top = length;
1529                inset.right = length;
1530                inset.bottom = length;
1531                inset.left = length;
1532                self
1533            }
1534        }
1535        fn inset_3_4th(mut self) -> Self
1536        where
1537            Self: Sized,
1538        {
1539            let length = DefinedLength::Percent(75.).into();
1540            {
1541                let inset = self
1542                    .computed_style()
1543                    .inset
1544                    .get_or_insert_with(Default::default);
1545                inset.top = length;
1546                inset.right = length;
1547                inset.bottom = length;
1548                inset.left = length;
1549                self
1550            }
1551        }
1552        fn inset_1_5th(mut self) -> Self
1553        where
1554            Self: Sized,
1555        {
1556            let length = DefinedLength::Percent(20.).into();
1557            {
1558                let inset = self
1559                    .computed_style()
1560                    .inset
1561                    .get_or_insert_with(Default::default);
1562                inset.top = length;
1563                inset.right = length;
1564                inset.bottom = length;
1565                inset.left = length;
1566                self
1567            }
1568        }
1569        fn inset_2_5th(mut self) -> Self
1570        where
1571            Self: Sized,
1572        {
1573            let length = DefinedLength::Percent(40.).into();
1574            {
1575                let inset = self
1576                    .computed_style()
1577                    .inset
1578                    .get_or_insert_with(Default::default);
1579                inset.top = length;
1580                inset.right = length;
1581                inset.bottom = length;
1582                inset.left = length;
1583                self
1584            }
1585        }
1586        fn inset_3_5th(mut self) -> Self
1587        where
1588            Self: Sized,
1589        {
1590            let length = DefinedLength::Percent(60.).into();
1591            {
1592                let inset = self
1593                    .computed_style()
1594                    .inset
1595                    .get_or_insert_with(Default::default);
1596                inset.top = length;
1597                inset.right = length;
1598                inset.bottom = length;
1599                inset.left = length;
1600                self
1601            }
1602        }
1603        fn inset_4_5th(mut self) -> Self
1604        where
1605            Self: Sized,
1606        {
1607            let length = DefinedLength::Percent(80.).into();
1608            {
1609                let inset = self
1610                    .computed_style()
1611                    .inset
1612                    .get_or_insert_with(Default::default);
1613                inset.top = length;
1614                inset.right = length;
1615                inset.bottom = length;
1616                inset.left = length;
1617                self
1618            }
1619        }
1620        fn inset_1_6th(mut self) -> Self
1621        where
1622            Self: Sized,
1623        {
1624            let length = DefinedLength::Percent(16.666667).into();
1625            {
1626                let inset = self
1627                    .computed_style()
1628                    .inset
1629                    .get_or_insert_with(Default::default);
1630                inset.top = length;
1631                inset.right = length;
1632                inset.bottom = length;
1633                inset.left = length;
1634                self
1635            }
1636        }
1637        fn inset_2_6th(mut self) -> Self
1638        where
1639            Self: Sized,
1640        {
1641            let length = DefinedLength::Percent(33.333333).into();
1642            {
1643                let inset = self
1644                    .computed_style()
1645                    .inset
1646                    .get_or_insert_with(Default::default);
1647                inset.top = length;
1648                inset.right = length;
1649                inset.bottom = length;
1650                inset.left = length;
1651                self
1652            }
1653        }
1654        fn inset_3_6th(mut self) -> Self
1655        where
1656            Self: Sized,
1657        {
1658            let length = DefinedLength::Percent(50.).into();
1659            {
1660                let inset = self
1661                    .computed_style()
1662                    .inset
1663                    .get_or_insert_with(Default::default);
1664                inset.top = length;
1665                inset.right = length;
1666                inset.bottom = length;
1667                inset.left = length;
1668                self
1669            }
1670        }
1671        fn inset_4_6th(mut self) -> Self
1672        where
1673            Self: Sized,
1674        {
1675            let length = DefinedLength::Percent(66.666667).into();
1676            {
1677                let inset = self
1678                    .computed_style()
1679                    .inset
1680                    .get_or_insert_with(Default::default);
1681                inset.top = length;
1682                inset.right = length;
1683                inset.bottom = length;
1684                inset.left = length;
1685                self
1686            }
1687        }
1688        fn inset_5_6th(mut self) -> Self
1689        where
1690            Self: Sized,
1691        {
1692            let length = DefinedLength::Percent(83.333333).into();
1693            {
1694                let inset = self
1695                    .computed_style()
1696                    .inset
1697                    .get_or_insert_with(Default::default);
1698                inset.top = length;
1699                inset.right = length;
1700                inset.bottom = length;
1701                inset.left = length;
1702                self
1703            }
1704        }
1705        fn inset_1_12th(mut self) -> Self
1706        where
1707            Self: Sized,
1708        {
1709            let length = DefinedLength::Percent(8.333333).into();
1710            {
1711                let inset = self
1712                    .computed_style()
1713                    .inset
1714                    .get_or_insert_with(Default::default);
1715                inset.top = length;
1716                inset.right = length;
1717                inset.bottom = length;
1718                inset.left = length;
1719                self
1720            }
1721        }
1722        fn inset_2_12th(mut self) -> Self
1723        where
1724            Self: Sized,
1725        {
1726            let length = DefinedLength::Percent(16.666667).into();
1727            {
1728                let inset = self
1729                    .computed_style()
1730                    .inset
1731                    .get_or_insert_with(Default::default);
1732                inset.top = length;
1733                inset.right = length;
1734                inset.bottom = length;
1735                inset.left = length;
1736                self
1737            }
1738        }
1739        fn inset_3_12th(mut self) -> Self
1740        where
1741            Self: Sized,
1742        {
1743            let length = DefinedLength::Percent(25.).into();
1744            {
1745                let inset = self
1746                    .computed_style()
1747                    .inset
1748                    .get_or_insert_with(Default::default);
1749                inset.top = length;
1750                inset.right = length;
1751                inset.bottom = length;
1752                inset.left = length;
1753                self
1754            }
1755        }
1756        fn inset_4_12th(mut self) -> Self
1757        where
1758            Self: Sized,
1759        {
1760            let length = DefinedLength::Percent(33.333333).into();
1761            {
1762                let inset = self
1763                    .computed_style()
1764                    .inset
1765                    .get_or_insert_with(Default::default);
1766                inset.top = length;
1767                inset.right = length;
1768                inset.bottom = length;
1769                inset.left = length;
1770                self
1771            }
1772        }
1773        fn inset_5_12th(mut self) -> Self
1774        where
1775            Self: Sized,
1776        {
1777            let length = DefinedLength::Percent(41.666667).into();
1778            {
1779                let inset = self
1780                    .computed_style()
1781                    .inset
1782                    .get_or_insert_with(Default::default);
1783                inset.top = length;
1784                inset.right = length;
1785                inset.bottom = length;
1786                inset.left = length;
1787                self
1788            }
1789        }
1790        fn inset_6_12th(mut self) -> Self
1791        where
1792            Self: Sized,
1793        {
1794            let length = DefinedLength::Percent(50.).into();
1795            {
1796                let inset = self
1797                    .computed_style()
1798                    .inset
1799                    .get_or_insert_with(Default::default);
1800                inset.top = length;
1801                inset.right = length;
1802                inset.bottom = length;
1803                inset.left = length;
1804                self
1805            }
1806        }
1807        fn inset_7_12th(mut self) -> Self
1808        where
1809            Self: Sized,
1810        {
1811            let length = DefinedLength::Percent(58.333333).into();
1812            {
1813                let inset = self
1814                    .computed_style()
1815                    .inset
1816                    .get_or_insert_with(Default::default);
1817                inset.top = length;
1818                inset.right = length;
1819                inset.bottom = length;
1820                inset.left = length;
1821                self
1822            }
1823        }
1824        fn inset_8_12th(mut self) -> Self
1825        where
1826            Self: Sized,
1827        {
1828            let length = DefinedLength::Percent(66.666667).into();
1829            {
1830                let inset = self
1831                    .computed_style()
1832                    .inset
1833                    .get_or_insert_with(Default::default);
1834                inset.top = length;
1835                inset.right = length;
1836                inset.bottom = length;
1837                inset.left = length;
1838                self
1839            }
1840        }
1841        fn inset_9_12th(mut self) -> Self
1842        where
1843            Self: Sized,
1844        {
1845            let length = DefinedLength::Percent(75.).into();
1846            {
1847                let inset = self
1848                    .computed_style()
1849                    .inset
1850                    .get_or_insert_with(Default::default);
1851                inset.top = length;
1852                inset.right = length;
1853                inset.bottom = length;
1854                inset.left = length;
1855                self
1856            }
1857        }
1858        fn inset_10_12th(mut self) -> Self
1859        where
1860            Self: Sized,
1861        {
1862            let length = DefinedLength::Percent(83.333333).into();
1863            {
1864                let inset = self
1865                    .computed_style()
1866                    .inset
1867                    .get_or_insert_with(Default::default);
1868                inset.top = length;
1869                inset.right = length;
1870                inset.bottom = length;
1871                inset.left = length;
1872                self
1873            }
1874        }
1875        fn inset_11_12th(mut self) -> Self
1876        where
1877            Self: Sized,
1878        {
1879            let length = DefinedLength::Percent(91.666667).into();
1880            {
1881                let inset = self
1882                    .computed_style()
1883                    .inset
1884                    .get_or_insert_with(Default::default);
1885                inset.top = length;
1886                inset.right = length;
1887                inset.bottom = length;
1888                inset.left = length;
1889                self
1890            }
1891        }
1892        fn inset_full(mut self) -> Self
1893        where
1894            Self: Sized,
1895        {
1896            let length = DefinedLength::Percent(100.).into();
1897            {
1898                let inset = self
1899                    .computed_style()
1900                    .inset
1901                    .get_or_insert_with(Default::default);
1902                inset.top = length;
1903                inset.right = length;
1904                inset.bottom = length;
1905                inset.left = length;
1906                self
1907            }
1908        }
1909        fn w(mut self, width: impl Into<Length>) -> Self
1910        where
1911            Self: Sized,
1912        {
1913            self.declared_style().size.width = Some(width.into());
1914            self
1915        }
1916        fn w_auto(mut self) -> Self
1917        where
1918            Self: Sized,
1919        {
1920            self.declared_style().size.width = Some(Length::Auto);
1921            self
1922        }
1923        fn w_0(mut self) -> Self
1924        where
1925            Self: Sized,
1926        {
1927            let length = DefinedLength::Pixels(0.).into();
1928            {
1929                self.declared_style().size.width = Some(length);
1930                self
1931            }
1932        }
1933        fn w_px(mut self) -> Self
1934        where
1935            Self: Sized,
1936        {
1937            let length = DefinedLength::Pixels(1.).into();
1938            {
1939                self.declared_style().size.width = Some(length);
1940                self
1941            }
1942        }
1943        fn w_0_5(mut self) -> Self
1944        where
1945            Self: Sized,
1946        {
1947            let length = DefinedLength::Rems(0.125).into();
1948            {
1949                self.declared_style().size.width = Some(length);
1950                self
1951            }
1952        }
1953        fn w_1(mut self) -> Self
1954        where
1955            Self: Sized,
1956        {
1957            let length = DefinedLength::Rems(0.25).into();
1958            {
1959                self.declared_style().size.width = Some(length);
1960                self
1961            }
1962        }
1963        fn w_1_5(mut self) -> Self
1964        where
1965            Self: Sized,
1966        {
1967            let length = DefinedLength::Rems(0.375).into();
1968            {
1969                self.declared_style().size.width = Some(length);
1970                self
1971            }
1972        }
1973        fn w_2(mut self) -> Self
1974        where
1975            Self: Sized,
1976        {
1977            let length = DefinedLength::Rems(0.5).into();
1978            {
1979                self.declared_style().size.width = Some(length);
1980                self
1981            }
1982        }
1983        fn w_2_5(mut self) -> Self
1984        where
1985            Self: Sized,
1986        {
1987            let length = DefinedLength::Rems(0.625).into();
1988            {
1989                self.declared_style().size.width = Some(length);
1990                self
1991            }
1992        }
1993        fn w_3(mut self) -> Self
1994        where
1995            Self: Sized,
1996        {
1997            let length = DefinedLength::Rems(0.75).into();
1998            {
1999                self.declared_style().size.width = Some(length);
2000                self
2001            }
2002        }
2003        fn w_3_5(mut self) -> Self
2004        where
2005            Self: Sized,
2006        {
2007            let length = DefinedLength::Rems(0.875).into();
2008            {
2009                self.declared_style().size.width = Some(length);
2010                self
2011            }
2012        }
2013        fn w_4(mut self) -> Self
2014        where
2015            Self: Sized,
2016        {
2017            let length = DefinedLength::Rems(1.).into();
2018            {
2019                self.declared_style().size.width = Some(length);
2020                self
2021            }
2022        }
2023        fn w_5(mut self) -> Self
2024        where
2025            Self: Sized,
2026        {
2027            let length = DefinedLength::Rems(1.25).into();
2028            {
2029                self.declared_style().size.width = Some(length);
2030                self
2031            }
2032        }
2033        fn w_6(mut self) -> Self
2034        where
2035            Self: Sized,
2036        {
2037            let length = DefinedLength::Rems(1.5).into();
2038            {
2039                self.declared_style().size.width = Some(length);
2040                self
2041            }
2042        }
2043        fn w_7(mut self) -> Self
2044        where
2045            Self: Sized,
2046        {
2047            let length = DefinedLength::Rems(1.75).into();
2048            {
2049                self.declared_style().size.width = Some(length);
2050                self
2051            }
2052        }
2053        fn w_8(mut self) -> Self
2054        where
2055            Self: Sized,
2056        {
2057            let length = DefinedLength::Rems(2.).into();
2058            {
2059                self.declared_style().size.width = Some(length);
2060                self
2061            }
2062        }
2063        fn w_9(mut self) -> Self
2064        where
2065            Self: Sized,
2066        {
2067            let length = DefinedLength::Rems(2.25).into();
2068            {
2069                self.declared_style().size.width = Some(length);
2070                self
2071            }
2072        }
2073        fn w_10(mut self) -> Self
2074        where
2075            Self: Sized,
2076        {
2077            let length = DefinedLength::Rems(2.5).into();
2078            {
2079                self.declared_style().size.width = Some(length);
2080                self
2081            }
2082        }
2083        fn w_11(mut self) -> Self
2084        where
2085            Self: Sized,
2086        {
2087            let length = DefinedLength::Rems(2.75).into();
2088            {
2089                self.declared_style().size.width = Some(length);
2090                self
2091            }
2092        }
2093        fn w_12(mut self) -> Self
2094        where
2095            Self: Sized,
2096        {
2097            let length = DefinedLength::Rems(3.).into();
2098            {
2099                self.declared_style().size.width = Some(length);
2100                self
2101            }
2102        }
2103        fn w_14(mut self) -> Self
2104        where
2105            Self: Sized,
2106        {
2107            let length = DefinedLength::Rems(3.5).into();
2108            {
2109                self.declared_style().size.width = Some(length);
2110                self
2111            }
2112        }
2113        fn w_16(mut self) -> Self
2114        where
2115            Self: Sized,
2116        {
2117            let length = DefinedLength::Rems(4.).into();
2118            {
2119                self.declared_style().size.width = Some(length);
2120                self
2121            }
2122        }
2123        fn w_20(mut self) -> Self
2124        where
2125            Self: Sized,
2126        {
2127            let length = DefinedLength::Rems(5.).into();
2128            {
2129                self.declared_style().size.width = Some(length);
2130                self
2131            }
2132        }
2133        fn w_24(mut self) -> Self
2134        where
2135            Self: Sized,
2136        {
2137            let length = DefinedLength::Rems(6.).into();
2138            {
2139                self.declared_style().size.width = Some(length);
2140                self
2141            }
2142        }
2143        fn w_28(mut self) -> Self
2144        where
2145            Self: Sized,
2146        {
2147            let length = DefinedLength::Rems(7.).into();
2148            {
2149                self.declared_style().size.width = Some(length);
2150                self
2151            }
2152        }
2153        fn w_32(mut self) -> Self
2154        where
2155            Self: Sized,
2156        {
2157            let length = DefinedLength::Rems(8.).into();
2158            {
2159                self.declared_style().size.width = Some(length);
2160                self
2161            }
2162        }
2163        fn w_36(mut self) -> Self
2164        where
2165            Self: Sized,
2166        {
2167            let length = DefinedLength::Rems(9.).into();
2168            {
2169                self.declared_style().size.width = Some(length);
2170                self
2171            }
2172        }
2173        fn w_40(mut self) -> Self
2174        where
2175            Self: Sized,
2176        {
2177            let length = DefinedLength::Rems(10.).into();
2178            {
2179                self.declared_style().size.width = Some(length);
2180                self
2181            }
2182        }
2183        fn w_44(mut self) -> Self
2184        where
2185            Self: Sized,
2186        {
2187            let length = DefinedLength::Rems(11.).into();
2188            {
2189                self.declared_style().size.width = Some(length);
2190                self
2191            }
2192        }
2193        fn w_48(mut self) -> Self
2194        where
2195            Self: Sized,
2196        {
2197            let length = DefinedLength::Rems(12.).into();
2198            {
2199                self.declared_style().size.width = Some(length);
2200                self
2201            }
2202        }
2203        fn w_52(mut self) -> Self
2204        where
2205            Self: Sized,
2206        {
2207            let length = DefinedLength::Rems(13.).into();
2208            {
2209                self.declared_style().size.width = Some(length);
2210                self
2211            }
2212        }
2213        fn w_56(mut self) -> Self
2214        where
2215            Self: Sized,
2216        {
2217            let length = DefinedLength::Rems(14.).into();
2218            {
2219                self.declared_style().size.width = Some(length);
2220                self
2221            }
2222        }
2223        fn w_60(mut self) -> Self
2224        where
2225            Self: Sized,
2226        {
2227            let length = DefinedLength::Rems(15.).into();
2228            {
2229                self.declared_style().size.width = Some(length);
2230                self
2231            }
2232        }
2233        fn w_64(mut self) -> Self
2234        where
2235            Self: Sized,
2236        {
2237            let length = DefinedLength::Rems(16.).into();
2238            {
2239                self.declared_style().size.width = Some(length);
2240                self
2241            }
2242        }
2243        fn w_72(mut self) -> Self
2244        where
2245            Self: Sized,
2246        {
2247            let length = DefinedLength::Rems(18.).into();
2248            {
2249                self.declared_style().size.width = Some(length);
2250                self
2251            }
2252        }
2253        fn w_80(mut self) -> Self
2254        where
2255            Self: Sized,
2256        {
2257            let length = DefinedLength::Rems(20.).into();
2258            {
2259                self.declared_style().size.width = Some(length);
2260                self
2261            }
2262        }
2263        fn w_96(mut self) -> Self
2264        where
2265            Self: Sized,
2266        {
2267            let length = DefinedLength::Rems(24.).into();
2268            {
2269                self.declared_style().size.width = Some(length);
2270                self
2271            }
2272        }
2273        fn w_half(mut self) -> Self
2274        where
2275            Self: Sized,
2276        {
2277            let length = DefinedLength::Percent(50.).into();
2278            {
2279                self.declared_style().size.width = Some(length);
2280                self
2281            }
2282        }
2283        fn w_1_3rd(mut self) -> Self
2284        where
2285            Self: Sized,
2286        {
2287            let length = DefinedLength::Percent(33.333333).into();
2288            {
2289                self.declared_style().size.width = Some(length);
2290                self
2291            }
2292        }
2293        fn w_2_3rd(mut self) -> Self
2294        where
2295            Self: Sized,
2296        {
2297            let length = DefinedLength::Percent(66.666667).into();
2298            {
2299                self.declared_style().size.width = Some(length);
2300                self
2301            }
2302        }
2303        fn w_1_4th(mut self) -> Self
2304        where
2305            Self: Sized,
2306        {
2307            let length = DefinedLength::Percent(25.).into();
2308            {
2309                self.declared_style().size.width = Some(length);
2310                self
2311            }
2312        }
2313        fn w_2_4th(mut self) -> Self
2314        where
2315            Self: Sized,
2316        {
2317            let length = DefinedLength::Percent(50.).into();
2318            {
2319                self.declared_style().size.width = Some(length);
2320                self
2321            }
2322        }
2323        fn w_3_4th(mut self) -> Self
2324        where
2325            Self: Sized,
2326        {
2327            let length = DefinedLength::Percent(75.).into();
2328            {
2329                self.declared_style().size.width = Some(length);
2330                self
2331            }
2332        }
2333        fn w_1_5th(mut self) -> Self
2334        where
2335            Self: Sized,
2336        {
2337            let length = DefinedLength::Percent(20.).into();
2338            {
2339                self.declared_style().size.width = Some(length);
2340                self
2341            }
2342        }
2343        fn w_2_5th(mut self) -> Self
2344        where
2345            Self: Sized,
2346        {
2347            let length = DefinedLength::Percent(40.).into();
2348            {
2349                self.declared_style().size.width = Some(length);
2350                self
2351            }
2352        }
2353        fn w_3_5th(mut self) -> Self
2354        where
2355            Self: Sized,
2356        {
2357            let length = DefinedLength::Percent(60.).into();
2358            {
2359                self.declared_style().size.width = Some(length);
2360                self
2361            }
2362        }
2363        fn w_4_5th(mut self) -> Self
2364        where
2365            Self: Sized,
2366        {
2367            let length = DefinedLength::Percent(80.).into();
2368            {
2369                self.declared_style().size.width = Some(length);
2370                self
2371            }
2372        }
2373        fn w_1_6th(mut self) -> Self
2374        where
2375            Self: Sized,
2376        {
2377            let length = DefinedLength::Percent(16.666667).into();
2378            {
2379                self.declared_style().size.width = Some(length);
2380                self
2381            }
2382        }
2383        fn w_2_6th(mut self) -> Self
2384        where
2385            Self: Sized,
2386        {
2387            let length = DefinedLength::Percent(33.333333).into();
2388            {
2389                self.declared_style().size.width = Some(length);
2390                self
2391            }
2392        }
2393        fn w_3_6th(mut self) -> Self
2394        where
2395            Self: Sized,
2396        {
2397            let length = DefinedLength::Percent(50.).into();
2398            {
2399                self.declared_style().size.width = Some(length);
2400                self
2401            }
2402        }
2403        fn w_4_6th(mut self) -> Self
2404        where
2405            Self: Sized,
2406        {
2407            let length = DefinedLength::Percent(66.666667).into();
2408            {
2409                self.declared_style().size.width = Some(length);
2410                self
2411            }
2412        }
2413        fn w_5_6th(mut self) -> Self
2414        where
2415            Self: Sized,
2416        {
2417            let length = DefinedLength::Percent(83.333333).into();
2418            {
2419                self.declared_style().size.width = Some(length);
2420                self
2421            }
2422        }
2423        fn w_1_12th(mut self) -> Self
2424        where
2425            Self: Sized,
2426        {
2427            let length = DefinedLength::Percent(8.333333).into();
2428            {
2429                self.declared_style().size.width = Some(length);
2430                self
2431            }
2432        }
2433        fn w_2_12th(mut self) -> Self
2434        where
2435            Self: Sized,
2436        {
2437            let length = DefinedLength::Percent(16.666667).into();
2438            {
2439                self.declared_style().size.width = Some(length);
2440                self
2441            }
2442        }
2443        fn w_3_12th(mut self) -> Self
2444        where
2445            Self: Sized,
2446        {
2447            let length = DefinedLength::Percent(25.).into();
2448            {
2449                self.declared_style().size.width = Some(length);
2450                self
2451            }
2452        }
2453        fn w_4_12th(mut self) -> Self
2454        where
2455            Self: Sized,
2456        {
2457            let length = DefinedLength::Percent(33.333333).into();
2458            {
2459                self.declared_style().size.width = Some(length);
2460                self
2461            }
2462        }
2463        fn w_5_12th(mut self) -> Self
2464        where
2465            Self: Sized,
2466        {
2467            let length = DefinedLength::Percent(41.666667).into();
2468            {
2469                self.declared_style().size.width = Some(length);
2470                self
2471            }
2472        }
2473        fn w_6_12th(mut self) -> Self
2474        where
2475            Self: Sized,
2476        {
2477            let length = DefinedLength::Percent(50.).into();
2478            {
2479                self.declared_style().size.width = Some(length);
2480                self
2481            }
2482        }
2483        fn w_7_12th(mut self) -> Self
2484        where
2485            Self: Sized,
2486        {
2487            let length = DefinedLength::Percent(58.333333).into();
2488            {
2489                self.declared_style().size.width = Some(length);
2490                self
2491            }
2492        }
2493        fn w_8_12th(mut self) -> Self
2494        where
2495            Self: Sized,
2496        {
2497            let length = DefinedLength::Percent(66.666667).into();
2498            {
2499                self.declared_style().size.width = Some(length);
2500                self
2501            }
2502        }
2503        fn w_9_12th(mut self) -> Self
2504        where
2505            Self: Sized,
2506        {
2507            let length = DefinedLength::Percent(75.).into();
2508            {
2509                self.declared_style().size.width = Some(length);
2510                self
2511            }
2512        }
2513        fn w_10_12th(mut self) -> Self
2514        where
2515            Self: Sized,
2516        {
2517            let length = DefinedLength::Percent(83.333333).into();
2518            {
2519                self.declared_style().size.width = Some(length);
2520                self
2521            }
2522        }
2523        fn w_11_12th(mut self) -> Self
2524        where
2525            Self: Sized,
2526        {
2527            let length = DefinedLength::Percent(91.666667).into();
2528            {
2529                self.declared_style().size.width = Some(length);
2530                self
2531            }
2532        }
2533        fn w_full(mut self) -> Self
2534        where
2535            Self: Sized,
2536        {
2537            let length = DefinedLength::Percent(100.).into();
2538            {
2539                self.declared_style().size.width = Some(length);
2540                self
2541            }
2542        }
2543        fn min_w_0(mut self) -> Self
2544        where
2545            Self: Sized,
2546        {
2547            let length = DefinedLength::Pixels(0.).into();
2548            {
2549                self.declared_style().min_size.width = Some(length);
2550                self
2551            }
2552        }
2553        fn min_w_px(mut self) -> Self
2554        where
2555            Self: Sized,
2556        {
2557            let length = DefinedLength::Pixels(1.).into();
2558            {
2559                self.declared_style().min_size.width = Some(length);
2560                self
2561            }
2562        }
2563        fn min_w_0_5(mut self) -> Self
2564        where
2565            Self: Sized,
2566        {
2567            let length = DefinedLength::Rems(0.125).into();
2568            {
2569                self.declared_style().min_size.width = Some(length);
2570                self
2571            }
2572        }
2573        fn min_w_1(mut self) -> Self
2574        where
2575            Self: Sized,
2576        {
2577            let length = DefinedLength::Rems(0.25).into();
2578            {
2579                self.declared_style().min_size.width = Some(length);
2580                self
2581            }
2582        }
2583        fn min_w_1_5(mut self) -> Self
2584        where
2585            Self: Sized,
2586        {
2587            let length = DefinedLength::Rems(0.375).into();
2588            {
2589                self.declared_style().min_size.width = Some(length);
2590                self
2591            }
2592        }
2593        fn min_w_2(mut self) -> Self
2594        where
2595            Self: Sized,
2596        {
2597            let length = DefinedLength::Rems(0.5).into();
2598            {
2599                self.declared_style().min_size.width = Some(length);
2600                self
2601            }
2602        }
2603        fn min_w_2_5(mut self) -> Self
2604        where
2605            Self: Sized,
2606        {
2607            let length = DefinedLength::Rems(0.625).into();
2608            {
2609                self.declared_style().min_size.width = Some(length);
2610                self
2611            }
2612        }
2613        fn min_w_3(mut self) -> Self
2614        where
2615            Self: Sized,
2616        {
2617            let length = DefinedLength::Rems(0.75).into();
2618            {
2619                self.declared_style().min_size.width = Some(length);
2620                self
2621            }
2622        }
2623        fn min_w_3_5(mut self) -> Self
2624        where
2625            Self: Sized,
2626        {
2627            let length = DefinedLength::Rems(0.875).into();
2628            {
2629                self.declared_style().min_size.width = Some(length);
2630                self
2631            }
2632        }
2633        fn min_w_4(mut self) -> Self
2634        where
2635            Self: Sized,
2636        {
2637            let length = DefinedLength::Rems(1.).into();
2638            {
2639                self.declared_style().min_size.width = Some(length);
2640                self
2641            }
2642        }
2643        fn min_w_5(mut self) -> Self
2644        where
2645            Self: Sized,
2646        {
2647            let length = DefinedLength::Rems(1.25).into();
2648            {
2649                self.declared_style().min_size.width = Some(length);
2650                self
2651            }
2652        }
2653        fn min_w_6(mut self) -> Self
2654        where
2655            Self: Sized,
2656        {
2657            let length = DefinedLength::Rems(1.5).into();
2658            {
2659                self.declared_style().min_size.width = Some(length);
2660                self
2661            }
2662        }
2663        fn min_w_7(mut self) -> Self
2664        where
2665            Self: Sized,
2666        {
2667            let length = DefinedLength::Rems(1.75).into();
2668            {
2669                self.declared_style().min_size.width = Some(length);
2670                self
2671            }
2672        }
2673        fn min_w_8(mut self) -> Self
2674        where
2675            Self: Sized,
2676        {
2677            let length = DefinedLength::Rems(2.).into();
2678            {
2679                self.declared_style().min_size.width = Some(length);
2680                self
2681            }
2682        }
2683        fn min_w_9(mut self) -> Self
2684        where
2685            Self: Sized,
2686        {
2687            let length = DefinedLength::Rems(2.25).into();
2688            {
2689                self.declared_style().min_size.width = Some(length);
2690                self
2691            }
2692        }
2693        fn min_w_10(mut self) -> Self
2694        where
2695            Self: Sized,
2696        {
2697            let length = DefinedLength::Rems(2.5).into();
2698            {
2699                self.declared_style().min_size.width = Some(length);
2700                self
2701            }
2702        }
2703        fn min_w_11(mut self) -> Self
2704        where
2705            Self: Sized,
2706        {
2707            let length = DefinedLength::Rems(2.75).into();
2708            {
2709                self.declared_style().min_size.width = Some(length);
2710                self
2711            }
2712        }
2713        fn min_w_12(mut self) -> Self
2714        where
2715            Self: Sized,
2716        {
2717            let length = DefinedLength::Rems(3.).into();
2718            {
2719                self.declared_style().min_size.width = Some(length);
2720                self
2721            }
2722        }
2723        fn min_w_14(mut self) -> Self
2724        where
2725            Self: Sized,
2726        {
2727            let length = DefinedLength::Rems(3.5).into();
2728            {
2729                self.declared_style().min_size.width = Some(length);
2730                self
2731            }
2732        }
2733        fn min_w_16(mut self) -> Self
2734        where
2735            Self: Sized,
2736        {
2737            let length = DefinedLength::Rems(4.).into();
2738            {
2739                self.declared_style().min_size.width = Some(length);
2740                self
2741            }
2742        }
2743        fn min_w_20(mut self) -> Self
2744        where
2745            Self: Sized,
2746        {
2747            let length = DefinedLength::Rems(5.).into();
2748            {
2749                self.declared_style().min_size.width = Some(length);
2750                self
2751            }
2752        }
2753        fn min_w_24(mut self) -> Self
2754        where
2755            Self: Sized,
2756        {
2757            let length = DefinedLength::Rems(6.).into();
2758            {
2759                self.declared_style().min_size.width = Some(length);
2760                self
2761            }
2762        }
2763        fn min_w_28(mut self) -> Self
2764        where
2765            Self: Sized,
2766        {
2767            let length = DefinedLength::Rems(7.).into();
2768            {
2769                self.declared_style().min_size.width = Some(length);
2770                self
2771            }
2772        }
2773        fn min_w_32(mut self) -> Self
2774        where
2775            Self: Sized,
2776        {
2777            let length = DefinedLength::Rems(8.).into();
2778            {
2779                self.declared_style().min_size.width = Some(length);
2780                self
2781            }
2782        }
2783        fn min_w_36(mut self) -> Self
2784        where
2785            Self: Sized,
2786        {
2787            let length = DefinedLength::Rems(9.).into();
2788            {
2789                self.declared_style().min_size.width = Some(length);
2790                self
2791            }
2792        }
2793        fn min_w_40(mut self) -> Self
2794        where
2795            Self: Sized,
2796        {
2797            let length = DefinedLength::Rems(10.).into();
2798            {
2799                self.declared_style().min_size.width = Some(length);
2800                self
2801            }
2802        }
2803        fn min_w_44(mut self) -> Self
2804        where
2805            Self: Sized,
2806        {
2807            let length = DefinedLength::Rems(11.).into();
2808            {
2809                self.declared_style().min_size.width = Some(length);
2810                self
2811            }
2812        }
2813        fn min_w_48(mut self) -> Self
2814        where
2815            Self: Sized,
2816        {
2817            let length = DefinedLength::Rems(12.).into();
2818            {
2819                self.declared_style().min_size.width = Some(length);
2820                self
2821            }
2822        }
2823        fn min_w_52(mut self) -> Self
2824        where
2825            Self: Sized,
2826        {
2827            let length = DefinedLength::Rems(13.).into();
2828            {
2829                self.declared_style().min_size.width = Some(length);
2830                self
2831            }
2832        }
2833        fn min_w_56(mut self) -> Self
2834        where
2835            Self: Sized,
2836        {
2837            let length = DefinedLength::Rems(14.).into();
2838            {
2839                self.declared_style().min_size.width = Some(length);
2840                self
2841            }
2842        }
2843        fn min_w_60(mut self) -> Self
2844        where
2845            Self: Sized,
2846        {
2847            let length = DefinedLength::Rems(15.).into();
2848            {
2849                self.declared_style().min_size.width = Some(length);
2850                self
2851            }
2852        }
2853        fn min_w_64(mut self) -> Self
2854        where
2855            Self: Sized,
2856        {
2857            let length = DefinedLength::Rems(16.).into();
2858            {
2859                self.declared_style().min_size.width = Some(length);
2860                self
2861            }
2862        }
2863        fn min_w_72(mut self) -> Self
2864        where
2865            Self: Sized,
2866        {
2867            let length = DefinedLength::Rems(18.).into();
2868            {
2869                self.declared_style().min_size.width = Some(length);
2870                self
2871            }
2872        }
2873        fn min_w_80(mut self) -> Self
2874        where
2875            Self: Sized,
2876        {
2877            let length = DefinedLength::Rems(20.).into();
2878            {
2879                self.declared_style().min_size.width = Some(length);
2880                self
2881            }
2882        }
2883        fn min_w_96(mut self) -> Self
2884        where
2885            Self: Sized,
2886        {
2887            let length = DefinedLength::Rems(24.).into();
2888            {
2889                self.declared_style().min_size.width = Some(length);
2890                self
2891            }
2892        }
2893        fn min_w_half(mut self) -> Self
2894        where
2895            Self: Sized,
2896        {
2897            let length = DefinedLength::Percent(50.).into();
2898            {
2899                self.declared_style().min_size.width = Some(length);
2900                self
2901            }
2902        }
2903        fn min_w_1_3rd(mut self) -> Self
2904        where
2905            Self: Sized,
2906        {
2907            let length = DefinedLength::Percent(33.333333).into();
2908            {
2909                self.declared_style().min_size.width = Some(length);
2910                self
2911            }
2912        }
2913        fn min_w_2_3rd(mut self) -> Self
2914        where
2915            Self: Sized,
2916        {
2917            let length = DefinedLength::Percent(66.666667).into();
2918            {
2919                self.declared_style().min_size.width = Some(length);
2920                self
2921            }
2922        }
2923        fn min_w_1_4th(mut self) -> Self
2924        where
2925            Self: Sized,
2926        {
2927            let length = DefinedLength::Percent(25.).into();
2928            {
2929                self.declared_style().min_size.width = Some(length);
2930                self
2931            }
2932        }
2933        fn min_w_2_4th(mut self) -> Self
2934        where
2935            Self: Sized,
2936        {
2937            let length = DefinedLength::Percent(50.).into();
2938            {
2939                self.declared_style().min_size.width = Some(length);
2940                self
2941            }
2942        }
2943        fn min_w_3_4th(mut self) -> Self
2944        where
2945            Self: Sized,
2946        {
2947            let length = DefinedLength::Percent(75.).into();
2948            {
2949                self.declared_style().min_size.width = Some(length);
2950                self
2951            }
2952        }
2953        fn min_w_1_5th(mut self) -> Self
2954        where
2955            Self: Sized,
2956        {
2957            let length = DefinedLength::Percent(20.).into();
2958            {
2959                self.declared_style().min_size.width = Some(length);
2960                self
2961            }
2962        }
2963        fn min_w_2_5th(mut self) -> Self
2964        where
2965            Self: Sized,
2966        {
2967            let length = DefinedLength::Percent(40.).into();
2968            {
2969                self.declared_style().min_size.width = Some(length);
2970                self
2971            }
2972        }
2973        fn min_w_3_5th(mut self) -> Self
2974        where
2975            Self: Sized,
2976        {
2977            let length = DefinedLength::Percent(60.).into();
2978            {
2979                self.declared_style().min_size.width = Some(length);
2980                self
2981            }
2982        }
2983        fn min_w_4_5th(mut self) -> Self
2984        where
2985            Self: Sized,
2986        {
2987            let length = DefinedLength::Percent(80.).into();
2988            {
2989                self.declared_style().min_size.width = Some(length);
2990                self
2991            }
2992        }
2993        fn min_w_1_6th(mut self) -> Self
2994        where
2995            Self: Sized,
2996        {
2997            let length = DefinedLength::Percent(16.666667).into();
2998            {
2999                self.declared_style().min_size.width = Some(length);
3000                self
3001            }
3002        }
3003        fn min_w_2_6th(mut self) -> Self
3004        where
3005            Self: Sized,
3006        {
3007            let length = DefinedLength::Percent(33.333333).into();
3008            {
3009                self.declared_style().min_size.width = Some(length);
3010                self
3011            }
3012        }
3013        fn min_w_3_6th(mut self) -> Self
3014        where
3015            Self: Sized,
3016        {
3017            let length = DefinedLength::Percent(50.).into();
3018            {
3019                self.declared_style().min_size.width = Some(length);
3020                self
3021            }
3022        }
3023        fn min_w_4_6th(mut self) -> Self
3024        where
3025            Self: Sized,
3026        {
3027            let length = DefinedLength::Percent(66.666667).into();
3028            {
3029                self.declared_style().min_size.width = Some(length);
3030                self
3031            }
3032        }
3033        fn min_w_5_6th(mut self) -> Self
3034        where
3035            Self: Sized,
3036        {
3037            let length = DefinedLength::Percent(83.333333).into();
3038            {
3039                self.declared_style().min_size.width = Some(length);
3040                self
3041            }
3042        }
3043        fn min_w_1_12th(mut self) -> Self
3044        where
3045            Self: Sized,
3046        {
3047            let length = DefinedLength::Percent(8.333333).into();
3048            {
3049                self.declared_style().min_size.width = Some(length);
3050                self
3051            }
3052        }
3053        fn min_w_2_12th(mut self) -> Self
3054        where
3055            Self: Sized,
3056        {
3057            let length = DefinedLength::Percent(16.666667).into();
3058            {
3059                self.declared_style().min_size.width = Some(length);
3060                self
3061            }
3062        }
3063        fn min_w_3_12th(mut self) -> Self
3064        where
3065            Self: Sized,
3066        {
3067            let length = DefinedLength::Percent(25.).into();
3068            {
3069                self.declared_style().min_size.width = Some(length);
3070                self
3071            }
3072        }
3073        fn min_w_4_12th(mut self) -> Self
3074        where
3075            Self: Sized,
3076        {
3077            let length = DefinedLength::Percent(33.333333).into();
3078            {
3079                self.declared_style().min_size.width = Some(length);
3080                self
3081            }
3082        }
3083        fn min_w_5_12th(mut self) -> Self
3084        where
3085            Self: Sized,
3086        {
3087            let length = DefinedLength::Percent(41.666667).into();
3088            {
3089                self.declared_style().min_size.width = Some(length);
3090                self
3091            }
3092        }
3093        fn min_w_6_12th(mut self) -> Self
3094        where
3095            Self: Sized,
3096        {
3097            let length = DefinedLength::Percent(50.).into();
3098            {
3099                self.declared_style().min_size.width = Some(length);
3100                self
3101            }
3102        }
3103        fn min_w_7_12th(mut self) -> Self
3104        where
3105            Self: Sized,
3106        {
3107            let length = DefinedLength::Percent(58.333333).into();
3108            {
3109                self.declared_style().min_size.width = Some(length);
3110                self
3111            }
3112        }
3113        fn min_w_8_12th(mut self) -> Self
3114        where
3115            Self: Sized,
3116        {
3117            let length = DefinedLength::Percent(66.666667).into();
3118            {
3119                self.declared_style().min_size.width = Some(length);
3120                self
3121            }
3122        }
3123        fn min_w_9_12th(mut self) -> Self
3124        where
3125            Self: Sized,
3126        {
3127            let length = DefinedLength::Percent(75.).into();
3128            {
3129                self.declared_style().min_size.width = Some(length);
3130                self
3131            }
3132        }
3133        fn min_w_10_12th(mut self) -> Self
3134        where
3135            Self: Sized,
3136        {
3137            let length = DefinedLength::Percent(83.333333).into();
3138            {
3139                self.declared_style().min_size.width = Some(length);
3140                self
3141            }
3142        }
3143        fn min_w_11_12th(mut self) -> Self
3144        where
3145            Self: Sized,
3146        {
3147            let length = DefinedLength::Percent(91.666667).into();
3148            {
3149                self.declared_style().min_size.width = Some(length);
3150                self
3151            }
3152        }
3153        fn min_w_full(mut self) -> Self
3154        where
3155            Self: Sized,
3156        {
3157            let length = DefinedLength::Percent(100.).into();
3158            {
3159                self.declared_style().min_size.width = Some(length);
3160                self
3161            }
3162        }
3163        fn h(mut self, height: impl Into<Length>) -> Self
3164        where
3165            Self: Sized,
3166        {
3167            self.declared_style().size.height = Some(height.into());
3168            self
3169        }
3170        fn h_auto(mut self) -> Self
3171        where
3172            Self: Sized,
3173        {
3174            self.declared_style().size.height = Some(Length::Auto);
3175            self
3176        }
3177        fn h_0(mut self) -> Self
3178        where
3179            Self: Sized,
3180        {
3181            let height = DefinedLength::Pixels(0.).into();
3182            {
3183                self.declared_style().size.height = Some(height);
3184                self
3185            }
3186        }
3187        fn h_px(mut self) -> Self
3188        where
3189            Self: Sized,
3190        {
3191            let height = DefinedLength::Pixels(1.).into();
3192            {
3193                self.declared_style().size.height = Some(height);
3194                self
3195            }
3196        }
3197        fn h_0_5(mut self) -> Self
3198        where
3199            Self: Sized,
3200        {
3201            let height = DefinedLength::Rems(0.125).into();
3202            {
3203                self.declared_style().size.height = Some(height);
3204                self
3205            }
3206        }
3207        fn h_1(mut self) -> Self
3208        where
3209            Self: Sized,
3210        {
3211            let height = DefinedLength::Rems(0.25).into();
3212            {
3213                self.declared_style().size.height = Some(height);
3214                self
3215            }
3216        }
3217        fn h_1_5(mut self) -> Self
3218        where
3219            Self: Sized,
3220        {
3221            let height = DefinedLength::Rems(0.375).into();
3222            {
3223                self.declared_style().size.height = Some(height);
3224                self
3225            }
3226        }
3227        fn h_2(mut self) -> Self
3228        where
3229            Self: Sized,
3230        {
3231            let height = DefinedLength::Rems(0.5).into();
3232            {
3233                self.declared_style().size.height = Some(height);
3234                self
3235            }
3236        }
3237        fn h_2_5(mut self) -> Self
3238        where
3239            Self: Sized,
3240        {
3241            let height = DefinedLength::Rems(0.625).into();
3242            {
3243                self.declared_style().size.height = Some(height);
3244                self
3245            }
3246        }
3247        fn h_3(mut self) -> Self
3248        where
3249            Self: Sized,
3250        {
3251            let height = DefinedLength::Rems(0.75).into();
3252            {
3253                self.declared_style().size.height = Some(height);
3254                self
3255            }
3256        }
3257        fn h_3_5(mut self) -> Self
3258        where
3259            Self: Sized,
3260        {
3261            let height = DefinedLength::Rems(0.875).into();
3262            {
3263                self.declared_style().size.height = Some(height);
3264                self
3265            }
3266        }
3267        fn h_4(mut self) -> Self
3268        where
3269            Self: Sized,
3270        {
3271            let height = DefinedLength::Rems(1.).into();
3272            {
3273                self.declared_style().size.height = Some(height);
3274                self
3275            }
3276        }
3277        fn h_5(mut self) -> Self
3278        where
3279            Self: Sized,
3280        {
3281            let height = DefinedLength::Rems(1.25).into();
3282            {
3283                self.declared_style().size.height = Some(height);
3284                self
3285            }
3286        }
3287        fn h_6(mut self) -> Self
3288        where
3289            Self: Sized,
3290        {
3291            let height = DefinedLength::Rems(1.5).into();
3292            {
3293                self.declared_style().size.height = Some(height);
3294                self
3295            }
3296        }
3297        fn h_7(mut self) -> Self
3298        where
3299            Self: Sized,
3300        {
3301            let height = DefinedLength::Rems(1.75).into();
3302            {
3303                self.declared_style().size.height = Some(height);
3304                self
3305            }
3306        }
3307        fn h_8(mut self) -> Self
3308        where
3309            Self: Sized,
3310        {
3311            let height = DefinedLength::Rems(2.).into();
3312            {
3313                self.declared_style().size.height = Some(height);
3314                self
3315            }
3316        }
3317        fn h_9(mut self) -> Self
3318        where
3319            Self: Sized,
3320        {
3321            let height = DefinedLength::Rems(2.25).into();
3322            {
3323                self.declared_style().size.height = Some(height);
3324                self
3325            }
3326        }
3327        fn h_10(mut self) -> Self
3328        where
3329            Self: Sized,
3330        {
3331            let height = DefinedLength::Rems(2.5).into();
3332            {
3333                self.declared_style().size.height = Some(height);
3334                self
3335            }
3336        }
3337        fn h_11(mut self) -> Self
3338        where
3339            Self: Sized,
3340        {
3341            let height = DefinedLength::Rems(2.75).into();
3342            {
3343                self.declared_style().size.height = Some(height);
3344                self
3345            }
3346        }
3347        fn h_12(mut self) -> Self
3348        where
3349            Self: Sized,
3350        {
3351            let height = DefinedLength::Rems(3.).into();
3352            {
3353                self.declared_style().size.height = Some(height);
3354                self
3355            }
3356        }
3357        fn h_14(mut self) -> Self
3358        where
3359            Self: Sized,
3360        {
3361            let height = DefinedLength::Rems(3.5).into();
3362            {
3363                self.declared_style().size.height = Some(height);
3364                self
3365            }
3366        }
3367        fn h_16(mut self) -> Self
3368        where
3369            Self: Sized,
3370        {
3371            let height = DefinedLength::Rems(4.).into();
3372            {
3373                self.declared_style().size.height = Some(height);
3374                self
3375            }
3376        }
3377        fn h_20(mut self) -> Self
3378        where
3379            Self: Sized,
3380        {
3381            let height = DefinedLength::Rems(5.).into();
3382            {
3383                self.declared_style().size.height = Some(height);
3384                self
3385            }
3386        }
3387        fn h_24(mut self) -> Self
3388        where
3389            Self: Sized,
3390        {
3391            let height = DefinedLength::Rems(6.).into();
3392            {
3393                self.declared_style().size.height = Some(height);
3394                self
3395            }
3396        }
3397        fn h_28(mut self) -> Self
3398        where
3399            Self: Sized,
3400        {
3401            let height = DefinedLength::Rems(7.).into();
3402            {
3403                self.declared_style().size.height = Some(height);
3404                self
3405            }
3406        }
3407        fn h_32(mut self) -> Self
3408        where
3409            Self: Sized,
3410        {
3411            let height = DefinedLength::Rems(8.).into();
3412            {
3413                self.declared_style().size.height = Some(height);
3414                self
3415            }
3416        }
3417        fn h_36(mut self) -> Self
3418        where
3419            Self: Sized,
3420        {
3421            let height = DefinedLength::Rems(9.).into();
3422            {
3423                self.declared_style().size.height = Some(height);
3424                self
3425            }
3426        }
3427        fn h_40(mut self) -> Self
3428        where
3429            Self: Sized,
3430        {
3431            let height = DefinedLength::Rems(10.).into();
3432            {
3433                self.declared_style().size.height = Some(height);
3434                self
3435            }
3436        }
3437        fn h_44(mut self) -> Self
3438        where
3439            Self: Sized,
3440        {
3441            let height = DefinedLength::Rems(11.).into();
3442            {
3443                self.declared_style().size.height = Some(height);
3444                self
3445            }
3446        }
3447        fn h_48(mut self) -> Self
3448        where
3449            Self: Sized,
3450        {
3451            let height = DefinedLength::Rems(12.).into();
3452            {
3453                self.declared_style().size.height = Some(height);
3454                self
3455            }
3456        }
3457        fn h_52(mut self) -> Self
3458        where
3459            Self: Sized,
3460        {
3461            let height = DefinedLength::Rems(13.).into();
3462            {
3463                self.declared_style().size.height = Some(height);
3464                self
3465            }
3466        }
3467        fn h_56(mut self) -> Self
3468        where
3469            Self: Sized,
3470        {
3471            let height = DefinedLength::Rems(14.).into();
3472            {
3473                self.declared_style().size.height = Some(height);
3474                self
3475            }
3476        }
3477        fn h_60(mut self) -> Self
3478        where
3479            Self: Sized,
3480        {
3481            let height = DefinedLength::Rems(15.).into();
3482            {
3483                self.declared_style().size.height = Some(height);
3484                self
3485            }
3486        }
3487        fn h_64(mut self) -> Self
3488        where
3489            Self: Sized,
3490        {
3491            let height = DefinedLength::Rems(16.).into();
3492            {
3493                self.declared_style().size.height = Some(height);
3494                self
3495            }
3496        }
3497        fn h_72(mut self) -> Self
3498        where
3499            Self: Sized,
3500        {
3501            let height = DefinedLength::Rems(18.).into();
3502            {
3503                self.declared_style().size.height = Some(height);
3504                self
3505            }
3506        }
3507        fn h_80(mut self) -> Self
3508        where
3509            Self: Sized,
3510        {
3511            let height = DefinedLength::Rems(20.).into();
3512            {
3513                self.declared_style().size.height = Some(height);
3514                self
3515            }
3516        }
3517        fn h_96(mut self) -> Self
3518        where
3519            Self: Sized,
3520        {
3521            let height = DefinedLength::Rems(24.).into();
3522            {
3523                self.declared_style().size.height = Some(height);
3524                self
3525            }
3526        }
3527        fn h_half(mut self) -> Self
3528        where
3529            Self: Sized,
3530        {
3531            let height = DefinedLength::Percent(50.).into();
3532            {
3533                self.declared_style().size.height = Some(height);
3534                self
3535            }
3536        }
3537        fn h_1_3rd(mut self) -> Self
3538        where
3539            Self: Sized,
3540        {
3541            let height = DefinedLength::Percent(33.333333).into();
3542            {
3543                self.declared_style().size.height = Some(height);
3544                self
3545            }
3546        }
3547        fn h_2_3rd(mut self) -> Self
3548        where
3549            Self: Sized,
3550        {
3551            let height = DefinedLength::Percent(66.666667).into();
3552            {
3553                self.declared_style().size.height = Some(height);
3554                self
3555            }
3556        }
3557        fn h_1_4th(mut self) -> Self
3558        where
3559            Self: Sized,
3560        {
3561            let height = DefinedLength::Percent(25.).into();
3562            {
3563                self.declared_style().size.height = Some(height);
3564                self
3565            }
3566        }
3567        fn h_2_4th(mut self) -> Self
3568        where
3569            Self: Sized,
3570        {
3571            let height = DefinedLength::Percent(50.).into();
3572            {
3573                self.declared_style().size.height = Some(height);
3574                self
3575            }
3576        }
3577        fn h_3_4th(mut self) -> Self
3578        where
3579            Self: Sized,
3580        {
3581            let height = DefinedLength::Percent(75.).into();
3582            {
3583                self.declared_style().size.height = Some(height);
3584                self
3585            }
3586        }
3587        fn h_1_5th(mut self) -> Self
3588        where
3589            Self: Sized,
3590        {
3591            let height = DefinedLength::Percent(20.).into();
3592            {
3593                self.declared_style().size.height = Some(height);
3594                self
3595            }
3596        }
3597        fn h_2_5th(mut self) -> Self
3598        where
3599            Self: Sized,
3600        {
3601            let height = DefinedLength::Percent(40.).into();
3602            {
3603                self.declared_style().size.height = Some(height);
3604                self
3605            }
3606        }
3607        fn h_3_5th(mut self) -> Self
3608        where
3609            Self: Sized,
3610        {
3611            let height = DefinedLength::Percent(60.).into();
3612            {
3613                self.declared_style().size.height = Some(height);
3614                self
3615            }
3616        }
3617        fn h_4_5th(mut self) -> Self
3618        where
3619            Self: Sized,
3620        {
3621            let height = DefinedLength::Percent(80.).into();
3622            {
3623                self.declared_style().size.height = Some(height);
3624                self
3625            }
3626        }
3627        fn h_1_6th(mut self) -> Self
3628        where
3629            Self: Sized,
3630        {
3631            let height = DefinedLength::Percent(16.666667).into();
3632            {
3633                self.declared_style().size.height = Some(height);
3634                self
3635            }
3636        }
3637        fn h_2_6th(mut self) -> Self
3638        where
3639            Self: Sized,
3640        {
3641            let height = DefinedLength::Percent(33.333333).into();
3642            {
3643                self.declared_style().size.height = Some(height);
3644                self
3645            }
3646        }
3647        fn h_3_6th(mut self) -> Self
3648        where
3649            Self: Sized,
3650        {
3651            let height = DefinedLength::Percent(50.).into();
3652            {
3653                self.declared_style().size.height = Some(height);
3654                self
3655            }
3656        }
3657        fn h_4_6th(mut self) -> Self
3658        where
3659            Self: Sized,
3660        {
3661            let height = DefinedLength::Percent(66.666667).into();
3662            {
3663                self.declared_style().size.height = Some(height);
3664                self
3665            }
3666        }
3667        fn h_5_6th(mut self) -> Self
3668        where
3669            Self: Sized,
3670        {
3671            let height = DefinedLength::Percent(83.333333).into();
3672            {
3673                self.declared_style().size.height = Some(height);
3674                self
3675            }
3676        }
3677        fn h_1_12th(mut self) -> Self
3678        where
3679            Self: Sized,
3680        {
3681            let height = DefinedLength::Percent(8.333333).into();
3682            {
3683                self.declared_style().size.height = Some(height);
3684                self
3685            }
3686        }
3687        fn h_2_12th(mut self) -> Self
3688        where
3689            Self: Sized,
3690        {
3691            let height = DefinedLength::Percent(16.666667).into();
3692            {
3693                self.declared_style().size.height = Some(height);
3694                self
3695            }
3696        }
3697        fn h_3_12th(mut self) -> Self
3698        where
3699            Self: Sized,
3700        {
3701            let height = DefinedLength::Percent(25.).into();
3702            {
3703                self.declared_style().size.height = Some(height);
3704                self
3705            }
3706        }
3707        fn h_4_12th(mut self) -> Self
3708        where
3709            Self: Sized,
3710        {
3711            let height = DefinedLength::Percent(33.333333).into();
3712            {
3713                self.declared_style().size.height = Some(height);
3714                self
3715            }
3716        }
3717        fn h_5_12th(mut self) -> Self
3718        where
3719            Self: Sized,
3720        {
3721            let height = DefinedLength::Percent(41.666667).into();
3722            {
3723                self.declared_style().size.height = Some(height);
3724                self
3725            }
3726        }
3727        fn h_6_12th(mut self) -> Self
3728        where
3729            Self: Sized,
3730        {
3731            let height = DefinedLength::Percent(50.).into();
3732            {
3733                self.declared_style().size.height = Some(height);
3734                self
3735            }
3736        }
3737        fn h_7_12th(mut self) -> Self
3738        where
3739            Self: Sized,
3740        {
3741            let height = DefinedLength::Percent(58.333333).into();
3742            {
3743                self.declared_style().size.height = Some(height);
3744                self
3745            }
3746        }
3747        fn h_8_12th(mut self) -> Self
3748        where
3749            Self: Sized,
3750        {
3751            let height = DefinedLength::Percent(66.666667).into();
3752            {
3753                self.declared_style().size.height = Some(height);
3754                self
3755            }
3756        }
3757        fn h_9_12th(mut self) -> Self
3758        where
3759            Self: Sized,
3760        {
3761            let height = DefinedLength::Percent(75.).into();
3762            {
3763                self.declared_style().size.height = Some(height);
3764                self
3765            }
3766        }
3767        fn h_10_12th(mut self) -> Self
3768        where
3769            Self: Sized,
3770        {
3771            let height = DefinedLength::Percent(83.333333).into();
3772            {
3773                self.declared_style().size.height = Some(height);
3774                self
3775            }
3776        }
3777        fn h_11_12th(mut self) -> Self
3778        where
3779            Self: Sized,
3780        {
3781            let height = DefinedLength::Percent(91.666667).into();
3782            {
3783                self.declared_style().size.height = Some(height);
3784                self
3785            }
3786        }
3787        fn h_full(mut self) -> Self
3788        where
3789            Self: Sized,
3790        {
3791            let height = DefinedLength::Percent(100.).into();
3792            {
3793                self.declared_style().size.height = Some(height);
3794                self
3795            }
3796        }
3797        fn min_h_0(mut self) -> Self
3798        where
3799            Self: Sized,
3800        {
3801            let length = DefinedLength::Pixels(0.).into();
3802            {
3803                self.declared_style().min_size.height = Some(length);
3804                self
3805            }
3806        }
3807        fn min_h_px(mut self) -> Self
3808        where
3809            Self: Sized,
3810        {
3811            let length = DefinedLength::Pixels(1.).into();
3812            {
3813                self.declared_style().min_size.height = Some(length);
3814                self
3815            }
3816        }
3817        fn min_h_0_5(mut self) -> Self
3818        where
3819            Self: Sized,
3820        {
3821            let length = DefinedLength::Rems(0.125).into();
3822            {
3823                self.declared_style().min_size.height = Some(length);
3824                self
3825            }
3826        }
3827        fn min_h_1(mut self) -> Self
3828        where
3829            Self: Sized,
3830        {
3831            let length = DefinedLength::Rems(0.25).into();
3832            {
3833                self.declared_style().min_size.height = Some(length);
3834                self
3835            }
3836        }
3837        fn min_h_1_5(mut self) -> Self
3838        where
3839            Self: Sized,
3840        {
3841            let length = DefinedLength::Rems(0.375).into();
3842            {
3843                self.declared_style().min_size.height = Some(length);
3844                self
3845            }
3846        }
3847        fn min_h_2(mut self) -> Self
3848        where
3849            Self: Sized,
3850        {
3851            let length = DefinedLength::Rems(0.5).into();
3852            {
3853                self.declared_style().min_size.height = Some(length);
3854                self
3855            }
3856        }
3857        fn min_h_2_5(mut self) -> Self
3858        where
3859            Self: Sized,
3860        {
3861            let length = DefinedLength::Rems(0.625).into();
3862            {
3863                self.declared_style().min_size.height = Some(length);
3864                self
3865            }
3866        }
3867        fn min_h_3(mut self) -> Self
3868        where
3869            Self: Sized,
3870        {
3871            let length = DefinedLength::Rems(0.75).into();
3872            {
3873                self.declared_style().min_size.height = Some(length);
3874                self
3875            }
3876        }
3877        fn min_h_3_5(mut self) -> Self
3878        where
3879            Self: Sized,
3880        {
3881            let length = DefinedLength::Rems(0.875).into();
3882            {
3883                self.declared_style().min_size.height = Some(length);
3884                self
3885            }
3886        }
3887        fn min_h_4(mut self) -> Self
3888        where
3889            Self: Sized,
3890        {
3891            let length = DefinedLength::Rems(1.).into();
3892            {
3893                self.declared_style().min_size.height = Some(length);
3894                self
3895            }
3896        }
3897        fn min_h_5(mut self) -> Self
3898        where
3899            Self: Sized,
3900        {
3901            let length = DefinedLength::Rems(1.25).into();
3902            {
3903                self.declared_style().min_size.height = Some(length);
3904                self
3905            }
3906        }
3907        fn min_h_6(mut self) -> Self
3908        where
3909            Self: Sized,
3910        {
3911            let length = DefinedLength::Rems(1.5).into();
3912            {
3913                self.declared_style().min_size.height = Some(length);
3914                self
3915            }
3916        }
3917        fn min_h_7(mut self) -> Self
3918        where
3919            Self: Sized,
3920        {
3921            let length = DefinedLength::Rems(1.75).into();
3922            {
3923                self.declared_style().min_size.height = Some(length);
3924                self
3925            }
3926        }
3927        fn min_h_8(mut self) -> Self
3928        where
3929            Self: Sized,
3930        {
3931            let length = DefinedLength::Rems(2.).into();
3932            {
3933                self.declared_style().min_size.height = Some(length);
3934                self
3935            }
3936        }
3937        fn min_h_9(mut self) -> Self
3938        where
3939            Self: Sized,
3940        {
3941            let length = DefinedLength::Rems(2.25).into();
3942            {
3943                self.declared_style().min_size.height = Some(length);
3944                self
3945            }
3946        }
3947        fn min_h_10(mut self) -> Self
3948        where
3949            Self: Sized,
3950        {
3951            let length = DefinedLength::Rems(2.5).into();
3952            {
3953                self.declared_style().min_size.height = Some(length);
3954                self
3955            }
3956        }
3957        fn min_h_11(mut self) -> Self
3958        where
3959            Self: Sized,
3960        {
3961            let length = DefinedLength::Rems(2.75).into();
3962            {
3963                self.declared_style().min_size.height = Some(length);
3964                self
3965            }
3966        }
3967        fn min_h_12(mut self) -> Self
3968        where
3969            Self: Sized,
3970        {
3971            let length = DefinedLength::Rems(3.).into();
3972            {
3973                self.declared_style().min_size.height = Some(length);
3974                self
3975            }
3976        }
3977        fn min_h_14(mut self) -> Self
3978        where
3979            Self: Sized,
3980        {
3981            let length = DefinedLength::Rems(3.5).into();
3982            {
3983                self.declared_style().min_size.height = Some(length);
3984                self
3985            }
3986        }
3987        fn min_h_16(mut self) -> Self
3988        where
3989            Self: Sized,
3990        {
3991            let length = DefinedLength::Rems(4.).into();
3992            {
3993                self.declared_style().min_size.height = Some(length);
3994                self
3995            }
3996        }
3997        fn min_h_20(mut self) -> Self
3998        where
3999            Self: Sized,
4000        {
4001            let length = DefinedLength::Rems(5.).into();
4002            {
4003                self.declared_style().min_size.height = Some(length);
4004                self
4005            }
4006        }
4007        fn min_h_24(mut self) -> Self
4008        where
4009            Self: Sized,
4010        {
4011            let length = DefinedLength::Rems(6.).into();
4012            {
4013                self.declared_style().min_size.height = Some(length);
4014                self
4015            }
4016        }
4017        fn min_h_28(mut self) -> Self
4018        where
4019            Self: Sized,
4020        {
4021            let length = DefinedLength::Rems(7.).into();
4022            {
4023                self.declared_style().min_size.height = Some(length);
4024                self
4025            }
4026        }
4027        fn min_h_32(mut self) -> Self
4028        where
4029            Self: Sized,
4030        {
4031            let length = DefinedLength::Rems(8.).into();
4032            {
4033                self.declared_style().min_size.height = Some(length);
4034                self
4035            }
4036        }
4037        fn min_h_36(mut self) -> Self
4038        where
4039            Self: Sized,
4040        {
4041            let length = DefinedLength::Rems(9.).into();
4042            {
4043                self.declared_style().min_size.height = Some(length);
4044                self
4045            }
4046        }
4047        fn min_h_40(mut self) -> Self
4048        where
4049            Self: Sized,
4050        {
4051            let length = DefinedLength::Rems(10.).into();
4052            {
4053                self.declared_style().min_size.height = Some(length);
4054                self
4055            }
4056        }
4057        fn min_h_44(mut self) -> Self
4058        where
4059            Self: Sized,
4060        {
4061            let length = DefinedLength::Rems(11.).into();
4062            {
4063                self.declared_style().min_size.height = Some(length);
4064                self
4065            }
4066        }
4067        fn min_h_48(mut self) -> Self
4068        where
4069            Self: Sized,
4070        {
4071            let length = DefinedLength::Rems(12.).into();
4072            {
4073                self.declared_style().min_size.height = Some(length);
4074                self
4075            }
4076        }
4077        fn min_h_52(mut self) -> Self
4078        where
4079            Self: Sized,
4080        {
4081            let length = DefinedLength::Rems(13.).into();
4082            {
4083                self.declared_style().min_size.height = Some(length);
4084                self
4085            }
4086        }
4087        fn min_h_56(mut self) -> Self
4088        where
4089            Self: Sized,
4090        {
4091            let length = DefinedLength::Rems(14.).into();
4092            {
4093                self.declared_style().min_size.height = Some(length);
4094                self
4095            }
4096        }
4097        fn min_h_60(mut self) -> Self
4098        where
4099            Self: Sized,
4100        {
4101            let length = DefinedLength::Rems(15.).into();
4102            {
4103                self.declared_style().min_size.height = Some(length);
4104                self
4105            }
4106        }
4107        fn min_h_64(mut self) -> Self
4108        where
4109            Self: Sized,
4110        {
4111            let length = DefinedLength::Rems(16.).into();
4112            {
4113                self.declared_style().min_size.height = Some(length);
4114                self
4115            }
4116        }
4117        fn min_h_72(mut self) -> Self
4118        where
4119            Self: Sized,
4120        {
4121            let length = DefinedLength::Rems(18.).into();
4122            {
4123                self.declared_style().min_size.height = Some(length);
4124                self
4125            }
4126        }
4127        fn min_h_80(mut self) -> Self
4128        where
4129            Self: Sized,
4130        {
4131            let length = DefinedLength::Rems(20.).into();
4132            {
4133                self.declared_style().min_size.height = Some(length);
4134                self
4135            }
4136        }
4137        fn min_h_96(mut self) -> Self
4138        where
4139            Self: Sized,
4140        {
4141            let length = DefinedLength::Rems(24.).into();
4142            {
4143                self.declared_style().min_size.height = Some(length);
4144                self
4145            }
4146        }
4147        fn min_h_half(mut self) -> Self
4148        where
4149            Self: Sized,
4150        {
4151            let length = DefinedLength::Percent(50.).into();
4152            {
4153                self.declared_style().min_size.height = Some(length);
4154                self
4155            }
4156        }
4157        fn min_h_1_3rd(mut self) -> Self
4158        where
4159            Self: Sized,
4160        {
4161            let length = DefinedLength::Percent(33.333333).into();
4162            {
4163                self.declared_style().min_size.height = Some(length);
4164                self
4165            }
4166        }
4167        fn min_h_2_3rd(mut self) -> Self
4168        where
4169            Self: Sized,
4170        {
4171            let length = DefinedLength::Percent(66.666667).into();
4172            {
4173                self.declared_style().min_size.height = Some(length);
4174                self
4175            }
4176        }
4177        fn min_h_1_4th(mut self) -> Self
4178        where
4179            Self: Sized,
4180        {
4181            let length = DefinedLength::Percent(25.).into();
4182            {
4183                self.declared_style().min_size.height = Some(length);
4184                self
4185            }
4186        }
4187        fn min_h_2_4th(mut self) -> Self
4188        where
4189            Self: Sized,
4190        {
4191            let length = DefinedLength::Percent(50.).into();
4192            {
4193                self.declared_style().min_size.height = Some(length);
4194                self
4195            }
4196        }
4197        fn min_h_3_4th(mut self) -> Self
4198        where
4199            Self: Sized,
4200        {
4201            let length = DefinedLength::Percent(75.).into();
4202            {
4203                self.declared_style().min_size.height = Some(length);
4204                self
4205            }
4206        }
4207        fn min_h_1_5th(mut self) -> Self
4208        where
4209            Self: Sized,
4210        {
4211            let length = DefinedLength::Percent(20.).into();
4212            {
4213                self.declared_style().min_size.height = Some(length);
4214                self
4215            }
4216        }
4217        fn min_h_2_5th(mut self) -> Self
4218        where
4219            Self: Sized,
4220        {
4221            let length = DefinedLength::Percent(40.).into();
4222            {
4223                self.declared_style().min_size.height = Some(length);
4224                self
4225            }
4226        }
4227        fn min_h_3_5th(mut self) -> Self
4228        where
4229            Self: Sized,
4230        {
4231            let length = DefinedLength::Percent(60.).into();
4232            {
4233                self.declared_style().min_size.height = Some(length);
4234                self
4235            }
4236        }
4237        fn min_h_4_5th(mut self) -> Self
4238        where
4239            Self: Sized,
4240        {
4241            let length = DefinedLength::Percent(80.).into();
4242            {
4243                self.declared_style().min_size.height = Some(length);
4244                self
4245            }
4246        }
4247        fn min_h_1_6th(mut self) -> Self
4248        where
4249            Self: Sized,
4250        {
4251            let length = DefinedLength::Percent(16.666667).into();
4252            {
4253                self.declared_style().min_size.height = Some(length);
4254                self
4255            }
4256        }
4257        fn min_h_2_6th(mut self) -> Self
4258        where
4259            Self: Sized,
4260        {
4261            let length = DefinedLength::Percent(33.333333).into();
4262            {
4263                self.declared_style().min_size.height = Some(length);
4264                self
4265            }
4266        }
4267        fn min_h_3_6th(mut self) -> Self
4268        where
4269            Self: Sized,
4270        {
4271            let length = DefinedLength::Percent(50.).into();
4272            {
4273                self.declared_style().min_size.height = Some(length);
4274                self
4275            }
4276        }
4277        fn min_h_4_6th(mut self) -> Self
4278        where
4279            Self: Sized,
4280        {
4281            let length = DefinedLength::Percent(66.666667).into();
4282            {
4283                self.declared_style().min_size.height = Some(length);
4284                self
4285            }
4286        }
4287        fn min_h_5_6th(mut self) -> Self
4288        where
4289            Self: Sized,
4290        {
4291            let length = DefinedLength::Percent(83.333333).into();
4292            {
4293                self.declared_style().min_size.height = Some(length);
4294                self
4295            }
4296        }
4297        fn min_h_1_12th(mut self) -> Self
4298        where
4299            Self: Sized,
4300        {
4301            let length = DefinedLength::Percent(8.333333).into();
4302            {
4303                self.declared_style().min_size.height = Some(length);
4304                self
4305            }
4306        }
4307        fn min_h_2_12th(mut self) -> Self
4308        where
4309            Self: Sized,
4310        {
4311            let length = DefinedLength::Percent(16.666667).into();
4312            {
4313                self.declared_style().min_size.height = Some(length);
4314                self
4315            }
4316        }
4317        fn min_h_3_12th(mut self) -> Self
4318        where
4319            Self: Sized,
4320        {
4321            let length = DefinedLength::Percent(25.).into();
4322            {
4323                self.declared_style().min_size.height = Some(length);
4324                self
4325            }
4326        }
4327        fn min_h_4_12th(mut self) -> Self
4328        where
4329            Self: Sized,
4330        {
4331            let length = DefinedLength::Percent(33.333333).into();
4332            {
4333                self.declared_style().min_size.height = Some(length);
4334                self
4335            }
4336        }
4337        fn min_h_5_12th(mut self) -> Self
4338        where
4339            Self: Sized,
4340        {
4341            let length = DefinedLength::Percent(41.666667).into();
4342            {
4343                self.declared_style().min_size.height = Some(length);
4344                self
4345            }
4346        }
4347        fn min_h_6_12th(mut self) -> Self
4348        where
4349            Self: Sized,
4350        {
4351            let length = DefinedLength::Percent(50.).into();
4352            {
4353                self.declared_style().min_size.height = Some(length);
4354                self
4355            }
4356        }
4357        fn min_h_7_12th(mut self) -> Self
4358        where
4359            Self: Sized,
4360        {
4361            let length = DefinedLength::Percent(58.333333).into();
4362            {
4363                self.declared_style().min_size.height = Some(length);
4364                self
4365            }
4366        }
4367        fn min_h_8_12th(mut self) -> Self
4368        where
4369            Self: Sized,
4370        {
4371            let length = DefinedLength::Percent(66.666667).into();
4372            {
4373                self.declared_style().min_size.height = Some(length);
4374                self
4375            }
4376        }
4377        fn min_h_9_12th(mut self) -> Self
4378        where
4379            Self: Sized,
4380        {
4381            let length = DefinedLength::Percent(75.).into();
4382            {
4383                self.declared_style().min_size.height = Some(length);
4384                self
4385            }
4386        }
4387        fn min_h_10_12th(mut self) -> Self
4388        where
4389            Self: Sized,
4390        {
4391            let length = DefinedLength::Percent(83.333333).into();
4392            {
4393                self.declared_style().min_size.height = Some(length);
4394                self
4395            }
4396        }
4397        fn min_h_11_12th(mut self) -> Self
4398        where
4399            Self: Sized,
4400        {
4401            let length = DefinedLength::Percent(91.666667).into();
4402            {
4403                self.declared_style().min_size.height = Some(length);
4404                self
4405            }
4406        }
4407        fn min_h_full(mut self) -> Self
4408        where
4409            Self: Sized,
4410        {
4411            let length = DefinedLength::Percent(100.).into();
4412            {
4413                self.declared_style().min_size.height = Some(length);
4414                self
4415            }
4416        }
4417        fn hoverable(self) -> Hoverable<V, Self>
4418        where
4419            Self: Sized,
4420        {
4421            Hoverable::new(self)
4422        }
4423        fn fill(mut self, fill: impl Into<Fill>) -> Self
4424        where
4425            Self: Sized,
4426        {
4427            self.declared_style().fill = Some(Some(fill.into()));
4428            self
4429        }
4430        fn text_color(mut self, color: impl Into<Hsla>) -> Self
4431        where
4432            Self: Sized,
4433        {
4434            self.declared_style().text_color = Some(Some(color.into()));
4435            self
4436        }
4437    }
4438    trait ElementObject<V> {
4439        fn style(&mut self) -> &mut OptionalStyle;
4440        fn handlers_mut(&mut self) -> &mut Vec<EventHandler<V>>;
4441        fn layout(
4442            &mut self,
4443            view: &mut V,
4444            cx: &mut LayoutContext<V>,
4445        ) -> Result<(NodeId, Box<dyn Any>)>;
4446        fn paint(
4447            &mut self,
4448            layout: Layout<dyn Any>,
4449            view: &mut V,
4450            cx: &mut PaintContext<V>,
4451        ) -> Result<()>;
4452    }
4453    impl<V: 'static, E: Element<V>> ElementObject<V> for E {
4454        fn style(&mut self) -> &mut OptionalStyle {
4455            Element::declared_style(self)
4456        }
4457        fn handlers_mut(&mut self) -> &mut Vec<EventHandler<V>> {
4458            Element::handlers_mut(self)
4459        }
4460        fn layout(
4461            &mut self,
4462            view: &mut V,
4463            cx: &mut LayoutContext<V>,
4464        ) -> Result<(NodeId, Box<dyn Any>)> {
4465            let (node_id, layout) = self.layout(view, cx)?;
4466            let layout = Box::new(layout) as Box<dyn Any>;
4467            Ok((node_id, layout))
4468        }
4469        fn paint(
4470            &mut self,
4471            layout: Layout<dyn Any>,
4472            view: &mut V,
4473            cx: &mut PaintContext<V>,
4474        ) -> Result<()> {
4475            let layout = Layout {
4476                from_engine: layout.from_engine,
4477                from_element: layout.from_element.downcast_mut::<E::Layout>().unwrap(),
4478            };
4479            self.paint(layout, view, cx)
4480        }
4481    }
4482    /// A dynamically typed element.
4483    pub struct AnyElement<V> {
4484        element: Box<dyn ElementObject<V>>,
4485        layout: Option<(NodeId, Box<dyn Any>)>,
4486    }
4487    impl<V: 'static> AnyElement<V> {
4488        pub fn layout(
4489            &mut self,
4490            view: &mut V,
4491            cx: &mut LayoutContext<V>,
4492        ) -> Result<NodeId> {
4493            let pushed_text_style = self.push_text_style(cx);
4494            let (node_id, layout) = self.element.layout(view, cx)?;
4495            self.layout = Some((node_id, layout));
4496            if pushed_text_style {
4497                cx.pop_text_style();
4498            }
4499            Ok(node_id)
4500        }
4501        pub fn push_text_style(&mut self, cx: &mut impl RenderContext) -> bool {
4502            let text_style = self.element.style().text_style();
4503            if let Some(text_style) = text_style {
4504                let mut current_text_style = cx.text_style();
4505                text_style.apply(&mut current_text_style);
4506                cx.push_text_style(current_text_style);
4507                true
4508            } else {
4509                false
4510            }
4511        }
4512        pub fn paint(&mut self, view: &mut V, cx: &mut PaintContext<V>) -> Result<()> {
4513            let pushed_text_style = self.push_text_style(cx);
4514            let (layout_node_id, element_layout) = self
4515                .layout
4516                .as_mut()
4517                .expect("paint called before layout");
4518            let layout = Layout {
4519                from_engine: cx
4520                    .layout_engine()
4521                    .unwrap()
4522                    .computed_layout(*layout_node_id)
4523                    .expect(
4524                        "you can currently only use playground elements within an adapter",
4525                    ),
4526                from_element: element_layout.as_mut(),
4527            };
4528            let style = self.element.style();
4529            let fill_color = style.fill.flatten().and_then(|fill| fill.color());
4530            if let Some(fill_color) = fill_color {
4531                cx.scene
4532                    .push_quad(gpui::scene::Quad {
4533                        bounds: layout.from_engine.bounds,
4534                        background: Some(fill_color.into()),
4535                        border: Default::default(),
4536                        corner_radii: Default::default(),
4537                    });
4538            }
4539            for event_handler in self.element.handlers_mut().iter().cloned() {
4540                let EngineLayout { order, bounds } = layout.from_engine;
4541                let view_id = cx.view_id();
4542                let view_event_handler = event_handler.handler.clone();
4543                cx.scene
4544                    .interactive_regions
4545                    .push(gpui::scene::InteractiveRegion {
4546                        order,
4547                        bounds,
4548                        outside_bounds: event_handler.outside_bounds,
4549                        event_handler: Rc::new(move |view, event, window_cx, view_id| {
4550                            let mut view_context = ViewContext::mutable(
4551                                window_cx,
4552                                view_id,
4553                            );
4554                            let mut event_context = EventContext::new(&mut view_context);
4555                            view_event_handler(
4556                                view.downcast_mut().unwrap(),
4557                                event,
4558                                &mut event_context,
4559                            );
4560                        }),
4561                        event_type: event_handler.event_type,
4562                        view_id,
4563                    });
4564            }
4565            self.element.paint(layout, view, cx)?;
4566            if pushed_text_style {
4567                cx.pop_text_style();
4568            }
4569            Ok(())
4570        }
4571    }
4572    impl<V: 'static> Element<V> for AnyElement<V> {
4573        type Layout = ();
4574        fn declared_style(&mut self) -> &mut OptionalStyle {
4575            self.element.style()
4576        }
4577        fn handlers_mut(&mut self) -> &mut Vec<EventHandler<V>> {
4578            self.element.handlers_mut()
4579        }
4580        fn layout(
4581            &mut self,
4582            view: &mut V,
4583            cx: &mut LayoutContext<V>,
4584        ) -> Result<(NodeId, Self::Layout)> {
4585            Ok((self.layout(view, cx)?, ()))
4586        }
4587        fn paint(
4588            &mut self,
4589            layout: Layout<()>,
4590            view: &mut V,
4591            cx: &mut PaintContext<V>,
4592        ) -> Result<()> {
4593            self.paint(view, cx)
4594        }
4595    }
4596    pub trait IntoElement<V: 'static> {
4597        type Element: Element<V>;
4598        fn into_element(self) -> Self::Element;
4599        fn into_any_element(self) -> AnyElement<V>
4600        where
4601            Self: Sized,
4602        {
4603            self.into_element().into_any()
4604        }
4605    }
4606}
4607mod frame {
4608    use crate::{
4609        element::{
4610            AnyElement, Element, EventHandler, IntoElement, Layout, LayoutContext,
4611            NodeId, PaintContext,
4612        },
4613        style::{OptionalStyle, Style},
4614    };
4615    use anyhow::{anyhow, Result};
4616    use gpui::LayoutNodeId;
4617    use playground_macros::IntoElement;
4618    #[element_crate = "crate"]
4619    pub struct Frame<V: 'static> {
4620        style: OptionalStyle,
4621        handlers: Vec<EventHandler<V>>,
4622        children: Vec<AnyElement<V>>,
4623    }
4624    impl<V: 'static> crate::element::IntoElement<V> for Frame<V> {
4625        type Element = Self;
4626        fn into_element(self) -> Self {
4627            self
4628        }
4629    }
4630    pub fn frame<V>() -> Frame<V> {
4631        Frame {
4632            style: OptionalStyle::default(),
4633            handlers: Vec::new(),
4634            children: Vec::new(),
4635        }
4636    }
4637    impl<V: 'static> Element<V> for Frame<V> {
4638        type Layout = ();
4639        fn declared_style(&mut self) -> &mut OptionalStyle {
4640            &mut self.style
4641        }
4642        fn handlers_mut(&mut self) -> &mut Vec<EventHandler<V>> {
4643            &mut self.handlers
4644        }
4645        fn layout(
4646            &mut self,
4647            view: &mut V,
4648            cx: &mut LayoutContext<V>,
4649        ) -> Result<(NodeId, Self::Layout)> {
4650            let child_layout_node_ids = self
4651                .children
4652                .iter_mut()
4653                .map(|child| child.layout(view, cx))
4654                .collect::<Result<Vec<LayoutNodeId>>>()?;
4655            let rem_size = cx.rem_pixels();
4656            let style: Style = self.style.into();
4657            let node_id = cx
4658                .layout_engine()
4659                .ok_or_else(|| ::anyhow::__private::must_use({
4660                    let error = ::anyhow::__private::format_err(
4661                        format_args!("no layout engine"),
4662                    );
4663                    error
4664                }))?
4665                .add_node(style.to_taffy(rem_size), child_layout_node_ids)?;
4666            Ok((node_id, ()))
4667        }
4668        fn paint(
4669            &mut self,
4670            layout: Layout<()>,
4671            view: &mut V,
4672            cx: &mut PaintContext<V>,
4673        ) -> Result<()> {
4674            for child in &mut self.children {
4675                child.paint(view, cx)?;
4676            }
4677            Ok(())
4678        }
4679    }
4680    impl<V: 'static> Frame<V> {
4681        pub fn child(mut self, child: impl IntoElement<V>) -> Self {
4682            self.children.push(child.into_any_element());
4683            self
4684        }
4685        pub fn children<I, E>(mut self, children: I) -> Self
4686        where
4687            I: IntoIterator<Item = E>,
4688            E: IntoElement<V>,
4689        {
4690            self.children.extend(children.into_iter().map(|e| e.into_any_element()));
4691            self
4692        }
4693    }
4694}
4695mod hoverable {
4696    use std::{cell::Cell, marker::PhantomData, rc::Rc};
4697    use gpui::{
4698        geometry::{rect::RectF, vector::Vector2F},
4699        scene::MouseMove, EngineLayout,
4700    };
4701    use crate::{element::Element, style::{OptionalStyle, Style}};
4702    pub struct Hoverable<V, E> {
4703        hover_style: OptionalStyle,
4704        computed_style: Option<Style>,
4705        view_type: PhantomData<V>,
4706        child: E,
4707    }
4708    impl<V, E> Hoverable<V, E> {
4709        pub fn new(child: E) -> Self {
4710            Self {
4711                hover_style: OptionalStyle::default(),
4712                computed_style: None,
4713                view_type: PhantomData,
4714                child,
4715            }
4716        }
4717    }
4718    impl<V: 'static, E: Element<V>> Element<V> for Hoverable<V, E> {
4719        type Layout = E::Layout;
4720        fn declared_style(&mut self) -> &mut OptionalStyle {
4721            &mut self.hover_style
4722        }
4723        fn computed_style(&mut self) -> &OptionalStyle {
4724            ::core::panicking::panic("not yet implemented")
4725        }
4726        fn handlers_mut(&mut self) -> &mut Vec<crate::element::EventHandler<V>> {
4727            self.child.handlers_mut()
4728        }
4729        fn layout(
4730            &mut self,
4731            view: &mut V,
4732            cx: &mut gpui::LayoutContext<V>,
4733        ) -> anyhow::Result<(taffy::tree::NodeId, Self::Layout)> {
4734            self.child.layout(view, cx)
4735        }
4736        fn paint<'a>(
4737            &mut self,
4738            layout: crate::element::Layout<Self::Layout>,
4739            view: &mut V,
4740            cx: &mut crate::element::PaintContext<V>,
4741        ) -> anyhow::Result<()> {
4742            let EngineLayout { bounds, order } = layout.from_engine;
4743            let window_bounds = RectF::new(Vector2F::zero(), cx.window_size());
4744            let was_hovered = Rc::new(Cell::new(false));
4745            self.child.paint(layout, view, cx)?;
4746            cx.draw_interactive_region(
4747                order,
4748                window_bounds,
4749                false,
4750                move |view, event: &MouseMove, cx| {
4751                    let is_hovered = bounds.contains_point(cx.mouse_position());
4752                    if is_hovered != was_hovered.get() {
4753                        was_hovered.set(is_hovered);
4754                        cx.repaint();
4755                    }
4756                },
4757            );
4758            Ok(())
4759        }
4760    }
4761}
4762mod paint_context {
4763    use std::{any::TypeId, rc::Rc};
4764    use derive_more::{Deref, DerefMut};
4765    use gpui::{geometry::rect::RectF, EventContext, RenderContext, ViewContext};
4766    pub use gpui::{LayoutContext, PaintContext as LegacyPaintContext};
4767    pub use taffy::tree::NodeId;
4768    pub struct PaintContext<'a, 'b, 'c, 'd, V> {
4769        #[deref]
4770        #[deref_mut]
4771        pub(crate) legacy_cx: &'d mut LegacyPaintContext<'a, 'b, 'c, V>,
4772        pub(crate) scene: &'d mut gpui::SceneBuilder,
4773    }
4774    impl<'a, 'b, 'c, 'd, V> ::core::ops::Deref for PaintContext<'a, 'b, 'c, 'd, V> {
4775        type Target = &'d mut LegacyPaintContext<'a, 'b, 'c, V>;
4776        #[inline]
4777        fn deref(&self) -> &Self::Target {
4778            &self.legacy_cx
4779        }
4780    }
4781    impl<'a, 'b, 'c, 'd, V> ::core::ops::DerefMut for PaintContext<'a, 'b, 'c, 'd, V> {
4782        #[inline]
4783        fn deref_mut(&mut self) -> &mut Self::Target {
4784            &mut self.legacy_cx
4785        }
4786    }
4787    impl<V> RenderContext for PaintContext<'_, '_, '_, '_, V> {
4788        fn text_style(&self) -> gpui::fonts::TextStyle {
4789            self.legacy_cx.text_style()
4790        }
4791        fn push_text_style(&mut self, style: gpui::fonts::TextStyle) {
4792            self.legacy_cx.push_text_style(style)
4793        }
4794        fn pop_text_style(&mut self) {
4795            self.legacy_cx.pop_text_style()
4796        }
4797    }
4798    impl<'a, 'b, 'c, 'd, V: 'static> PaintContext<'a, 'b, 'c, 'd, V> {
4799        pub fn new(
4800            legacy_cx: &'d mut LegacyPaintContext<'a, 'b, 'c, V>,
4801            scene: &'d mut gpui::SceneBuilder,
4802        ) -> Self {
4803            Self { legacy_cx, scene }
4804        }
4805        pub fn draw_interactive_region<E: 'static>(
4806            &mut self,
4807            order: u32,
4808            bounds: RectF,
4809            outside_bounds: bool,
4810            event_handler: impl Fn(&mut V, &E, &mut EventContext<V>) + 'static,
4811        ) {
4812            self.scene
4813                .interactive_regions
4814                .push(gpui::scene::InteractiveRegion {
4815                    order,
4816                    bounds,
4817                    outside_bounds,
4818                    event_handler: Rc::new(move |view, event, window_cx, view_id| {
4819                        let mut view_context = ViewContext::mutable(window_cx, view_id);
4820                        let mut event_context = EventContext::new(&mut view_context);
4821                        event_handler(
4822                            view.downcast_mut().unwrap(),
4823                            event.downcast_ref().unwrap(),
4824                            &mut event_context,
4825                        );
4826                    }),
4827                    event_type: TypeId::of::<E>(),
4828                    view_id: self.view_id(),
4829                });
4830        }
4831    }
4832}
4833mod style {
4834    use crate::color::Hsla;
4835    use gpui::geometry::{
4836        DefinedLength, Edges, Length, OptionalEdges, OptionalPoint, OptionalSize, Point,
4837        Size,
4838    };
4839    use optional::Optional;
4840    pub use taffy::style::{
4841        AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap,
4842        JustifyContent, Overflow, Position,
4843    };
4844    pub struct Style {
4845        /// What layout strategy should be used?
4846        pub display: Display,
4847        /// How children overflowing their container should affect layout
4848        #[optional]
4849        pub overflow: Point<Overflow>,
4850        /// How much space (in points) should be reserved for the scrollbars of `Overflow::Scroll` and `Overflow::Auto` nodes.
4851        pub scrollbar_width: f32,
4852        /// What should the `position` value of this struct use as a base offset?
4853        pub position: Position,
4854        /// How should the position of this element be tweaked relative to the layout defined?
4855        pub inset: Edges<Length>,
4856        /// Sets the initial size of the item
4857        #[optional]
4858        pub size: Size<Length>,
4859        /// Controls the minimum size of the item
4860        #[optional]
4861        pub min_size: Size<Length>,
4862        /// Controls the maximum size of the item
4863        #[optional]
4864        pub max_size: Size<Length>,
4865        /// Sets the preferred aspect ratio for the item. The ratio is calculated as width divided by height.
4866        pub aspect_ratio: Option<f32>,
4867        /// How large should the margin be on each side?
4868        #[optional]
4869        pub margin: Edges<Length>,
4870        /// How large should the padding be on each side?
4871        pub padding: Edges<DefinedLength>,
4872        /// How large should the border be on each side?
4873        pub border: Edges<DefinedLength>,
4874        /// How this node's children aligned in the cross/block axis?
4875        pub align_items: Option<AlignItems>,
4876        /// How this node should be aligned in the cross/block axis. Falls back to the parents [`AlignItems`] if not set
4877        pub align_self: Option<AlignSelf>,
4878        /// How should content contained within this item be aligned in the cross/block axis
4879        pub align_content: Option<AlignContent>,
4880        /// How should contained within this item be aligned in the main/inline axis
4881        pub justify_content: Option<JustifyContent>,
4882        /// How large should the gaps between items in a flex container be?
4883        pub gap: Size<DefinedLength>,
4884        /// Which direction does the main axis flow in?
4885        pub flex_direction: FlexDirection,
4886        /// Should elements wrap, or stay in a single line?
4887        pub flex_wrap: FlexWrap,
4888        /// Sets the initial main axis size of the item
4889        pub flex_basis: Length,
4890        /// The relative rate at which this item grows when it is expanding to fill space, 0.0 is the default value, and this value must be positive.
4891        pub flex_grow: f32,
4892        /// The relative rate at which this item shrinks when it is contracting to fit into space, 1.0 is the default value, and this value must be positive.
4893        pub flex_shrink: f32,
4894        /// The fill color of this element
4895        pub fill: Option<Fill>,
4896        /// The color of text within this element. Cascades to children unless overridden.
4897        pub text_color: Option<Hsla>,
4898    }
4899    #[automatically_derived]
4900    impl ::core::clone::Clone for Style {
4901        #[inline]
4902        fn clone(&self) -> Style {
4903            Style {
4904                display: ::core::clone::Clone::clone(&self.display),
4905                overflow: ::core::clone::Clone::clone(&self.overflow),
4906                scrollbar_width: ::core::clone::Clone::clone(&self.scrollbar_width),
4907                position: ::core::clone::Clone::clone(&self.position),
4908                inset: ::core::clone::Clone::clone(&self.inset),
4909                size: ::core::clone::Clone::clone(&self.size),
4910                min_size: ::core::clone::Clone::clone(&self.min_size),
4911                max_size: ::core::clone::Clone::clone(&self.max_size),
4912                aspect_ratio: ::core::clone::Clone::clone(&self.aspect_ratio),
4913                margin: ::core::clone::Clone::clone(&self.margin),
4914                padding: ::core::clone::Clone::clone(&self.padding),
4915                border: ::core::clone::Clone::clone(&self.border),
4916                align_items: ::core::clone::Clone::clone(&self.align_items),
4917                align_self: ::core::clone::Clone::clone(&self.align_self),
4918                align_content: ::core::clone::Clone::clone(&self.align_content),
4919                justify_content: ::core::clone::Clone::clone(&self.justify_content),
4920                gap: ::core::clone::Clone::clone(&self.gap),
4921                flex_direction: ::core::clone::Clone::clone(&self.flex_direction),
4922                flex_wrap: ::core::clone::Clone::clone(&self.flex_wrap),
4923                flex_basis: ::core::clone::Clone::clone(&self.flex_basis),
4924                flex_grow: ::core::clone::Clone::clone(&self.flex_grow),
4925                flex_shrink: ::core::clone::Clone::clone(&self.flex_shrink),
4926                fill: ::core::clone::Clone::clone(&self.fill),
4927                text_color: ::core::clone::Clone::clone(&self.text_color),
4928            }
4929        }
4930    }
4931    pub struct OptionalStyle {
4932        pub display: Option<Display>,
4933        pub overflow: OptionalPoint<Overflow>,
4934        pub scrollbar_width: Option<f32>,
4935        pub position: Option<Position>,
4936        pub inset: Option<Edges<Length>>,
4937        pub size: OptionalSize<Length>,
4938        pub min_size: OptionalSize<Length>,
4939        pub max_size: OptionalSize<Length>,
4940        pub aspect_ratio: Option<Option<f32>>,
4941        pub margin: OptionalEdges<Length>,
4942        pub padding: Option<Edges<DefinedLength>>,
4943        pub border: Option<Edges<DefinedLength>>,
4944        pub align_items: Option<Option<AlignItems>>,
4945        pub align_self: Option<Option<AlignSelf>>,
4946        pub align_content: Option<Option<AlignContent>>,
4947        pub justify_content: Option<Option<JustifyContent>>,
4948        pub gap: Option<Size<DefinedLength>>,
4949        pub flex_direction: Option<FlexDirection>,
4950        pub flex_wrap: Option<FlexWrap>,
4951        pub flex_basis: Option<Length>,
4952        pub flex_grow: Option<f32>,
4953        pub flex_shrink: Option<f32>,
4954        pub fill: Option<Option<Fill>>,
4955        pub text_color: Option<Option<Hsla>>,
4956    }
4957    #[automatically_derived]
4958    impl ::core::default::Default for OptionalStyle {
4959        #[inline]
4960        fn default() -> OptionalStyle {
4961            OptionalStyle {
4962                display: ::core::default::Default::default(),
4963                overflow: ::core::default::Default::default(),
4964                scrollbar_width: ::core::default::Default::default(),
4965                position: ::core::default::Default::default(),
4966                inset: ::core::default::Default::default(),
4967                size: ::core::default::Default::default(),
4968                min_size: ::core::default::Default::default(),
4969                max_size: ::core::default::Default::default(),
4970                aspect_ratio: ::core::default::Default::default(),
4971                margin: ::core::default::Default::default(),
4972                padding: ::core::default::Default::default(),
4973                border: ::core::default::Default::default(),
4974                align_items: ::core::default::Default::default(),
4975                align_self: ::core::default::Default::default(),
4976                align_content: ::core::default::Default::default(),
4977                justify_content: ::core::default::Default::default(),
4978                gap: ::core::default::Default::default(),
4979                flex_direction: ::core::default::Default::default(),
4980                flex_wrap: ::core::default::Default::default(),
4981                flex_basis: ::core::default::Default::default(),
4982                flex_grow: ::core::default::Default::default(),
4983                flex_shrink: ::core::default::Default::default(),
4984                fill: ::core::default::Default::default(),
4985                text_color: ::core::default::Default::default(),
4986            }
4987        }
4988    }
4989    #[automatically_derived]
4990    impl ::core::clone::Clone for OptionalStyle {
4991        #[inline]
4992        fn clone(&self) -> OptionalStyle {
4993            OptionalStyle {
4994                display: ::core::clone::Clone::clone(&self.display),
4995                overflow: ::core::clone::Clone::clone(&self.overflow),
4996                scrollbar_width: ::core::clone::Clone::clone(&self.scrollbar_width),
4997                position: ::core::clone::Clone::clone(&self.position),
4998                inset: ::core::clone::Clone::clone(&self.inset),
4999                size: ::core::clone::Clone::clone(&self.size),
5000                min_size: ::core::clone::Clone::clone(&self.min_size),
5001                max_size: ::core::clone::Clone::clone(&self.max_size),
5002                aspect_ratio: ::core::clone::Clone::clone(&self.aspect_ratio),
5003                margin: ::core::clone::Clone::clone(&self.margin),
5004                padding: ::core::clone::Clone::clone(&self.padding),
5005                border: ::core::clone::Clone::clone(&self.border),
5006                align_items: ::core::clone::Clone::clone(&self.align_items),
5007                align_self: ::core::clone::Clone::clone(&self.align_self),
5008                align_content: ::core::clone::Clone::clone(&self.align_content),
5009                justify_content: ::core::clone::Clone::clone(&self.justify_content),
5010                gap: ::core::clone::Clone::clone(&self.gap),
5011                flex_direction: ::core::clone::Clone::clone(&self.flex_direction),
5012                flex_wrap: ::core::clone::Clone::clone(&self.flex_wrap),
5013                flex_basis: ::core::clone::Clone::clone(&self.flex_basis),
5014                flex_grow: ::core::clone::Clone::clone(&self.flex_grow),
5015                flex_shrink: ::core::clone::Clone::clone(&self.flex_shrink),
5016                fill: ::core::clone::Clone::clone(&self.fill),
5017                text_color: ::core::clone::Clone::clone(&self.text_color),
5018            }
5019        }
5020    }
5021    impl Optional for OptionalStyle {
5022        type Base = Style;
5023        fn assign(&self, base: &mut Self::Base) {
5024            if let Some(value) = self.display.clone() {
5025                base.display = value;
5026            }
5027            if let Some(value) = self.overflow.clone() {
5028                base.overflow = value;
5029            }
5030            if let Some(value) = self.scrollbar_width.clone() {
5031                base.scrollbar_width = value;
5032            }
5033            if let Some(value) = self.position.clone() {
5034                base.position = value;
5035            }
5036            if let Some(value) = self.inset.clone() {
5037                base.inset = value;
5038            }
5039            if let Some(value) = self.size.clone() {
5040                base.size = value;
5041            }
5042            if let Some(value) = self.min_size.clone() {
5043                base.min_size = value;
5044            }
5045            if let Some(value) = self.max_size.clone() {
5046                base.max_size = value;
5047            }
5048            if let Some(value) = self.aspect_ratio.clone() {
5049                base.aspect_ratio = value;
5050            }
5051            if let Some(value) = self.margin.clone() {
5052                base.margin = value;
5053            }
5054            if let Some(value) = self.padding.clone() {
5055                base.padding = value;
5056            }
5057            if let Some(value) = self.border.clone() {
5058                base.border = value;
5059            }
5060            if let Some(value) = self.align_items.clone() {
5061                base.align_items = value;
5062            }
5063            if let Some(value) = self.align_self.clone() {
5064                base.align_self = value;
5065            }
5066            if let Some(value) = self.align_content.clone() {
5067                base.align_content = value;
5068            }
5069            if let Some(value) = self.justify_content.clone() {
5070                base.justify_content = value;
5071            }
5072            if let Some(value) = self.gap.clone() {
5073                base.gap = value;
5074            }
5075            if let Some(value) = self.flex_direction.clone() {
5076                base.flex_direction = value;
5077            }
5078            if let Some(value) = self.flex_wrap.clone() {
5079                base.flex_wrap = value;
5080            }
5081            if let Some(value) = self.flex_basis.clone() {
5082                base.flex_basis = value;
5083            }
5084            if let Some(value) = self.flex_grow.clone() {
5085                base.flex_grow = value;
5086            }
5087            if let Some(value) = self.flex_shrink.clone() {
5088                base.flex_shrink = value;
5089            }
5090            if let Some(value) = self.fill.clone() {
5091                base.fill = value;
5092            }
5093            if let Some(value) = self.text_color.clone() {
5094                base.text_color = value;
5095            }
5096        }
5097    }
5098    impl From<OptionalStyle> for Style
5099    where
5100        Style: Default,
5101    {
5102        fn from(wrapper: OptionalStyle) -> Self {
5103            let mut base = Self::default();
5104            wrapper.assign(&mut base);
5105            base
5106        }
5107    }
5108    impl Style {
5109        pub const DEFAULT: Style = Style {
5110            display: Display::DEFAULT,
5111            overflow: Point {
5112                x: Overflow::Visible,
5113                y: Overflow::Visible,
5114            },
5115            scrollbar_width: 0.0,
5116            position: Position::Relative,
5117            inset: Edges::auto(),
5118            margin: Edges::<Length>::zero(),
5119            padding: Edges::<DefinedLength>::zero(),
5120            border: Edges::<DefinedLength>::zero(),
5121            size: Size::auto(),
5122            min_size: Size::auto(),
5123            max_size: Size::auto(),
5124            aspect_ratio: None,
5125            gap: Size::zero(),
5126            align_items: None,
5127            align_self: None,
5128            align_content: None,
5129            justify_content: None,
5130            flex_direction: FlexDirection::Row,
5131            flex_wrap: FlexWrap::NoWrap,
5132            flex_grow: 0.0,
5133            flex_shrink: 1.0,
5134            flex_basis: Length::Auto,
5135            fill: None,
5136            text_color: None,
5137        };
5138        pub fn new() -> Self {
5139            Self::DEFAULT.clone()
5140        }
5141        pub fn to_taffy(&self, rem_size: f32) -> taffy::style::Style {
5142            taffy::style::Style {
5143                display: self.display,
5144                overflow: self.overflow.clone().into(),
5145                scrollbar_width: self.scrollbar_width,
5146                position: self.position,
5147                inset: self.inset.to_taffy(rem_size),
5148                size: self.size.to_taffy(rem_size),
5149                min_size: self.min_size.to_taffy(rem_size),
5150                max_size: self.max_size.to_taffy(rem_size),
5151                aspect_ratio: self.aspect_ratio,
5152                margin: self.margin.to_taffy(rem_size),
5153                padding: self.padding.to_taffy(rem_size),
5154                border: self.border.to_taffy(rem_size),
5155                align_items: self.align_items,
5156                align_self: self.align_self,
5157                align_content: self.align_content,
5158                justify_content: self.justify_content,
5159                gap: self.gap.to_taffy(rem_size),
5160                flex_direction: self.flex_direction,
5161                flex_wrap: self.flex_wrap,
5162                flex_basis: self.flex_basis.to_taffy(rem_size).into(),
5163                flex_grow: self.flex_grow,
5164                flex_shrink: self.flex_shrink,
5165                ..Default::default()
5166            }
5167        }
5168    }
5169    impl Default for Style {
5170        fn default() -> Self {
5171            Self::DEFAULT.clone()
5172        }
5173    }
5174    impl OptionalStyle {
5175        pub fn text_style(&self) -> Option<OptionalTextStyle> {
5176            self.text_color.map(|color| OptionalTextStyle { color })
5177        }
5178    }
5179    pub struct OptionalTextStyle {
5180        color: Option<Hsla>,
5181    }
5182    impl OptionalTextStyle {
5183        pub fn apply(&self, style: &mut gpui::fonts::TextStyle) {
5184            if let Some(color) = self.color {
5185                style.color = color.into();
5186            }
5187        }
5188    }
5189    pub enum Fill {
5190        Color(Hsla),
5191    }
5192    #[automatically_derived]
5193    impl ::core::clone::Clone for Fill {
5194        #[inline]
5195        fn clone(&self) -> Fill {
5196            match self {
5197                Fill::Color(__self_0) => {
5198                    Fill::Color(::core::clone::Clone::clone(__self_0))
5199                }
5200            }
5201        }
5202    }
5203    impl Fill {
5204        pub fn color(&self) -> Option<Hsla> {
5205            match self {
5206                Fill::Color(color) => Some(*color),
5207            }
5208        }
5209    }
5210    impl Default for Fill {
5211        fn default() -> Self {
5212            Self::Color(Hsla::default())
5213        }
5214    }
5215    impl From<Hsla> for Fill {
5216        fn from(color: Hsla) -> Self {
5217            Self::Color(color)
5218        }
5219    }
5220}
5221mod text {
5222    use crate::{
5223        element::{Element, ElementMetadata, EventHandler, IntoElement},
5224        style::Style,
5225    };
5226    use gpui::{geometry::Size, text_layout::LineLayout, RenderContext};
5227    use parking_lot::Mutex;
5228    use std::sync::Arc;
5229    impl<V: 'static, S: Into<ArcCow<'static, str>>> IntoElement<V> for S {
5230        type Element = Text<V>;
5231        fn into_element(self) -> Self::Element {
5232            Text {
5233                text: self.into(),
5234                metadata: Default::default(),
5235            }
5236        }
5237    }
5238    pub struct Text<V> {
5239        text: ArcCow<'static, str>,
5240        metadata: ElementMetadata<V>,
5241    }
5242    impl<V: 'static> Element<V> for Text<V> {
5243        type Layout = Arc<Mutex<Option<TextLayout>>>;
5244        fn declared_style(&mut self) -> &mut crate::style::OptionalStyle {
5245            &mut self.metadata.style
5246        }
5247        fn layout(
5248            &mut self,
5249            view: &mut V,
5250            cx: &mut gpui::LayoutContext<V>,
5251        ) -> anyhow::Result<(taffy::tree::NodeId, Self::Layout)> {
5252            let rem_size = cx.rem_pixels();
5253            let fonts = cx.platform().fonts();
5254            let text_style = cx.text_style();
5255            let line_height = cx.font_cache().line_height(text_style.font_size);
5256            let layout_engine = cx.layout_engine().expect("no layout engine present");
5257            let text = self.text.clone();
5258            let layout = Arc::new(Mutex::new(None));
5259            let style: Style = self.metadata.style.into();
5260            let node_id = layout_engine
5261                .add_measured_node(
5262                    style.to_taffy(rem_size),
5263                    {
5264                        let layout = layout.clone();
5265                        move |params| {
5266                            let line_layout = fonts
5267                                .layout_line(
5268                                    text.as_ref(),
5269                                    text_style.font_size,
5270                                    &[(text.len(), text_style.to_run())],
5271                                );
5272                            let size = Size {
5273                                width: line_layout.width,
5274                                height: line_height,
5275                            };
5276                            layout
5277                                .lock()
5278                                .replace(TextLayout {
5279                                    line_layout: Arc::new(line_layout),
5280                                    line_height,
5281                                });
5282                            size
5283                        }
5284                    },
5285                )?;
5286            Ok((node_id, layout))
5287        }
5288        fn paint<'a>(
5289            &mut self,
5290            layout: crate::element::Layout<Arc<Mutex<Option<TextLayout>>>>,
5291            view: &mut V,
5292            cx: &mut crate::element::PaintContext<V>,
5293        ) -> anyhow::Result<()> {
5294            let element_layout_lock = layout.from_element.lock();
5295            let element_layout = element_layout_lock
5296                .as_ref()
5297                .expect("layout has not been performed");
5298            let line_layout = element_layout.line_layout.clone();
5299            let line_height = element_layout.line_height;
5300            drop(element_layout_lock);
5301            let text_style = cx.text_style();
5302            let line = gpui::text_layout::Line::new(
5303                line_layout,
5304                &[(self.text.len(), text_style.to_run())],
5305            );
5306            line.paint(
5307                cx.scene,
5308                layout.from_engine.bounds.origin(),
5309                layout.from_engine.bounds,
5310                line_height,
5311                cx.legacy_cx,
5312            );
5313            Ok(())
5314        }
5315        fn handlers_mut(&mut self) -> &mut Vec<EventHandler<V>> {
5316            &mut self.metadata.handlers
5317        }
5318    }
5319    pub struct TextLayout {
5320        line_layout: Arc<LineLayout>,
5321        line_height: f32,
5322    }
5323    pub enum ArcCow<'a, T: ?Sized> {
5324        Borrowed(&'a T),
5325        Owned(Arc<T>),
5326    }
5327    impl<'a, T: ?Sized> Clone for ArcCow<'a, T> {
5328        fn clone(&self) -> Self {
5329            match self {
5330                Self::Borrowed(borrowed) => Self::Borrowed(borrowed),
5331                Self::Owned(owned) => Self::Owned(owned.clone()),
5332            }
5333        }
5334    }
5335    impl<'a, T: ?Sized> From<&'a T> for ArcCow<'a, T> {
5336        fn from(s: &'a T) -> Self {
5337            Self::Borrowed(s)
5338        }
5339    }
5340    impl<T> From<Arc<T>> for ArcCow<'_, T> {
5341        fn from(s: Arc<T>) -> Self {
5342            Self::Owned(s)
5343        }
5344    }
5345    impl From<String> for ArcCow<'_, str> {
5346        fn from(value: String) -> Self {
5347            Self::Owned(value.into())
5348        }
5349    }
5350    impl<T: ?Sized> std::ops::Deref for ArcCow<'_, T> {
5351        type Target = T;
5352        fn deref(&self) -> &Self::Target {
5353            match self {
5354                ArcCow::Borrowed(s) => s,
5355                ArcCow::Owned(s) => s.as_ref(),
5356            }
5357        }
5358    }
5359    impl<T: ?Sized> AsRef<T> for ArcCow<'_, T> {
5360        fn as_ref(&self) -> &T {
5361            match self {
5362                ArcCow::Borrowed(borrowed) => borrowed,
5363                ArcCow::Owned(owned) => owned.as_ref(),
5364            }
5365        }
5366    }
5367}
5368mod themes {
5369    use crate::color::{Hsla, Lerp};
5370    use std::ops::Range;
5371    pub mod rose_pine {
5372        use std::ops::Range;
5373        use crate::{
5374            color::{hsla, rgb, Hsla},
5375            ThemeColors,
5376        };
5377        pub struct RosePineThemes {
5378            pub default: RosePinePalette,
5379            pub dawn: RosePinePalette,
5380            pub moon: RosePinePalette,
5381        }
5382        pub struct RosePinePalette {
5383            pub base: Hsla,
5384            pub surface: Hsla,
5385            pub overlay: Hsla,
5386            pub muted: Hsla,
5387            pub subtle: Hsla,
5388            pub text: Hsla,
5389            pub love: Hsla,
5390            pub gold: Hsla,
5391            pub rose: Hsla,
5392            pub pine: Hsla,
5393            pub foam: Hsla,
5394            pub iris: Hsla,
5395            pub highlight_low: Hsla,
5396            pub highlight_med: Hsla,
5397            pub highlight_high: Hsla,
5398        }
5399        #[automatically_derived]
5400        impl ::core::clone::Clone for RosePinePalette {
5401            #[inline]
5402            fn clone(&self) -> RosePinePalette {
5403                let _: ::core::clone::AssertParamIsClone<Hsla>;
5404                *self
5405            }
5406        }
5407        #[automatically_derived]
5408        impl ::core::marker::Copy for RosePinePalette {}
5409        #[automatically_derived]
5410        impl ::core::fmt::Debug for RosePinePalette {
5411            fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5412                let names: &'static _ = &[
5413                    "base",
5414                    "surface",
5415                    "overlay",
5416                    "muted",
5417                    "subtle",
5418                    "text",
5419                    "love",
5420                    "gold",
5421                    "rose",
5422                    "pine",
5423                    "foam",
5424                    "iris",
5425                    "highlight_low",
5426                    "highlight_med",
5427                    "highlight_high",
5428                ];
5429                let values: &[&dyn ::core::fmt::Debug] = &[
5430                    &self.base,
5431                    &self.surface,
5432                    &self.overlay,
5433                    &self.muted,
5434                    &self.subtle,
5435                    &self.text,
5436                    &self.love,
5437                    &self.gold,
5438                    &self.rose,
5439                    &self.pine,
5440                    &self.foam,
5441                    &self.iris,
5442                    &self.highlight_low,
5443                    &self.highlight_med,
5444                    &&self.highlight_high,
5445                ];
5446                ::core::fmt::Formatter::debug_struct_fields_finish(
5447                    f,
5448                    "RosePinePalette",
5449                    names,
5450                    values,
5451                )
5452            }
5453        }
5454        impl RosePinePalette {
5455            pub fn default() -> RosePinePalette {
5456                RosePinePalette {
5457                    base: rgb(0x191724),
5458                    surface: rgb(0x1f1d2e),
5459                    overlay: rgb(0x26233a),
5460                    muted: rgb(0x6e6a86),
5461                    subtle: rgb(0x908caa),
5462                    text: rgb(0xe0def4),
5463                    love: rgb(0xeb6f92),
5464                    gold: rgb(0xf6c177),
5465                    rose: rgb(0xebbcba),
5466                    pine: rgb(0x31748f),
5467                    foam: rgb(0x9ccfd8),
5468                    iris: rgb(0xc4a7e7),
5469                    highlight_low: rgb(0x21202e),
5470                    highlight_med: rgb(0x403d52),
5471                    highlight_high: rgb(0x524f67),
5472                }
5473            }
5474            pub fn moon() -> RosePinePalette {
5475                RosePinePalette {
5476                    base: rgb(0x232136),
5477                    surface: rgb(0x2a273f),
5478                    overlay: rgb(0x393552),
5479                    muted: rgb(0x6e6a86),
5480                    subtle: rgb(0x908caa),
5481                    text: rgb(0xe0def4),
5482                    love: rgb(0xeb6f92),
5483                    gold: rgb(0xf6c177),
5484                    rose: rgb(0xea9a97),
5485                    pine: rgb(0x3e8fb0),
5486                    foam: rgb(0x9ccfd8),
5487                    iris: rgb(0xc4a7e7),
5488                    highlight_low: rgb(0x2a283e),
5489                    highlight_med: rgb(0x44415a),
5490                    highlight_high: rgb(0x56526e),
5491                }
5492            }
5493            pub fn dawn() -> RosePinePalette {
5494                RosePinePalette {
5495                    base: rgb(0xfaf4ed),
5496                    surface: rgb(0xfffaf3),
5497                    overlay: rgb(0xf2e9e1),
5498                    muted: rgb(0x9893a5),
5499                    subtle: rgb(0x797593),
5500                    text: rgb(0x575279),
5501                    love: rgb(0xb4637a),
5502                    gold: rgb(0xea9d34),
5503                    rose: rgb(0xd7827e),
5504                    pine: rgb(0x286983),
5505                    foam: rgb(0x56949f),
5506                    iris: rgb(0x907aa9),
5507                    highlight_low: rgb(0xf4ede8),
5508                    highlight_med: rgb(0xdfdad9),
5509                    highlight_high: rgb(0xcecacd),
5510                }
5511            }
5512        }
5513        pub fn default() -> ThemeColors {
5514            theme_colors(&RosePinePalette::default())
5515        }
5516        pub fn moon() -> ThemeColors {
5517            theme_colors(&RosePinePalette::moon())
5518        }
5519        pub fn dawn() -> ThemeColors {
5520            theme_colors(&RosePinePalette::dawn())
5521        }
5522        fn theme_colors(p: &RosePinePalette) -> ThemeColors {
5523            ThemeColors {
5524                base: scale_sl(p.base, (0.8, 0.8), (1.2, 1.2)),
5525                surface: scale_sl(p.surface, (0.8, 0.8), (1.2, 1.2)),
5526                overlay: scale_sl(p.overlay, (0.8, 0.8), (1.2, 1.2)),
5527                muted: scale_sl(p.muted, (0.8, 0.8), (1.2, 1.2)),
5528                subtle: scale_sl(p.subtle, (0.8, 0.8), (1.2, 1.2)),
5529                text: scale_sl(p.text, (0.8, 0.8), (1.2, 1.2)),
5530                highlight_low: scale_sl(p.highlight_low, (0.8, 0.8), (1.2, 1.2)),
5531                highlight_med: scale_sl(p.highlight_med, (0.8, 0.8), (1.2, 1.2)),
5532                highlight_high: scale_sl(p.highlight_high, (0.8, 0.8), (1.2, 1.2)),
5533                success: scale_sl(p.foam, (0.8, 0.8), (1.2, 1.2)),
5534                warning: scale_sl(p.gold, (0.8, 0.8), (1.2, 1.2)),
5535                error: scale_sl(p.love, (0.8, 0.8), (1.2, 1.2)),
5536                inserted: scale_sl(p.foam, (0.8, 0.8), (1.2, 1.2)),
5537                deleted: scale_sl(p.love, (0.8, 0.8), (1.2, 1.2)),
5538                modified: scale_sl(p.rose, (0.8, 0.8), (1.2, 1.2)),
5539            }
5540        }
5541        /// Produces a range by multiplying the saturation and lightness of the base color by the given
5542        /// start and end factors.
5543        fn scale_sl(
5544            base: Hsla,
5545            (start_s, start_l): (f32, f32),
5546            (end_s, end_l): (f32, f32),
5547        ) -> Range<Hsla> {
5548            let start = hsla(base.h, base.s * start_s, base.l * start_l, base.a);
5549            let end = hsla(base.h, base.s * end_s, base.l * end_l, base.a);
5550            Range { start, end }
5551        }
5552    }
5553    pub struct ThemeColors {
5554        pub base: Range<Hsla>,
5555        pub surface: Range<Hsla>,
5556        pub overlay: Range<Hsla>,
5557        pub muted: Range<Hsla>,
5558        pub subtle: Range<Hsla>,
5559        pub text: Range<Hsla>,
5560        pub highlight_low: Range<Hsla>,
5561        pub highlight_med: Range<Hsla>,
5562        pub highlight_high: Range<Hsla>,
5563        pub success: Range<Hsla>,
5564        pub warning: Range<Hsla>,
5565        pub error: Range<Hsla>,
5566        pub inserted: Range<Hsla>,
5567        pub deleted: Range<Hsla>,
5568        pub modified: Range<Hsla>,
5569    }
5570    impl ThemeColors {
5571        pub fn base(&self, level: f32) -> Hsla {
5572            self.base.lerp(level)
5573        }
5574        pub fn surface(&self, level: f32) -> Hsla {
5575            self.surface.lerp(level)
5576        }
5577        pub fn overlay(&self, level: f32) -> Hsla {
5578            self.overlay.lerp(level)
5579        }
5580        pub fn muted(&self, level: f32) -> Hsla {
5581            self.muted.lerp(level)
5582        }
5583        pub fn subtle(&self, level: f32) -> Hsla {
5584            self.subtle.lerp(level)
5585        }
5586        pub fn text(&self, level: f32) -> Hsla {
5587            self.text.lerp(level)
5588        }
5589        pub fn highlight_low(&self, level: f32) -> Hsla {
5590            self.highlight_low.lerp(level)
5591        }
5592        pub fn highlight_med(&self, level: f32) -> Hsla {
5593            self.highlight_med.lerp(level)
5594        }
5595        pub fn highlight_high(&self, level: f32) -> Hsla {
5596            self.highlight_high.lerp(level)
5597        }
5598        pub fn success(&self, level: f32) -> Hsla {
5599            self.success.lerp(level)
5600        }
5601        pub fn warning(&self, level: f32) -> Hsla {
5602            self.warning.lerp(level)
5603        }
5604        pub fn error(&self, level: f32) -> Hsla {
5605            self.error.lerp(level)
5606        }
5607        pub fn inserted(&self, level: f32) -> Hsla {
5608            self.inserted.lerp(level)
5609        }
5610        pub fn deleted(&self, level: f32) -> Hsla {
5611            self.deleted.lerp(level)
5612        }
5613        pub fn modified(&self, level: f32) -> Hsla {
5614            self.modified.lerp(level)
5615        }
5616    }
5617}
5618mod view {
5619    use crate::element::{AnyElement, Element};
5620    use gpui::{Element as _, ViewContext};
5621    pub fn view<F, E>(mut render: F) -> ViewFn
5622    where
5623        F: 'static + FnMut(&mut ViewContext<ViewFn>) -> E,
5624        E: Element<ViewFn>,
5625    {
5626        ViewFn(Box::new(move |cx| (render)(cx).into_any()))
5627    }
5628    pub struct ViewFn(Box<dyn FnMut(&mut ViewContext<ViewFn>) -> AnyElement<ViewFn>>);
5629    impl gpui::Entity for ViewFn {
5630        type Event = ();
5631    }
5632    impl gpui::View for ViewFn {
5633        fn render(&mut self, cx: &mut ViewContext<Self>) -> gpui::AnyElement<Self> {
5634            (self.0)(cx).adapt().into_any()
5635        }
5636    }
5637}
5638fn main() {
5639    SimpleLogger::init(LevelFilter::Info, Default::default())
5640        .expect("could not initialize logger");
5641    gpui::App::new(())
5642        .unwrap()
5643        .run(|cx| {
5644            cx.add_window(
5645                WindowOptions {
5646                    bounds: gpui::platform::WindowBounds::Fixed(
5647                        RectF::new(vec2f(0., 0.), vec2f(400., 300.)),
5648                    ),
5649                    center: true,
5650                    ..Default::default()
5651                },
5652                |_| view(|_| playground(&rose_pine::moon())),
5653            );
5654            cx.platform().activate(true);
5655        });
5656}
5657fn playground<V: 'static>(theme: &ThemeColors) -> impl Element<V> {
5658    frame()
5659        .text_color(black())
5660        .h_full()
5661        .w_half()
5662        .fill(theme.success(0.5))
5663        .child(
5664            button()
5665                .label("Hello")
5666                .click(|_, _, _| {
5667                    ::std::io::_print(format_args!("click!\n"));
5668                }),
5669        )
5670}