Skip to main content

core.scrollbar

Scrollbar Use Scrollbar:set_size to set the bounding box of the view the scrollbar belongs to. Use Scrollbar:update to update the scrollbar animations. Use Scrollbar:draw to draw the scrollbar. Use Scrollbar:on_mouse_pressed, Scrollbar:on_mouse_released, Scrollbar:on_mouse_moved and Scrollbar:on_mouse_left to react to mouse movements; the scrollbar won't update automatically. Use Scrollbar:set_percent to set the scrollbar location externally.

To manage all the orientations, the scrollbar changes the coordinates system accordingly. The "normal" coordinate system adapts the scrollbar coordinates as if it's always a vertical scrollbar, positioned at the end of the bounding box.

local scrollbar = require "core.scrollbar"

__index

(field) __index: core.object

alignment

(field) alignment: "e"|"s"

Start or End (left to right, top to bottom)


contracted_size

(field) contracted_size: number?

Override the default value specified by style.scrollbar_size


direction

(field) direction: "h"|"v"

Vertical or Horizontal


drag_start_offset

(field) drag_start_offset: integer

Private. Used to offset the start of the drag from the top of the thumb


dragging

(field) dragging: boolean

Scrollbar dragging status


expand_percent

(field) expand_percent: number

Private. Used to keep track of animations


expanded_size

(field) expanded_size: number?

Override the default value specified by style.expanded_scrollbar_size


force_status

(field) force_status: "contracted"|"expanded"|false

Force the scrollbar status


hovering

(field) hovering: table

What is currently being hovered. thumb implies track


normal_rect

(field) normal_rect: table

percent

(field) percent: integer

Position in percent [0-1]


rect

(field) rect: table

Position information of the owner


super

(field) super: core.object

ScrollbarOptions

alignment

(field) alignment: "e"|"s"

Start or End (left to right, top to bottom)


contracted_size

(field) contracted_size: number?

Override the default value specified by style.scrollbar_size


direction

(field) direction: "h"|"v"

Vertical or Horizontal


expanded_size

(field) expanded_size: number?

Override the default value specified by style.expanded_scrollbar_size


force_status

(field) force_status: "contracted"|"expanded"|false

Force the scrollbar status


__call

(method) core.object:__call(...any)
-> core.object

Metamethod to allow using the object call as a constructor.


__tostring

(method) core.object:__tostring()
-> string

Metamethod to get a string representation of an object.


_get_thumb_rect_normal

(method) core.scrollbar:_get_thumb_rect_normal()
-> number
2. integer
3. number
4. integer

_get_track_rect_normal

(method) core.scrollbar:_get_track_rect_normal()
-> number
2. integer
3. number
4. integer

_on_mouse_moved_normal

(method) core.scrollbar:_on_mouse_moved_normal(x: any, y: any, dx: any, dy: any)
-> boolean|number

_on_mouse_pressed_normal

(method) core.scrollbar:_on_mouse_pressed_normal(button: any, x: any, y: any, clicks: any)
-> boolean|number

_on_mouse_released_normal

(method) core.scrollbar:_on_mouse_released_normal(button: any, x: any, y: any)
-> boolean

_overlaps_normal

(method) core.scrollbar:_overlaps_normal(x: any, y: any)
-> string|unknown

_update_hover_status_normal

(method) core.scrollbar:_update_hover_status_normal(x: any, y: any)
-> boolean

Updates the scrollbar hover status. This gets called by other functions and shouldn't be called manually


draw

(method) core.scrollbar:draw()

Draw both the scrollbar track and thumb


draw_thumb

(method) core.scrollbar:draw_thumb()

Draw the scrollbar thumb


draw_track

(method) core.scrollbar:draw_track()

Draw the scrollbar track


extend

(method) core.object:extend()
-> core.object

extends

(method) core.object:extends(T: any)
-> boolean

Check if the object inherits from the given type.


get_thumb_rect

(method) core.scrollbar:get_thumb_rect()
-> integer
2. integer
3. integer
4. integer

Get the thumb rect (the part of the scrollbar that can be dragged)

@return — x, y, w, h


get_track_rect

(method) core.scrollbar:get_track_rect()
-> number
2. number
3. number
4. number

Get the track rect (the "background" of the scrollbar)

@return — x, y, w, h


is

(method) core.object:is(T: any)
-> boolean

Check if the object is strictly of the given type.


is_class_of

(method) core.object:is_class_of(T: any)
-> boolean

Check if the parameter is strictly of the object type.


is_extended_by

(method) core.object:is_extended_by(T: any)
-> boolean

Check if the parameter inherits from the object.


new

(method) core.scrollbar:new(options: ScrollbarOptions)

normal_to_real

(method) core.scrollbar:normal_to_real(x: any, y: any, w: any, h: any)
-> unknown
2. unknown
3. unknown
4. unknown

on_mouse_left

(method) core.scrollbar:on_mouse_left()

Updates the scrollbar hovering status


on_mouse_moved

(method) core.scrollbar:on_mouse_moved(x: any, y: any, dx: any, dy: any)
-> boolean|number

Updates the scrollbar with mouse moved info. Won't update the scrollbar position automatically. Use Scrollbar:set_percent to update it.

This updates the hovering status.

Returns a falsy value if the event happened outside the scrollbar. Returns true if the scrollbar is hovered. If the scrollbar was being dragged, this returns a value between 0 and 1 representing the percent of the position.


on_mouse_pressed

(method) core.scrollbar:on_mouse_pressed(button: any, x: any, y: any, clicks: any)
-> boolean|number

Updates the scrollbar with mouse pressed info. Won't update the scrollbar position automatically. Use Scrollbar:set_percent to update it.

This sets the dragging status if needed.

Returns a falsy value if the event happened outside the scrollbar. Returns true if the thumb was pressed. If the track was pressed this returns a value between 0 and 1 representing the percent of the position.


on_mouse_released

(method) core.scrollbar:on_mouse_released(button: any, x: any, y: any)
-> boolean|nil

Updates the scrollbar dragging status


overlaps

(method) core.scrollbar:overlaps(x: any, y: any)
-> "thumb"|"track"|nil

Get what part of the scrollbar the coordinates overlap

return #1:
| "thumb"
| "track"

real_to_normal

(method) core.scrollbar:real_to_normal(x: any, y: any, w: any, h: any)
-> unknown
2. unknown
3. unknown
4. unknown

set_forced_status

(method) core.scrollbar:set_forced_status(status: "contracted"|"expanded"|false)

Set the status the scrollbar is forced to keep

@param status — The status to force

status:
| "expanded"
| "contracted"
| false

set_percent

(method) core.scrollbar:set_percent(percent: number)

Updates the scrollbar location

@param percent — number between 0 and 1 where 0 means thumb at the top and 1 at the bottom


set_size

(method) core.scrollbar:set_size(x: number, y: number, w: number, h: number, scrollable: number)

Updates the bounding box of the view the scrollbar belongs to.

@param scrollable — size of the scrollable area


update

(method) core.scrollbar:update()

Updates the scrollbar animations