[−][src]Struct druid::scroll_component::ScrollComponent
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 aClipBox
. - Call
event
andlifecycle
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]
F: FnOnce(Duration) -> TimerToken,
Makes the scrollbars visible, and resets the fade timer.
pub fn calc_vertical_bar_bounds(
&self,
port: &Viewport,
env: &Env
) -> Option<Rect>
[src]
&self,
port: &Viewport,
env: &Env
) -> Option<Rect>
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]
&self,
port: &Viewport,
env: &Env
) -> Option<Rect>
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]
&self,
ctx: &mut PaintCtx<'_, '_, '_>,
port: &Viewport,
env: &Env
)
Draw scroll bars.
pub fn point_hits_vertical_bar(
&self,
port: &Viewport,
pos: Point,
env: &Env
) -> bool
[src]
&self,
port: &Viewport,
pos: Point,
env: &Env
) -> bool
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]
&self,
port: &Viewport,
pos: Point,
env: &Env
) -> bool
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]
&mut self,
port: &mut Viewport,
ctx: &mut EventCtx<'_, '_>,
event: &Event,
env: &Env
)
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]
&mut self,
port: &mut Viewport,
ctx: &mut EventCtx<'_, '_>,
event: &Event,
env: &Env
)
Applies mousewheel scrolling if the event has not already been handled
pub fn lifecycle(
&mut self,
ctx: &mut LifeCycleCtx<'_, '_>,
event: &LifeCycle,
env: &Env
)
[src]
&mut self,
ctx: &mut LifeCycleCtx<'_, '_>,
event: &LifeCycle,
env: &Env
)
Perform any necessary action prompted by a lifecycle event
Make sure to call on every lifecycle event
Trait Implementations
impl Clone for ScrollComponent
[src]
pub fn clone(&self) -> ScrollComponent
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for ScrollComponent
[src]
impl Debug for ScrollComponent
[src]
impl Default for ScrollComponent
[src]
Auto Trait Implementations
impl RefUnwindSafe for ScrollComponent
[src]
impl Send for ScrollComponent
[src]
impl Sync for ScrollComponent
[src]
impl Unpin for ScrollComponent
[src]
impl UnwindSafe for ScrollComponent
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
pub fn round_into(self) -> U
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,