| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | use crate::{ |
| 35 | App, ArenaBox, AvailableSpace, Bounds, Context, DispatchNodeId, ELEMENT_ARENA, ElementId, |
| 36 | FocusHandle, InspectorElementId, LayoutId, Pixels, Point, Size, Style, Window, |
| 37 | util::FluentBuilder, |
| 38 | }; |
| 39 | use derive_more::{Deref, DerefMut}; |
| 40 | pub(crate) use smallvec::SmallVec; |
| 41 | use std::{ |
| 42 | any::{Any, type_name}, |
| 43 | fmt::{self, Debug, Display}, |
| 44 | mem, panic, |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | pub trait Element: 'static + IntoElement { |
| 52 | |
| 53 | |
| 54 | type RequestLayoutState: 'static; |
| 55 | |
| 56 | |
| 57 | |
| 58 | type PrepaintState: 'static; |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | fn id(&self) -> Option<ElementId>; |
| 66 | |
| 67 | |
| 68 | |
| 69 | fn source_location(&self) -> Option<&'static panic::Location<'static>>; |
| 70 | |
| 71 | |
| 72 | |
| 73 | fn request_layout( |
| 74 | &mut self, |
| 75 | id: Option<&GlobalElementId>, |
| 76 | inspector_id: Option<&InspectorElementId>, |
| 77 | window: &mut Window, |
| 78 | cx: &mut App, |
| 79 | ) -> (LayoutId, Self::RequestLayoutState); |
| 80 | |
| 81 | |
| 82 | |
| 83 | fn prepaint( |
| 84 | &mut self, |
| 85 | id: Option<&GlobalElementId>, |
| 86 | inspector_id: Option<&InspectorElementId>, |
| 87 | bounds: Bounds<Pixels>, |
| 88 | request_layout: &mut Self::RequestLayoutState, |
| 89 | window: &mut Window, |
| 90 | cx: &mut App, |
| 91 | ) -> Self::PrepaintState; |
| 92 | |
| 93 | |
| 94 | |
| 95 | fn paint( |
| 96 | &mut self, |
| 97 | id: Option<&GlobalElementId>, |
| 98 | inspector_id: Option<&InspectorElementId>, |
| 99 | bounds: Bounds<Pixels>, |
| 100 | request_layout: &mut Self::RequestLayoutState, |
| 101 | prepaint: &mut Self::PrepaintState, |
| 102 | window: &mut Window, |
| 103 | cx: &mut App, |
| 104 | ); |
| 105 | |
| 106 | |
| 107 | fn into_any(self) -> AnyElement { |
| 108 | AnyElement::new(self) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | |
| 113 | pub trait IntoElement: Sized { |
| 114 | |
| 115 | |
| 116 | type Element: Element; |
| 117 | |
| 118 | |
| 119 | fn into_element(self) -> Self::Element; |
| 120 | |
| 121 | |
| 122 | fn into_any_element(self) -> AnyElement { |
| 123 | self.into_element().into_any() |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | impl<T: IntoElement> FluentBuilder for T {} |
| 128 | |
| 129 | |
| 130 | |
| 131 | pub trait Render: 'static + Sized { |
| 132 | |
| 133 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement; |
| 134 | } |
| 135 | |
| 136 | impl Render for Empty { |
| 137 | fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { |
| 138 | Empty |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | pub trait RenderOnce: 'static { |
| 148 | |
| 149 | |
| 150 | |
| 151 | fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | |
| 156 | pub trait ParentElement { |
| 157 | |
| 158 | fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>); |
| 159 | |
| 160 | |
| 161 | fn child(mut self, child: impl IntoElement) -> Self |
| 162 | where |
| 163 | Self: Sized, |
| 164 | { |
| 165 | self.extend(std::iter::once(child.into_element().into_any())); |
| 166 | self |
| 167 | } |
| 168 | |
| 169 | |
| 170 | fn children(mut self, children: impl IntoIterator<Item = impl IntoElement>) -> Self |
| 171 | where |
| 172 | Self: Sized, |
| 173 | { |
| 174 | self.extend(children.into_iter().map(|child| child.into_any_element())); |
| 175 | self |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | |
| 180 | |
| 181 | #[doc(hidden)] |
| 182 | pub struct Component<C: RenderOnce> { |
| 183 | component: Option<C>, |
| 184 | #[cfg(debug_assertions)] |
| 185 | source: &'static core::panic::Location<'static>, |
| 186 | } |
| 187 | |
| 188 | impl<C: RenderOnce> Component<C> { |
| 189 | |
| 190 | #[track_caller] |
| 191 | pub fn new(component: C) -> Self { |
| 192 | Component { |
| 193 | component: Some(component), |
| 194 | #[cfg(debug_assertions)] |
| 195 | source: core::panic::Location::caller(), |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | impl<C: RenderOnce> Element for Component<C> { |
| 201 | type RequestLayoutState = AnyElement; |
| 202 | type PrepaintState = (); |
| 203 | |
| 204 | fn id(&self) -> Option<ElementId> { |
| 205 | None |
| 206 | } |
| 207 | |
| 208 | fn source_location(&self) -> Option<&'static core::panic::Location<'static>> { |
| 209 | #[cfg(debug_assertions)] |
| 210 | return Some(self.source); |
| 211 | |
| 212 | #[cfg(not(debug_assertions))] |
| 213 | return None; |
| 214 | } |
| 215 | |
| 216 | fn request_layout( |
| 217 | &mut self, |
| 218 | _id: Option<&GlobalElementId>, |
| 219 | _inspector_id: Option<&InspectorElementId>, |
| 220 | window: &mut Window, |
| 221 | cx: &mut App, |
| 222 | ) -> (LayoutId, Self::RequestLayoutState) { |
| 223 | window.with_global_id(ElementId::Name(type_name::<C>().into()), |_, window| { |
| 224 | let mut element = self |
| 225 | .component |
| 226 | .take() |
| 227 | .unwrap() |
| 228 | .render(window, cx) |
| 229 | .into_any_element(); |
| 230 | |
| 231 | let layout_id = element.request_layout(window, cx); |
| 232 | (layout_id, element) |
| 233 | }) |
| 234 | } |
| 235 | |
| 236 | fn prepaint( |
| 237 | &mut self, |
| 238 | _id: Option<&GlobalElementId>, |
| 239 | _inspector_id: Option<&InspectorElementId>, |
| 240 | _: Bounds<Pixels>, |
| 241 | element: &mut AnyElement, |
| 242 | window: &mut Window, |
| 243 | cx: &mut App, |
| 244 | ) { |
| 245 | window.with_global_id(ElementId::Name(type_name::<C>().into()), |_, window| { |
| 246 | element.prepaint(window, cx); |
| 247 | }) |
| 248 | } |
| 249 | |
| 250 | fn paint( |
| 251 | &mut self, |
| 252 | _id: Option<&GlobalElementId>, |
| 253 | _inspector_id: Option<&InspectorElementId>, |
| 254 | _: Bounds<Pixels>, |
| 255 | element: &mut Self::RequestLayoutState, |
| 256 | _: &mut Self::PrepaintState, |
| 257 | window: &mut Window, |
| 258 | cx: &mut App, |
| 259 | ) { |
| 260 | window.with_global_id(ElementId::Name(type_name::<C>().into()), |_, window| { |
| 261 | element.paint(window, cx); |
| 262 | }) |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | impl<C: RenderOnce> IntoElement for Component<C> { |
| 267 | type Element = Self; |
| 268 | |
| 269 | fn into_element(self) -> Self::Element { |
| 270 | self |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | |
| 275 | #[derive(Deref, DerefMut, Default, Debug, Eq, PartialEq, Hash)] |
| 276 | pub struct GlobalElementId(pub(crate) SmallVec<[ElementId; 32]>); |
| 277 | |
| 278 | impl Display for GlobalElementId { |
| 279 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 280 | for (i, element_id) in self.0.iter().enumerate() { |
| 281 | if i > 0 { |
| 282 | write!(f, ".")?; |
| 283 | } |
| 284 | write!(f, "{}", element_id)?; |
| 285 | } |
| 286 | Ok(()) |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | trait ElementObject { |
| 291 | fn inner_element(&mut self) -> &mut dyn Any; |
| 292 | |
| 293 | fn request_layout(&mut self, window: &mut Window, cx: &mut App) -> LayoutId; |
| 294 | |
| 295 | fn prepaint(&mut self, window: &mut Window, cx: &mut App); |
| 296 | |
| 297 | fn paint(&mut self, window: &mut Window, cx: &mut App); |
| 298 | |
| 299 | fn layout_as_root( |
| 300 | &mut self, |
| 301 | available_space: Size<AvailableSpace>, |
| 302 | window: &mut Window, |
| 303 | cx: &mut App, |
| 304 | ) -> Size<Pixels>; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | pub struct Drawable<E: Element> { |
| 309 | |
| 310 | pub element: E, |
| 311 | phase: ElementDrawPhase<E::RequestLayoutState, E::PrepaintState>, |
| 312 | } |
| 313 | |
| 314 | #[derive(Default)] |
| 315 | enum ElementDrawPhase<RequestLayoutState, PrepaintState> { |
| 316 | #[default] |
| 317 | Start, |
| 318 | RequestLayout { |
| 319 | layout_id: LayoutId, |
| 320 | global_id: Option<GlobalElementId>, |
| 321 | inspector_id: Option<InspectorElementId>, |
| 322 | request_layout: RequestLayoutState, |
| 323 | }, |
| 324 | LayoutComputed { |
| 325 | layout_id: LayoutId, |
| 326 | global_id: Option<GlobalElementId>, |
| 327 | inspector_id: Option<InspectorElementId>, |
| 328 | available_space: Size<AvailableSpace>, |
| 329 | request_layout: RequestLayoutState, |
| 330 | }, |
| 331 | Prepaint { |
| 332 | node_id: DispatchNodeId, |
| 333 | global_id: Option<GlobalElementId>, |
| 334 | inspector_id: Option<InspectorElementId>, |
| 335 | bounds: Bounds<Pixels>, |
| 336 | request_layout: RequestLayoutState, |
| 337 | prepaint: PrepaintState, |
| 338 | }, |
| 339 | Painted, |
| 340 | } |
| 341 | |
| 342 | |
| 343 | impl<E: Element> Drawable<E> { |
| 344 | pub(crate) fn new(element: E) -> Self { |
| 345 | Drawable { |
| 346 | element, |
| 347 | phase: ElementDrawPhase::Start, |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | fn request_layout(&mut self, window: &mut Window, cx: &mut App) -> LayoutId { |
| 352 | match mem::take(&mut self.phase) { |
| 353 | ElementDrawPhase::Start => { |
| 354 | let global_id = self.element.id().map(|element_id| { |
| 355 | window.element_id_stack.push(element_id); |
| 356 | GlobalElementId(window.element_id_stack.clone()) |
| 357 | }); |
| 358 | |
| 359 | let inspector_id; |
| 360 | #[cfg(any(feature = "inspector", debug_assertions))] |
| 361 | { |
| 362 | inspector_id = self.element.source_location().map(|source| { |
| 363 | let path = crate::InspectorElementPath { |
| 364 | global_id: GlobalElementId(window.element_id_stack.clone()), |
| 365 | source_location: source, |
| 366 | }; |
| 367 | window.build_inspector_element_id(path) |
| 368 | }); |
| 369 | } |
| 370 | #[cfg(not(any(feature = "inspector", debug_assertions)))] |
| 371 | { |
| 372 | inspector_id = None; |
| 373 | } |
| 374 | |
| 375 | let (layout_id, request_layout) = self.element.request_layout( |
| 376 | global_id.as_ref(), |
| 377 | inspector_id.as_ref(), |
| 378 | window, |
| 379 | cx, |
| 380 | ); |
| 381 | |
| 382 | if global_id.is_some() { |
| 383 | window.element_id_stack.pop(); |
| 384 | } |
| 385 | |
| 386 | self.phase = ElementDrawPhase::RequestLayout { |
| 387 | layout_id, |
| 388 | global_id, |
| 389 | inspector_id, |
| 390 | request_layout, |
| 391 | }; |
| 392 | layout_id |
| 393 | } |
| 394 | _ => panic!("must call request_layout only once"), |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | pub(crate) fn prepaint(&mut self, window: &mut Window, cx: &mut App) { |
| 399 | match mem::take(&mut self.phase) { |
| 400 | ElementDrawPhase::RequestLayout { |
| 401 | layout_id, |
| 402 | global_id, |
| 403 | inspector_id, |
| 404 | mut request_layout, |
| 405 | } |
| 406 | | ElementDrawPhase::LayoutComputed { |
| 407 | layout_id, |
| 408 | global_id, |
| 409 | inspector_id, |
| 410 | mut request_layout, |
| 411 | .. |
| 412 | } => { |
| 413 | if let Some(element_id) = self.element.id() { |
| 414 | window.element_id_stack.push(element_id); |
| 415 | debug_assert_eq!(global_id.as_ref().unwrap().0, window.element_id_stack); |
| 416 | } |
| 417 | |
| 418 | let bounds = window.layout_bounds(layout_id); |
| 419 | let node_id = window.next_frame.dispatch_tree.push_node(); |
| 420 | let prepaint = self.element.prepaint( |
| 421 | global_id.as_ref(), |
| 422 | inspector_id.as_ref(), |
| 423 | bounds, |
| 424 | &mut request_layout, |
| 425 | window, |
| 426 | cx, |
| 427 | ); |
| 428 | window.next_frame.dispatch_tree.pop_node(); |
| 429 | |
| 430 | if global_id.is_some() { |
| 431 | window.element_id_stack.pop(); |
| 432 | } |
| 433 | |
| 434 | self.phase = ElementDrawPhase::Prepaint { |
| 435 | node_id, |
| 436 | global_id, |
| 437 | inspector_id, |
| 438 | bounds, |
| 439 | request_layout, |
| 440 | prepaint, |
| 441 | }; |
| 442 | } |
| 443 | _ => panic!("must call request_layout before prepaint"), |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | pub(crate) fn paint( |
| 448 | &mut self, |
| 449 | window: &mut Window, |
| 450 | cx: &mut App, |
| 451 | ) -> (E::RequestLayoutState, E::PrepaintState) { |
| 452 | match mem::take(&mut self.phase) { |
| 453 | ElementDrawPhase::Prepaint { |
| 454 | node_id, |
| 455 | global_id, |
| 456 | inspector_id, |
| 457 | bounds, |
| 458 | mut request_layout, |
| 459 | mut prepaint, |
| 460 | .. |
| 461 | } => { |
| 462 | if let Some(element_id) = self.element.id() { |
| 463 | window.element_id_stack.push(element_id); |
| 464 | debug_assert_eq!(global_id.as_ref().unwrap().0, window.element_id_stack); |
| 465 | } |
| 466 | |
| 467 | window.next_frame.dispatch_tree.set_active_node(node_id); |
| 468 | self.element.paint( |
| 469 | global_id.as_ref(), |
| 470 | inspector_id.as_ref(), |
| 471 | bounds, |
| 472 | &mut request_layout, |
| 473 | &mut prepaint, |
| 474 | window, |
| 475 | cx, |
| 476 | ); |
| 477 | |
| 478 | if global_id.is_some() { |
| 479 | window.element_id_stack.pop(); |
| 480 | } |
| 481 | |
| 482 | self.phase = ElementDrawPhase::Painted; |
| 483 | (request_layout, prepaint) |
| 484 | } |
| 485 | _ => panic!("must call prepaint before paint"), |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | pub(crate) fn layout_as_root( |
| 490 | &mut self, |
| 491 | available_space: Size<AvailableSpace>, |
| 492 | window: &mut Window, |
| 493 | cx: &mut App, |
| 494 | ) -> Size<Pixels> { |
| 495 | if matches!(&self.phase, ElementDrawPhase::Start) { |
| 496 | self.request_layout(window, cx); |
| 497 | } |
| 498 | |
| 499 | let layout_id = match mem::take(&mut self.phase) { |
| 500 | ElementDrawPhase::RequestLayout { |
| 501 | layout_id, |
| 502 | global_id, |
| 503 | inspector_id, |
| 504 | request_layout, |
| 505 | } => { |
| 506 | window.compute_layout(layout_id, available_space, cx); |
| 507 | self.phase = ElementDrawPhase::LayoutComputed { |
| 508 | layout_id, |
| 509 | global_id, |
| 510 | inspector_id, |
| 511 | available_space, |
| 512 | request_layout, |
| 513 | }; |
| 514 | layout_id |
| 515 | } |
| 516 | ElementDrawPhase::LayoutComputed { |
| 517 | layout_id, |
| 518 | global_id, |
| 519 | inspector_id, |
| 520 | available_space: prev_available_space, |
| 521 | request_layout, |
| 522 | } => { |
| 523 | if available_space != prev_available_space { |
| 524 | window.compute_layout(layout_id, available_space, cx); |
| 525 | } |
| 526 | self.phase = ElementDrawPhase::LayoutComputed { |
| 527 | layout_id, |
| 528 | global_id, |
| 529 | inspector_id, |
| 530 | available_space, |
| 531 | request_layout, |
| 532 | }; |
| 533 | layout_id |
| 534 | } |
| 535 | _ => panic!("cannot measure after painting"), |
| 536 | }; |
| 537 | |
| 538 | window.layout_bounds(layout_id).size |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | impl<E> ElementObject for Drawable<E> |
| 543 | where |
| 544 | E: Element, |
| 545 | E::RequestLayoutState: 'static, |
| 546 | { |
| 547 | fn inner_element(&mut self) -> &mut dyn Any { |
| 548 | &mut self.element |
| 549 | } |
| 550 | |
| 551 | fn request_layout(&mut self, window: &mut Window, cx: &mut App) -> LayoutId { |
| 552 | Drawable::request_layout(self, window, cx) |
| 553 | } |
| 554 | |
| 555 | fn prepaint(&mut self, window: &mut Window, cx: &mut App) { |
| 556 | Drawable::prepaint(self, window, cx); |
| 557 | } |
| 558 | |
| 559 | fn paint(&mut self, window: &mut Window, cx: &mut App) { |
| 560 | Drawable::paint(self, window, cx); |
| 561 | } |
| 562 | |
| 563 | fn layout_as_root( |
| 564 | &mut self, |
| 565 | available_space: Size<AvailableSpace>, |
| 566 | window: &mut Window, |
| 567 | cx: &mut App, |
| 568 | ) -> Size<Pixels> { |
| 569 | Drawable::layout_as_root(self, available_space, window, cx) |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | |
| 574 | pub struct AnyElement(ArenaBox<dyn ElementObject>); |
| 575 | |
| 576 | impl AnyElement { |
| 577 | pub(crate) fn new<E>(element: E) -> Self |
| 578 | where |
| 579 | E: 'static + Element, |
| 580 | E::RequestLayoutState: Any, |
| 581 | { |
| 582 | let element = ELEMENT_ARENA |
| 583 | .with_borrow_mut(|arena| arena.alloc(|| Drawable::new(element))) |
| 584 | .map(|element| element as &mut dyn ElementObject); |
| 585 | AnyElement(element) |
| 586 | } |
| 587 | |
| 588 | |
| 589 | pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> { |
| 590 | self.0.inner_element().downcast_mut::<T>() |
| 591 | } |
| 592 | |
| 593 | |
| 594 | |
| 595 | pub fn request_layout(&mut self, window: &mut Window, cx: &mut App) -> LayoutId { |
| 596 | self.0.request_layout(window, cx) |
| 597 | } |
| 598 | |
| 599 | |
| 600 | |
| 601 | pub fn prepaint(&mut self, window: &mut Window, cx: &mut App) -> Option<FocusHandle> { |
| 602 | let focus_assigned = window.next_frame.focus.is_some(); |
| 603 | |
| 604 | self.0.prepaint(window, cx); |
| 605 | |
| 606 | if !focus_assigned && let Some(focus_id) = window.next_frame.focus { |
| 607 | return FocusHandle::for_id(focus_id, &cx.focus_handles); |
| 608 | } |
| 609 | |
| 610 | None |
| 611 | } |
| 612 | |
| 613 | |
| 614 | pub fn paint(&mut self, window: &mut Window, cx: &mut App) { |
| 615 | self.0.paint(window, cx); |
| 616 | } |
| 617 | |
| 618 | |
| 619 | pub fn layout_as_root( |
| 620 | &mut self, |
| 621 | available_space: Size<AvailableSpace>, |
| 622 | window: &mut Window, |
| 623 | cx: &mut App, |
| 624 | ) -> Size<Pixels> { |
| 625 | self.0.layout_as_root(available_space, window, cx) |
| 626 | } |
| 627 | |
| 628 | |
| 629 | |
| 630 | pub fn prepaint_at( |
| 631 | &mut self, |
| 632 | origin: Point<Pixels>, |
| 633 | window: &mut Window, |
| 634 | cx: &mut App, |
| 635 | ) -> Option<FocusHandle> { |
| 636 | window.with_absolute_element_offset(origin, |window| self.prepaint(window, cx)) |
| 637 | } |
| 638 | |
| 639 | |
| 640 | |
| 641 | pub fn prepaint_as_root( |
| 642 | &mut self, |
| 643 | origin: Point<Pixels>, |
| 644 | available_space: Size<AvailableSpace>, |
| 645 | window: &mut Window, |
| 646 | cx: &mut App, |
| 647 | ) -> Option<FocusHandle> { |
| 648 | self.layout_as_root(available_space, window, cx); |
| 649 | window.with_absolute_element_offset(origin, |window| self.prepaint(window, cx)) |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | impl Element for AnyElement { |
| 654 | type RequestLayoutState = (); |
| 655 | type PrepaintState = (); |
| 656 | |
| 657 | fn id(&self) -> Option<ElementId> { |
| 658 | None |
| 659 | } |
| 660 | |
| 661 | fn source_location(&self) -> Option<&'static panic::Location<'static>> { |
| 662 | None |
| 663 | } |
| 664 | |
| 665 | fn request_layout( |
| 666 | &mut self, |
| 667 | _: Option<&GlobalElementId>, |
| 668 | _inspector_id: Option<&InspectorElementId>, |
| 669 | window: &mut Window, |
| 670 | cx: &mut App, |
| 671 | ) -> (LayoutId, Self::RequestLayoutState) { |
| 672 | let layout_id = self.request_layout(window, cx); |
| 673 | (layout_id, ()) |
| 674 | } |
| 675 | |
| 676 | fn prepaint( |
| 677 | &mut self, |
| 678 | _: Option<&GlobalElementId>, |
| 679 | _inspector_id: Option<&InspectorElementId>, |
| 680 | _: Bounds<Pixels>, |
| 681 | _: &mut Self::RequestLayoutState, |
| 682 | window: &mut Window, |
| 683 | cx: &mut App, |
| 684 | ) { |
| 685 | self.prepaint(window, cx); |
| 686 | } |
| 687 | |
| 688 | fn paint( |
| 689 | &mut self, |
| 690 | _: Option<&GlobalElementId>, |
| 691 | _inspector_id: Option<&InspectorElementId>, |
| 692 | _: Bounds<Pixels>, |
| 693 | _: &mut Self::RequestLayoutState, |
| 694 | _: &mut Self::PrepaintState, |
| 695 | window: &mut Window, |
| 696 | cx: &mut App, |
| 697 | ) { |
| 698 | self.paint(window, cx); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | impl IntoElement for AnyElement { |
| 703 | type Element = Self; |
| 704 | |
| 705 | fn into_element(self) -> Self::Element { |
| 706 | self |
| 707 | } |
| 708 | |
| 709 | fn into_any_element(self) -> AnyElement { |
| 710 | self |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | |
| 715 | pub struct Empty; |
| 716 | |
| 717 | impl IntoElement for Empty { |
| 718 | type Element = Self; |
| 719 | |
| 720 | fn into_element(self) -> Self::Element { |
| 721 | self |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | impl Element for Empty { |
| 726 | type RequestLayoutState = (); |
| 727 | type PrepaintState = (); |
| 728 | |
| 729 | fn id(&self) -> Option<ElementId> { |
| 730 | None |
| 731 | } |
| 732 | |
| 733 | fn source_location(&self) -> Option<&'static panic::Location<'static>> { |
| 734 | None |
| 735 | } |
| 736 | |
| 737 | fn request_layout( |
| 738 | &mut self, |
| 739 | _id: Option<&GlobalElementId>, |
| 740 | _inspector_id: Option<&InspectorElementId>, |
| 741 | window: &mut Window, |
| 742 | cx: &mut App, |
| 743 | ) -> (LayoutId, Self::RequestLayoutState) { |
| 744 | (window.request_layout(Style::default(), None, cx), ()) |
| 745 | } |
| 746 | |
| 747 | fn prepaint( |
| 748 | &mut self, |
| 749 | _id: Option<&GlobalElementId>, |
| 750 | _inspector_id: Option<&InspectorElementId>, |
| 751 | _bounds: Bounds<Pixels>, |
| 752 | _state: &mut Self::RequestLayoutState, |
| 753 | _window: &mut Window, |
| 754 | _cx: &mut App, |
| 755 | ) { |
| 756 | } |
| 757 | |
| 758 | fn paint( |
| 759 | &mut self, |
| 760 | _id: Option<&GlobalElementId>, |
| 761 | _inspector_id: Option<&InspectorElementId>, |
| 762 | _bounds: Bounds<Pixels>, |
| 763 | _request_layout: &mut Self::RequestLayoutState, |
| 764 | _prepaint: &mut Self::PrepaintState, |
| 765 | _window: &mut Window, |
| 766 | _cx: &mut App, |
| 767 | ) { |
| 768 | } |
| 769 | } |