Trait ViewWrapper

Source
pub trait ViewWrapper:
    Send
    + Sync
    + 'static {
    type V: View + ?Sized;

    // Required methods
    fn with_view<F, R>(&self, f: F) -> Option<R>
       where F: FnOnce(&Self::V) -> R;
    fn with_view_mut<F, R>(&mut self, f: F) -> Option<R>
       where F: FnOnce(&mut Self::V) -> R;

    // Provided methods
    fn into_inner(self) -> Result<Self::V, Self>
       where Self: Sized,
             Self::V: Sized { ... }
    fn wrap_draw(&self, printer: &Printer<'_, '_>) { ... }
    fn wrap_required_size(&mut self, req: Vec2) -> Vec2 { ... }
    fn wrap_on_event(&mut self, ch: Event) -> EventResult { ... }
    fn wrap_layout(&mut self, size: Vec2) { ... }
    fn wrap_take_focus(
        &mut self,
        source: Direction,
    ) -> Result<EventResult, CannotFocus> { ... }
    fn wrap_call_on_any(&mut self, selector: &Selector<'_>, callback: AnyCb<'_>) { ... }
    fn wrap_focus_view(
        &mut self,
        selector: &Selector<'_>,
    ) -> Result<EventResult, ViewNotFound> { ... }
    fn wrap_needs_relayout(&self) -> bool { ... }
    fn wrap_important_area(&self, size: Vec2) -> Rect { ... }
}
Expand description

Generic wrapper around a view.

This trait is a shortcut to implement View on a type by forwarding calls to a wrapped view.

You only need to define with_view and with_view_mut (the wrap_impl! macro can help you with that), and you will get the View implementation for free.

You can also override any of the wrap_* methods for more specific behaviors (the default implementations simply forwards the calls to the child view).

Required Associated Types§

Source

type V: View + ?Sized

Type that this view wraps.

Required Methods§

Source

fn with_view<F, R>(&self, f: F) -> Option<R>
where F: FnOnce(&Self::V) -> R,

Runs a function on the inner view, returning the result.

Returns None if the inner view is unavailable. This should only happen with some views if they are already borrowed by another call.

Source

fn with_view_mut<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce(&mut Self::V) -> R,

Runs a function on the inner view, returning the result.

Returns None if the inner view is unavailable. This should only happen with some views if they are already borrowed by another call.

Provided Methods§

Source

fn into_inner(self) -> Result<Self::V, Self>
where Self: Sized, Self::V: Sized,

Attempts to retrieve the inner view.

Source

fn wrap_draw(&self, printer: &Printer<'_, '_>)

Wraps the draw method.

Source

fn wrap_required_size(&mut self, req: Vec2) -> Vec2

Wraps the required_size method.

Source

fn wrap_on_event(&mut self, ch: Event) -> EventResult

Wraps the on_event method.

Source

fn wrap_layout(&mut self, size: Vec2)

Wraps the layout method.

Source

fn wrap_take_focus( &mut self, source: Direction, ) -> Result<EventResult, CannotFocus>

Wraps the take_focus method.

Source

fn wrap_call_on_any(&mut self, selector: &Selector<'_>, callback: AnyCb<'_>)

Wraps the find method.

Source

fn wrap_focus_view( &mut self, selector: &Selector<'_>, ) -> Result<EventResult, ViewNotFound>

Wraps the focus_view method.

Source

fn wrap_needs_relayout(&self) -> bool

Wraps the needs_relayout method.

Source

fn wrap_important_area(&self, size: Vec2) -> Rect

Wraps the important_area method.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl ViewWrapper for BoxedView

Source§

type V = dyn View

Source§

impl<T: View + 'static> ViewWrapper for NamedView<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for CircularFocus<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for FocusTracker<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for LastSizeView<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for Layer<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for OnEventView<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for ResizedView<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for ShadowView<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for ThemedView<T>

Source§

type V = T

Source§

impl<T: View> ViewWrapper for TrackedView<T>

Source§

type V = T

Source§

impl<T: View, I> ViewWrapper for GradientView<T, I>
where I: Send + Sync + 'static + Interpolator,

Source§

type V = T

Source§

impl<V> ViewWrapper for ScreensView<V>
where V: View,

Source§

type V = V

Source§

impl<V: View> ViewWrapper for EnableableView<V>

Source§

type V = V

Source§

impl<V: View> ViewWrapper for HideableView<V>

Source§

type V = V

Source§

impl<V: View> ViewWrapper for OnLayoutView<V>

Source§

type V = V

Source§

impl<V: View> ViewWrapper for PaddedView<V>

Source§

type V = V

Source§

impl<V: View> ViewWrapper for Panel<V>

Source§

type V = V