Scenic Scrollable v0.1.0 Scenic.Scrollable.Drag View Source

Module for handling the drag controllability for Scenic.Scrollable components.

Link to this section Summary

Types

Atom representing what state the drag functionality is currently in. The drag state can be 'idle' or 'dragging'

Atom representing a mouse button

Data structure with settings that dictate the behaviour of the drag controllability. It consists of a list with Scenic.Scrollable.Drag.mouse_button/0s which specify the buttons with which the user can drag the Scenic.Scrollable component. By default, drag functionality is disabled

t()

The state containing the necessary information to enable the drag functionality

Shorthand for Scenic.Math.vector_2/0. Consists of a tuple containing the x and y numeric values

Functions

Increases the current scroll speed, intended to be called when the user stops dragging. The increase in speed is intended to make the drag experience more smooth

Find out if the user is currently dragging the Scenic.Scrollable component

Update the Scenic.Scrollable.Drag.t/0 based on the pressed mouse button, mouse position, and the position of the scrollable content

Update the Scenic.Scrollable.Drag.t/0 based on the new cursor position the user has moved to

Update the Scenic.Scrollable.Drag.t/0 based on the released mouse button and mouse position

Initialize the Scenic.Scrollable.Drag.t/0 state by passing in the Scenic.Scrollable.Drag.settings/0 settings object. When nil is passed, the default settings will be used

Get the position of the users cursor during the previous update. Returns an OptionEx.t/0 containing the coordinate, or :none if the user was not dragging during the previous update

Calculate the new scroll position based on the current drag state. The result will be wrapped in an OptionEx.t/0, resulting in :none if the user currently is not scrolling

Link to this section Types

Link to this type

drag_state() View Source
drag_state() :: :idle | :dragging

Atom representing what state the drag functionality is currently in. The drag state can be 'idle' or 'dragging'.

Link to this type

mouse_button() View Source
mouse_button() :: :left | :right | :middle

Atom representing a mouse button.

Link to this type

settings() View Source
settings() :: %{optional(:mouse_buttons) => [mouse_button()]}

Data structure with settings that dictate the behaviour of the drag controllability. It consists of a list with Scenic.Scrollable.Drag.mouse_button/0s which specify the buttons with which the user can drag the Scenic.Scrollable component. By default, drag functionality is disabled.

Link to this type

t() View Source
t() :: %Scenic.Scrollable.Drag{
  current: :none | {:some, v2()},
  drag_start: :none | {:some, v2()},
  drag_start_content_position: :none | {:some, v2()},
  drag_state: drag_state(),
  enabled_buttons: [mouse_button()]
}

The state containing the necessary information to enable the drag functionality.

Shorthand for Scenic.Math.vector_2/0. Consists of a tuple containing the x and y numeric values.

Link to this section Functions

Link to this function

amplify_speed(_, speed) View Source
amplify_speed(t(), v2()) :: v2()

Increases the current scroll speed, intended to be called when the user stops dragging. The increase in speed is intended to make the drag experience more smooth.

Link to this function

dragging?(map) View Source
dragging?(t()) :: boolean()

Find out if the user is currently dragging the Scenic.Scrollable component.

Link to this function

handle_mouse_click(state, button, point, content_position) View Source
handle_mouse_click(t(), mouse_button(), v2(), v2()) :: t()

Update the Scenic.Scrollable.Drag.t/0 based on the pressed mouse button, mouse position, and the position of the scrollable content.

Link to this function

handle_mouse_move(state, point) View Source
handle_mouse_move(t(), v2()) :: t()

Update the Scenic.Scrollable.Drag.t/0 based on the new cursor position the user has moved to.

Link to this function

handle_mouse_release(state, button, point) View Source
handle_mouse_release(t(), mouse_button(), v2()) :: t()

Update the Scenic.Scrollable.Drag.t/0 based on the released mouse button and mouse position.

Link to this function

init(settings) View Source
init(nil | settings()) :: t()

Initialize the Scenic.Scrollable.Drag.t/0 state by passing in the Scenic.Scrollable.Drag.settings/0 settings object. When nil is passed, the default settings will be used.

Link to this function

last_position(map) View Source
last_position(t()) :: {:some, v2()} | :none

Get the position of the users cursor during the previous update. Returns an OptionEx.t/0 containing the coordinate, or :none if the user was not dragging during the previous update.

Link to this function

new_position(arg1) View Source
new_position(t()) :: {:some, v2()} | :none

Calculate the new scroll position based on the current drag state. The result will be wrapped in an OptionEx.t/0, resulting in :none if the user currently is not scrolling.