[][src]Struct druid::scroll_component::ScrollComponent

pub struct ScrollComponent {
    pub opacity: f64,
    pub timer_id: TimerToken,
    pub hovered: BarHoveredState,
    pub held: BarHeldState,
}

Embeddable component exposing reusable scroll handling logic.

In most situations composing Scroll is a better idea for general UI construction. However some cases are not covered by composing those widgets, such as when a widget needs fine grained control over its scrolling state or doesn't make sense to exist alone without scrolling behavior.

ScrollComponent contains the input-handling and scrollbar-positioning logic used by Scroll. It can be used to add this logic to a custom widget when the need arises.

It can be used like this:

  • Store an instance of ScrollComponent in your widget's struct, and wrap the child widget to be scrolled in a ClipBox.
  • Call event and lifecycle with all event and lifecycle events before propagating them to children.
  • Call handle_scroll with all events after handling / propagating them.
  • Call draw_bars to draw the scrollbars.

Taking a look at the Scroll source code can be helpful. You can also do scrolling without wrapping a child in a ClipBox, but you will need to do certain event and paint transformations yourself; see the ClipBox source code for an example.

Fields

opacity: f64

Current opacity for both scrollbars

timer_id: TimerToken

ID for the timer which schedules scrollbar fade out

hovered: BarHoveredState

Which if any scrollbar is currently hovered by the mouse

held: BarHeldState

Which if any scrollbar is currently being dragged by the mouse

Implementations

impl ScrollComponent[src]

pub fn new() -> ScrollComponent[src]

Constructs a new ScrollComponent for use.

pub fn are_bars_held(&self) -> bool[src]

true if either scrollbar is currently held down/being dragged

pub fn reset_scrollbar_fade<F>(&mut self, request_timer: F, env: &Env) where
    F: FnOnce(Duration) -> TimerToken
[src]

Makes the scrollbars visible, and resets the fade timer.

pub fn calc_vertical_bar_bounds(
    &self,
    port: &Viewport,
    env: &Env
) -> Option<Rect>
[src]

Calculates the paint rect of the vertical scrollbar, or None if the vertical scrollbar is not visible.

pub fn calc_horizontal_bar_bounds(
    &self,
    port: &Viewport,
    env: &Env
) -> Option<Rect>
[src]

Calculates the paint rect of the horizontal scrollbar, or None if the horizontal scrollbar is not visible.

pub fn draw_bars(
    &self,
    ctx: &mut PaintCtx<'_, '_, '_>,
    port: &Viewport,
    env: &Env
)
[src]

Draw scroll bars.

pub fn point_hits_vertical_bar(
    &self,
    port: &Viewport,
    pos: Point,
    env: &Env
) -> bool
[src]

Tests if the specified point overlaps the vertical scrollbar

Returns false if the vertical scrollbar is not visible

pub fn point_hits_horizontal_bar(
    &self,
    port: &Viewport,
    pos: Point,
    env: &Env
) -> bool
[src]

Tests if the specified point overlaps the horizontal scrollbar

Returns false if the horizontal scrollbar is not visible

pub fn event(
    &mut self,
    port: &mut Viewport,
    ctx: &mut EventCtx<'_, '_>,
    event: &Event,
    env: &Env
)
[src]

Checks if the event applies to the scroll behavior, uses it, and marks it handled

Make sure to call on every event

pub fn handle_scroll(
    &mut self,
    port: &mut Viewport,
    ctx: &mut EventCtx<'_, '_>,
    event: &Event,
    env: &Env
)
[src]

Applies mousewheel scrolling if the event has not already been handled

pub fn lifecycle(
    &mut self,
    ctx: &mut LifeCycleCtx<'_, '_>,
    event: &LifeCycle,
    env: &Env
)
[src]

Perform any necessary action prompted by a lifecycle event

Make sure to call on every lifecycle event

Trait Implementations

impl Clone for ScrollComponent[src]

impl Copy for ScrollComponent[src]

impl Debug for ScrollComponent[src]

impl Default for ScrollComponent[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> RoundFrom<T> for T

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

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.