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