pub struct Viewport {
    pub content_size: Size,
    pub view_origin: Point,
    pub view_size: Size,
}
Expand description

Represents the size and position of a rectangular “viewport” into a larger area.

Fields§

§content_size: Size

The size of the area that we have a viewport into.

§view_origin: Point

The origin of the view rectangle, relative to the content.

§view_size: Size

The size of the view rectangle.

Implementations§

§

impl Viewport

pub fn view_rect(&self) -> Rect

The view rectangle.

pub fn clamp_view_origin(&self, origin: Point) -> Point

Tries to find a position for the view rectangle that is contained in the content rectangle.

If the supplied origin is good, returns it; if it isn’t, we try to return the nearest origin that would make the view rectangle contained in the content rectangle. (This will fail if the content is smaller than the view, and we return 0.0 in each dimension where the content is smaller.)

pub fn pan_by(&mut self, delta: Vec2) -> bool

Changes the viewport offset by delta, while trying to keep the view rectangle inside the content rectangle.

Returns true if the offset actually changed. Even if delta is non-zero, the offset might not change. For example, if you try to move the viewport down but it is already at the bottom of the child widget, then the offset will not change and this function will return false.

pub fn pan_to(&mut self, pos: Point) -> bool

Sets the viewport origin to pos, while trying to keep the view rectangle inside the content rectangle.

Returns true if the position changed. Note that the valid values for the viewport origin are constrained by the size of the child, and so the origin might not get set to exactly pos.

pub fn pan_to_on_axis(&mut self, axis: Axis, pos: f64) -> bool

Sets the component selected by axis of viewport origin to pos, while trying to keep the view rectangle inside the content rectangle.

Returns true if the position changed. Note that the valid values for the viewport origin are constrained by the size of the child, and so the origin might not get set to exactly pos.

pub fn pan_to_visible(&mut self, rect: Rect) -> bool

Pan the smallest distance that makes the target Rect visible.

If the target rect is larger than viewport size, we will prioritize the region of the target closest to its origin.

pub fn default_scroll_to_view_handling( &mut self, ctx: &mut EventCtx<'_, '_>, global_highlight_rect: Rect ) -> bool

The default handling of the SCROLL_TO_VIEW notification for a scrolling container.

The SCROLL_TO_VIEW notification is sent when EventCtx::scroll_to_view or EventCtx::scroll_area_to_view are called.

pub fn fixed_scroll_to_view_handling( &self, ctx: &mut EventCtx<'_, '_>, global_highlight_rect: Rect, source: WidgetId )

This method handles SCROLL_TO_VIEW by clipping the view_rect to the content rect.

The SCROLL_TO_VIEW notification is sent when EventCtx::scroll_to_view or EventCtx::scroll_area_to_view are called.

Trait Implementations§

§

impl Clone for Viewport

§

fn clone(&self) -> Viewport

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Debug for Viewport

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Viewport

§

fn default() -> Viewport

Returns the “default value” for a type. Read more
§

impl PartialEq<Viewport> for Viewport

§

fn eq(&self, other: &Viewport) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Copy for Viewport

§

impl StructuralPartialEq for Viewport

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyEq for Twhere T: Any + PartialEq<T>,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 Twhere U: From<T>,

const: unstable · 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.

§

impl<T> IsDefault for Twhere T: Default + PartialEq<T> + Copy,

§

fn is_default(&self) -> bool

Checks that type has a default value.
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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