use crate::{
App, Bounds, Element, ElementId, GlobalElementId, InspectorElementId, IntoElement, LayoutId,
Pixels, PlatformViewHandle, Style, StyleRefinement, Styled, Window,
};
use refineable::Refineable;
pub struct PlatformView {
handle: PlatformViewHandle,
style: StyleRefinement,
}
pub fn platform_view(handle: PlatformViewHandle) -> PlatformView {
PlatformView {
handle,
style: StyleRefinement::default(),
}
}
impl Element for PlatformView {
type RequestLayoutState = ();
type PrepaintState = ();
fn id(&self) -> Option<ElementId> {
None
}
fn source_location(&self) -> Option<&'static core::panic::Location<'static>> {
None
}
fn request_layout(
&mut self,
_global_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
window: &mut Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState) {
let mut style = Style::default();
style.refine(&self.style);
let layout_id = window.request_layout(style, [], cx);
(layout_id, ())
}
fn prepaint(
&mut self,
_global_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
_bounds: Bounds<Pixels>,
_request_layout: &mut Self::RequestLayoutState,
_window: &mut Window,
_cx: &mut App,
) -> Self::PrepaintState {
}
fn paint(
&mut self,
_global_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
_request_layout: &mut Self::RequestLayoutState,
_prepaint: &mut Self::PrepaintState,
window: &mut Window,
_cx: &mut App,
) {
window.paint_platform_view(bounds, self.handle.clone());
}
}
impl IntoElement for PlatformView {
type Element = Self;
fn into_element(self) -> Self::Element {
self
}
}
impl Styled for PlatformView {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}