pub struct NativeView(/* private fields */);Expand description
A view owned by the platform’s UI toolkit, shown inside a GPUI window.
Only macOS shows native views so far, where the view is an NSView.
NativeView::new fails on every other platform.
The view is composited beneath the window’s GPUI content and shows through wherever this handle is used as an element, so elements painted after it cover it like they would cover any other element. The view is treated as opaque, and is not affected by element opacity or transformations.
Mouse input over the view goes to the view, and to nothing behind it,
wherever no element painted after the view takes mouse input. An element
that is only drawn over the view covers it without taking its mouse input. The window’s own content is still told of a mouse press
there, as a press outside every element. An element behind the view hears
no mouse moves while the pointer is over it, so follow a drag that can cross
the view with on_drag_move, or with an element in front of the view.
The view takes keyboard input directly from the platform while its
FocusHandle is focused, which a click on the view does, as can an
assistive technology such as VoiceOver moving its cursor into the view.
A key the view doesn’t use is then dispatched from the view’s element like
any other key press, so key bindings apply to what the view leaves.
Two kinds of key reach key bindings before the view. Bindings for actions
passed to reserve_action apply first, and their
keys never reach the view. A key held with Command or Control is offered to
the view as a key equivalent, which is how a web view takes it; a view that
only takes such keys as ordinary key presses, as AppKit’s text views do,
gets one after key bindings have had it.
The view may take a moment to leave a key, so the keys of any other multi-key binding can reach the view when they are typed quickly.
The view stays attached to the window it was created in, hidden when it isn’t painted, until the last clone of this handle is dropped. Painted more than once in a frame, it shows only where it was painted first. It shows nothing as an element of any other window, so showing the same platform view in another window takes dropping this handle and creating one there.
Implementations§
Source§impl NativeView
impl NativeView
Sourcepub unsafe fn new(
view: NonNull<c_void>,
window: &mut Window,
cx: &mut App,
) -> Result<Self>
pub unsafe fn new( view: NonNull<c_void>, window: &mut Window, cx: &mut App, ) -> Result<Self>
Attaches a platform view to the window.
§Errors
Fails on platforms that cannot composite native views, which is every platform but macOS for now.
§Safety
view must point to a live view of the kind the window’s platform
embeds, which is an NSView on macOS, and that view must not be in
another view hierarchy.
GPUI retains the view and puts it inside a view of its own, until the last clone of the returned handle is dropped. Until then GPUI decides the view’s frame, whether it is hidden, and its order among the window’s other views, so the caller must leave those alone and must not move the view to another superview.
Source§impl NativeView
impl NativeView
Sourcepub fn set_background(&self, color: impl Into<Hsla>, cx: &mut App)
pub fn set_background(&self, color: impl Into<Hsla>, cx: &mut App)
Sets the color shown where the view has not caught up with its element.
The platform moves the view through its own compositor, so for a frame or two after its element moves or resizes, part of the element can be uncovered. A color close to the view’s own background hides that. A window showing several native views uses the color of the one painted last.
Sourcepub fn reserve_action<A: Action>(&self)
pub fn reserve_action<A: Action>(&self)
Makes key bindings for A apply before the view sees the key.
The view otherwise sees every key first and can keep any of them, so this is for the few bindings that must work whatever the view shows. The view never sees a key that such a binding starts with, even when the rest of the binding’s keys don’t follow.
Trait Implementations§
Source§impl Clone for NativeView
impl Clone for NativeView
Source§impl Focusable for NativeView
impl Focusable for NativeView
Source§fn focus_handle(&self, _: &App) -> FocusHandle
fn focus_handle(&self, _: &App) -> FocusHandle
Source§impl IntoElement for NativeView
impl IntoElement for NativeView
Source§type Element = Div
type Element = Div
Source§fn into_element(self) -> Self::Element
fn into_element(self) -> Self::Element
Element.Source§fn into_any_element(self) -> AnyElement
fn into_any_element(self) -> AnyElement
AnyElement.Auto Trait Implementations§
impl !RefUnwindSafe for NativeView
impl !Send for NativeView
impl !Sync for NativeView
impl !UnwindSafe for NativeView
impl Forget for NativeView
impl Freeze for NativeView
impl Move for NativeView
impl Unpin for NativeView
impl UnsafeUnpin for NativeView
Blanket Implementations§
Source§impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
Source§fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_spring<T>(
self,
id: impl Into<ElementId>,
animation: SpringAnimation<T>,
animator: impl FnOnce(Self, T::Output) -> Self + 'static,
) -> SpringAnimationElement<Self>
fn with_spring<T>( self, id: impl Into<ElementId>, animation: SpringAnimation<T>, animator: impl FnOnce(Self, T::Output) -> Self + 'static, ) -> SpringAnimationElement<Self>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FluentBuilder for Twhere
T: IntoElement,
impl<T> FluentBuilder for Twhere
T: IntoElement,
Source§fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more