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
impl Viewport
pub fn clamp_view_origin(&self, origin: Point) -> Point
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
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
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
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
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
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
)
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.