Scenic Scrollable v0.1.0 Scenic.Scrollable.Acceleration View Source

Module for calculating the scroll speed for Scenic.Scrollable components.

Link to this section Summary

Types

Data structure containing settings that define the behaviour of the Scenic.Scrollable components scroll speed and acceleration. Note that the Scenic.Scrollable content may not be able to move when the acceleration is set too low, or the mass and counter_pressure are set too high

t()

Data structure with the necessary values to calculate the current scroll speed

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

Functions

Apply counter pressure to the current Scenic.Scrollable comonents movement. The counter pressures strength is calculated based on the Scenic.Scrollable components current speed, the components mass set during initialization, and the counter pressure value set during initialization

Apply force in the specified direction to make the Scenic.Scrollable component move

Initializes a t:Scenic.Scrollable.Acceleration.t state object based on the passed Scenic.Scrollable.Acceleration.settings/0. When nil is passed, the default settings will be used

Find out if the Scenic.Scrollable component is currently stationary

Directly update the speed of the Scenic.Scrollable components scroll movement, to make it move at a certain velocity in the given direction

Calculate the translation of a point based on the current speed

Link to this section Types

Link to this type

settings() View Source
settings() :: %{
  optional(:acceleration) => number(),
  optional(:mass) => number(),
  optional(:counter_pressure) => number()
}

Data structure containing settings that define the behaviour of the Scenic.Scrollable components scroll speed and acceleration. Note that the Scenic.Scrollable content may not be able to move when the acceleration is set too low, or the mass and counter_pressure are set too high.

Default settings:

  • acceleration: 20
  • mass: 1
  • counter_pressure: 0.1
Link to this type

t() View Source
t() :: %{
  acceleration: number(),
  mass: number(),
  counter_pressure: number(),
  force: v2(),
  speed: v2()
}

Data structure with the necessary values to calculate the current scroll speed.

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

apply_counter_pressure(state) View Source
apply_counter_pressure(t()) :: t()

Apply counter pressure to the current Scenic.Scrollable comonents movement. The counter pressures strength is calculated based on the Scenic.Scrollable components current speed, the components mass set during initialization, and the counter pressure value set during initialization.

Link to this function

apply_force(state, force) View Source
apply_force(t(), v2()) :: t()

Apply force in the specified direction to make the Scenic.Scrollable component move.

Initializes a t:Scenic.Scrollable.Acceleration.t state object based on the passed Scenic.Scrollable.Acceleration.settings/0. When nil is passed, the default settings will be used.

Link to this function

is_stationary?(arg1) View Source
is_stationary?(t()) :: boolean()

Find out if the Scenic.Scrollable component is currently stationary.

Link to this function

set_speed(state, speed) View Source
set_speed(t(), v2()) :: t()

Directly update the speed of the Scenic.Scrollable components scroll movement, to make it move at a certain velocity in the given direction.

Link to this function

translate(map, position) View Source
translate(t(), v2()) :: v2()

Calculate the translation of a point based on the current speed.