Scenic Scrollable v0.1.0 Scenic.Scrollable.ScrollBar View Source

The scroll bar component can be used to draw a scroll bar to the scene by adding it to the graph. The scroll bar is used internally by the Scenic.Scrollable component and for most cases it is recommended to use the Scenic.Scrollable component instead.

The scroll bar can be setup to make use of scroll buttons at the scroll bars edges, in order to enable scrolling by pressing and holding such button, in addition to dragging the scroll bar slider control to drag, or clicking the slider background to jump.

Data

Scenic.Scrollable.ScrollBar.settings/0

The scroll bar requires the following data for initialization:

  • width: number
  • height: number
  • content_size: number
  • scroll_position: number
  • direction: :horizontal | :vertical

Width and height define the display size of the scroll bar. The content size defines the size of the scrollable content in the direction of the scroll bar. When the scroll bar is a horizontal scroll bar, the content size should correspond to the width of the content. The scroll position specifies the starting position of the scrollable content. Note that the scroll position corresponds to the translation of the content, rather than the scroll bar slider. The direction specifies if the scroll bar scrolls in horizontal, or in vertical direction.

Styles

Scenic.Scrollable.ScrollBar.styles/0

Optional styles to customize the scroll bar. The following styles are supported:

The scroll_buttons boolean can be used to specify of the scroll bar should contain buttons for scrolling, in addition to the scroll bar slider. The scroll buttons are not shown by default. A theme can be passed using the scroll_bar_theme element to provide a set of colors for the scroll bar. For more information on themes, see the Scenic.Primitive.Style.Theme module. The default theme is :light. The scroll bars rounding and border can be adjusted using the scroll_bar_radius and scroll_bar_border elements respectively. The default values are 3 and 1. The scroll_drag settings can be provided to specify by which mouse button the scroll bar slider can be dragged. By default, the :left, :right and :middle buttons are all enabled.

Examples

iex> graph = Scenic.Scrollable.Components.scroll_bar(
...>   Scenic.Graph.build(),
...>   %{
...>     width: 200,
...>     height: 10,
...>     content_size: 1000,
...>     scroll_position: 0,
...>     direction: :horizontal
...>   },
...>   [id: :scroll_bar_component_1]
...> )
...> graph.primitives[1].id
:scroll_bar_component_1

iex> graph = Scenic.Scrollable.Components.scroll_bar(
...>   Scenic.Graph.build(),
...>   %{
...>     width: 200,
...>     height: 10,
...>     content_size: 1000,
...>     scroll_position: 0,
...>     direction: :horizontal
...>   },
...>   [
...>     scroll_buttons: true,
...>     scroll_bar_theme: Scenic.Primitive.Style.Theme.preset(:dark),
...>     scroll_bar_radius: 4,
...>     scroll_bar_border: 1,
...>     scroll_drag: %{
...>       mouse_buttons: [:left, :right]
...>     },
...>     id: :scroll_bar_component_2
...>   ]
...> )
...> graph.primitives[1].id
:scroll_bar_component_2

Link to this section Summary

Types

Atom representing a mouse button

Data structure representing a rectangle

A map containing information about the scroll button pressed states

Specifies the direction in which the scroll bar affects the content. A direction can be either :horizontal or :vertical

The data required to initialize a scroll bar component. The scroll bar requires the following data for initialization

The optional styles with which the scroll bar component can be customized. See this modules top section for a more detailed explanation of every style

A collection of optional styles with which the scroll bar component can be customized. See Scenic.Scrollable.ScrollBar.style/0 and this modules top section for more information

t()

The state with which the scroll bar components GenServer is running

Data structure representing a vector 2, in the form of an {x, y} tuple

Functions

Find out the direction in which the content should be scrolled based on the scroll buttons currently being pressed. Although the scroll bar will move along a single axis, a vector 2 is returned to facilitate translation calculations of the content

Find out if the scroll bar is currently being dragged by the user

Find the latest position the scrollable content should be updated with. The position corresponds to the contents translation, rather than the scroll bars drag control translation

Link to this section Types

Link to this type

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

Atom representing a mouse button.

Data structure representing a rectangle.

Link to this type

scroll_buttons() View Source
scroll_buttons() :: %{
  scroll_button_1: :pressed | :released,
  scroll_button_2: :pressed | :released
}

A map containing information about the scroll button pressed states.

Specifies the direction in which the scroll bar affects the content. A direction can be either :horizontal or :vertical.

Link to this type

settings() View Source
settings() :: %{
  width: number(),
  height: number(),
  content_size: number(),
  scroll_position: number(),
  direction: scroll_direction()
}

The data required to initialize a scroll bar component. The scroll bar requires the following data for initialization:

  • width: number
  • height: number
  • content_size: number
  • scroll_position: number
  • direction: :horizontal | :vertical

Width and height define the display size of the scroll bar. The content size defines the size of the scrollable content in the direction of the scroll bar. When the scroll bar is a horizontal scroll bar, the content size should correspond to the width of the content. The scroll position specifies the starting position of the scrollable content. Note that the scroll position corresponds to the translation of the content, rather than the scroll bar slider. The direction specifies if the scroll bar scrolls in horizontal, or in vertical direction.

Link to this type

style() View Source
style() ::
  {:scroll_buttons, boolean()}
  | {:scroll_bar_theme, %{}}
  | {:scroll_bar_radius, number()}
  | {:scroll_bar_border, number()}
  | {:scroll_drag, Scenic.Scrollable.Drag.settings()}

The optional styles with which the scroll bar component can be customized. See this modules top section for a more detailed explanation of every style.

Link to this type

styles() View Source
styles() :: [style()]

A collection of optional styles with which the scroll bar component can be customized. See Scenic.Scrollable.ScrollBar.style/0 and this modules top section for more information.

Link to this type

t() View Source
t() :: %Scenic.Scrollable.ScrollBar{
  content_size: Scenic.Scrollable.Direction.t(),
  direction: scroll_direction(),
  drag_state: Scenic.Scrollable.Drag.t(),
  frame_size: Scenic.Scrollable.Direction.t(),
  graph: Scenic.Graph.t(),
  height: Scenic.Scrollable.Direction.t(),
  id: atom(),
  last_scroll_position: Scenic.Scrollable.Direction.t(),
  pid: pid(),
  position_cap: Scenic.Scrollable.PositionCap.t(),
  scroll_bar_slider_background: :pressed | :released,
  scroll_buttons: :none | {:some, scroll_buttons()},
  scroll_position: Scenic.Scrollable.Direction.t(),
  scroll_state: :idle | :scrolling | :dragging,
  styles: styles(),
  width: Scenic.Scrollable.Direction.t()
}

The state with which the scroll bar components GenServer is running.

Data structure representing a vector 2, in the form of an {x, y} tuple.

Link to this section Functions

Link to this function

add_to_graph(graph, data \\ nil, opts \\ []) View Source
add_to_graph(graph :: Scenic.Graph.t(), data :: any(), opts :: list()) ::
  Scenic.Graph.t()

Callback implementation for Scenic.Component.add_to_graph/3.

Link to this function

direction(pid) View Source
direction(pid() | t()) :: v2()

Find out the direction in which the content should be scrolled based on the scroll buttons currently being pressed. Although the scroll bar will move along a single axis, a vector 2 is returned to facilitate translation calculations of the content.

Link to this function

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

Find out if the scroll bar is currently being dragged by the user.

Link to this function

new_position(state) View Source
new_position(t()) :: v2()

Find the latest position the scrollable content should be updated with. The position corresponds to the contents translation, rather than the scroll bars drag control translation.