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 outside
  • content_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 rect
  • window_rect: the rect of the scroll window
  • returned Rect: the focus rect, adjusted for scroll offset; normally this should be returned via another Response::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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Cast from Self to T

Try converting from Self to T

Cast to integer, truncating Read more

Cast to the nearest integer Read more

Cast the floor to an integer Read more

Cast the ceiling to an integer Read more

Try converting to integer with truncation Read more

Try converting to the nearest integer Read more

Try converting the floor to an integer Read more

Try convert the ceiling to an integer Read more

Convert from T to Self

Try converting from T to Self

Returns true if the given item matches this filter

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.