Struct titanium::desktop::gui::libdruid::scroll_component::ScrollComponent
pub struct ScrollComponent {
pub opacity: f64,
pub timer_id: TimerToken,
pub hovered: BarHoveredState,
pub held: BarHeldState,
pub enabled: ScrollbarsEnabled,
}
Expand description
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
enabled: ScrollbarsEnabled
Which scrollbars are enabled
Implementations§
§impl ScrollComponent
impl ScrollComponent
pub fn new() -> ScrollComponent
pub fn new() -> ScrollComponent
Constructs a new ScrollComponent
for use.
pub fn are_bars_held(&self) -> bool
pub fn are_bars_held(&self) -> bool
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,
pub fn reset_scrollbar_fade<F>(&mut self, request_timer: F, env: &Env)where 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>
pub fn calc_vertical_bar_bounds(&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>
pub fn calc_horizontal_bar_bounds( &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)
pub fn draw_bars(&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
pub fn point_hits_vertical_bar( &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
pub fn point_hits_horizontal_bar( &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
)
pub fn event( &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
)
pub fn handle_scroll( &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
)
pub fn lifecycle( &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
impl Clone for ScrollComponent
§fn clone(&self) -> ScrollComponent
fn clone(&self) -> ScrollComponent
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more