Struct kas_widgets::ScrollComponent [−][src]
pub struct ScrollComponent { /* fields omitted */ }
Expand description
Logic for a scroll region
This struct handles some scroll logic. It does not provide scrollbars.
Implementations
Get the maximum offset
Note: the minimum offset is always zero.
Get the current offset
To translate a coordinate from the outer region to a coordinate of the scrolled region, add this offset.
Set sizes:
window_size
: size of scroll region on the outsidecontent_size
: size of scroll region on the inside (usually larger)
Like Self::set_offset
this generates a TkAction
due to potential
change in offset. In practice the caller will likely be performing all
required updates regardless and the return value can be safely ignored.
Set the scroll offset
The offset is clamped to the available scroll range.
Returns TkAction::empty()
if the offset is identical to the old offset,
or TkAction::REGION_MOVED
if the offset changes.
Set the scroll rate
This affects how fast arrow keys and the mouse wheel scroll (but not pixel offsets, as from touch devices supporting smooth scrolling).
Apply offset to an event being sent to the scrolled child
Handle Response::Focus
Inputs and outputs:
rect
: the focus rectwindow_rect
: the rect of the scroll window- returned
Rect
: the focus rect, adjusted for scroll offset; normally this should be returned via anotherResponse::Focus
- returned
TkAction
: action to pass to the event manager
Use an event to scroll, if possible
Handles keyboard (Home/End, Page Up/Down and arrow keys), mouse wheel
and touchpad scroll events. Also handles mouse/touch drag events if
the on_press_start
closure activates a mouse/touch grab.
Behaviour on Event::PressStart
is configurable: the closure is called on
this event and should call Manager::request_grab
if the press should
scroll by drag. This allows control of which mouse button(s) are used and
whether any modifiers must be pressed. For example:
fn dummy_event_handler(
id: WidgetId,
scroll: &mut kas_widgets::ScrollComponent,
mgr: &mut Manager,
event: Event
)
-> Response<Msg>
{
let window_size = Size(100, 80);
let (action, response) = scroll.scroll_by_event(event, window_size, |source, _, coord| {
if source.is_primary() {
let icon = Some(kas::event::CursorIcon::Grabbing);
mgr.request_grab(id, source, coord, kas::event::GrabMode::Grab, icon);
}
});
*mgr |= action;
response.void_into()
}
If the returned TkAction
is None
, the scroll offset has not changed and
the returned Response
is either None
or Unhandled(..)
.
If the returned TkAction
is not None
, the scroll offset has been
updated and the second return value is Response::None
.
Trait Implementations
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for ScrollComponent
impl Send for ScrollComponent
impl Sync for ScrollComponent
impl Unpin for ScrollComponent
impl UnwindSafe for ScrollComponent
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn cast_trunc(self) -> T
pub fn cast_trunc(self) -> T
Cast to integer, truncating Read more
pub fn cast_nearest(self) -> T
pub fn cast_nearest(self) -> T
Cast to the nearest integer Read more
pub fn cast_floor(self) -> T
pub fn cast_floor(self) -> T
Cast the floor to an integer Read more
pub fn try_cast_trunc(self) -> Result<T, Error>
pub fn try_cast_trunc(self) -> Result<T, Error>
Try converting to integer with truncation Read more
pub fn try_cast_nearest(self) -> Result<T, Error>
pub fn try_cast_nearest(self) -> Result<T, Error>
Try converting to the nearest integer Read more
pub fn try_cast_floor(self) -> Result<T, Error>
pub fn try_cast_floor(self) -> Result<T, Error>
Try converting the floor to an integer Read more
pub fn try_cast_ceil(self) -> Result<T, Error>
pub fn try_cast_ceil(self) -> Result<T, Error>
Try convert the ceiling to an integer Read more