Skip to main content

NativeView

Struct NativeView 

Source
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

Source

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

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Focusable for NativeView

Source§

fn focus_handle(&self, _: &App) -> FocusHandle

Returns the focus handle associated with this view.
Source§

impl IntoElement for NativeView

Source§

type Element = Div

The specific type of element into which the implementing type is converted. Useful for converting other types into elements automatically, like Strings
Source§

fn into_element(self) -> Self::Element

Convert self into a type that implements Element.
Source§

fn into_any_element(self) -> AnyElement

Convert self into a dynamically-typed AnyElement.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<E> AnimationExt for E
where 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,

Render this component or element with an animation
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,

Render this component or element with a chain of animations
Source§

fn with_spring<T>( self, id: impl Into<ElementId>, animation: SpringAnimation<T>, animator: impl FnOnce(Self, T::Output) -> Self + 'static, ) -> SpringAnimationElement<Self>
where Self: Sized, T: SpringTarget, T::Output: 'static,

Renders this component or element at the value produced by a spring. Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> FluentBuilder for T
where T: IntoElement,

Source§

fn map<U>(self, f: impl FnOnce(Self) -> U) -> U
where Self: Sized,

Imperatively modify self with the given closure.
Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
where Self: Sized,

Conditionally modify self with the given closure.
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
where Self: Sized,

Conditionally modify self with the given closure.
Source§

fn when_some<T>( self, option: Option<T>, then: impl FnOnce(Self, T) -> Self, ) -> Self
where Self: Sized,

Conditionally unwrap and modify self with the given closure, if the given option is Some.
Source§

fn when_none<T>( self, option: &Option<T>, then: impl FnOnce(Self) -> Self, ) -> Self
where Self: Sized,

Conditionally unwrap and modify self with the given closure, if the given option is None.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more