# cp.ui.ScrollArea

A ScrollArea represents an AXScrollArea. They primarily function as a "portal" to view a larger area of the contained axuielement within (accessed via the AXContents attribute), and also provide access to the vertical and horizontal scroll bars (accessed via the verticalScrollBar and horizontalScrollBar properties).

The class that wraps the AXContents attribute can be provided via the contentsInit parameter in the constructor. If not provided it defaults to Element.

The ScrollArea also delegates to the contents property, so you can access any properties of the contained Element directly.

For example, if you have a ScrollArea with a contents of a TextField, you can normally access the text value via the TextField.value property. However, if you want to access the text value via the ScrollArea itself, you can do so via the ScrollArea.value property, like so:

local scrollArea = ScrollArea(parent, ui, TextArea)
-- via `contents`:
local value = scrollArea.contents:value()
--- via delegation:
local value = scrollArea:value()

It also has a Builder that supports customising an Element Builder to create a ScrollArea with a specified contents Element type. For example, another way to define our ScrollArea that contains a TextField is:

local scrollAreaWithTextField = ScrollArea:containing(TextField)
local scrollArea = scrollAreaWithTextField(parent, ui)

The main advantage of this style is that you can pass the Builder in to other Element types that require an "Element init" that will only be provided a parent and UI finder.

This is a subclass of Element.


# Submodules


# API Overview

Functions - API calls offered directly by the extension

  • containing
  • matches

Constructors - API calls which return an object, typically one that offers API methods

  • ScrollArea

Fields - Variables which can only be accessed from an object returned by a constructor

  • contents
  • contentsUI
  • horizontalScrollBar
  • selectedChildrenUI
  • verticalScrollBar
  • viewFrame

Methods - API calls which can only be made on an object returned by a constructor

  • childrenUI
  • deselectAll
  • loadLayout
  • saveLayout
  • selectAll
  • selectChild
  • selectChildAt
  • shiftHorizontalBy
  • shiftHorizontalTo
  • shiftVerticalBy
  • shiftVerticalTo
  • showChild
  • showChildAt

# API Documentation

# Functions

# containing

Signature cp.ui.ScrollArea:containing(elementInit) -> cp.ui.ScrollArea.Builder
Type Function
Description A static method that returns a new ScrollArea.Builder.
Parameters
  • elementInit - An Element initializer.
Returns
  • A new ScrollArea.Builder instance.
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 71

# matches

Signature cp.ui.ScrollArea.matches(element) -> boolean
Type Function
Description Checks to see if an element matches what we think it should be.
Parameters
  • element - An axuielementObject to check.
Returns
  • true if matches otherwise false
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 85

# Constructors

# ScrollArea

Signature cp.ui.ScrollArea(parent, uiFinder[, contentsInit]) -> cp.ui.ScrollArea
Type Constructor
Description Creates a new ScrollArea.
Parameters
  • parent - The parent object.
  • uiFinder - A function or cp.prop which will return the hs.axuielement when available.
  • contentsInit - An optional function to initialise the contentsUI. Uses cp.ui.Element by default.
Returns
  • The new ScrollArea.
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 96

# Fields

# contents

Signature cp.ui.ScrollArea.contents <cp.ui.Element>
Type Field
Description Returns the Element representing the ScrollArea Contents.
Notes None
Source src/extensions/cp/ui/ScrollArea.lua line 119

# contentsUI

Signature cp.ui.ScrollArea.contentsUI <cp.prop: hs.axuielement; read-only; live?>
Type Field
Description Returns the axuielement representing the Scroll Area Contents, or nil if not available.
Notes None
Source src/extensions/cp/ui/ScrollArea.lua line 112

# horizontalScrollBar

Signature cp.ui.ScrollArea.horizontalScrollBar <cp.ui.ScrollBar>
Type Field
Description The horizontal ScrollBar.
Notes None
Source src/extensions/cp/ui/ScrollArea.lua line 133

# selectedChildrenUI

Signature cp.ui.ScrollArea.selectedChildrenUI <cp.prop: hs.axuielement; read-only; live?>
Type Field
Description Returns the axuielement representing the Scroll Area Selected Children, or nil if not available.
Notes None
Source src/extensions/cp/ui/ScrollArea.lua line 140

# verticalScrollBar

Signature cp.ui.ScrollArea.verticalScrollBar <cp.ui.ScrollBar>
Type Field
Description The vertical ScrollBar.
Notes None
Source src/extensions/cp/ui/ScrollArea.lua line 126

# viewFrame

Signature cp.ui.ScrollArea.viewFrame <cp.prop:table; read-only>
Type Field
Description A cp.prop reporting the Scroll Area frame as a table containing {x, y, w, h}.
Notes None
Source src/extensions/cp/ui/ScrollArea.lua line 171

# Methods

# childrenUI

Signature cp.ui.ScrollArea:childrenUI(filterFn) -> hs.axuielement | nil
Type Method
Description Returns the list of axuielements representing the Scroll Area Contents, sorted top-down, or nil if not available.
Parameters
  • filterFn - The function which checks if the child matches the requirements.
Returns
  • The axuielement or nil.
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 153

# deselectAll

Signature cp.ui.ScrollArea:deselectAll() -> self
Type Method
Description Deselect all children in a scroll area.
Parameters
  • None
Returns
  • Self
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 305

# loadLayout

Signature cp.ui.ScrollArea:loadLayout(layout) -> none
Type Method
Description Loads a Scroll Area layout.
Parameters
  • layout - A table containing the ScrollArea layout settings, typically created using saveLayout.
Returns
  • None
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 393

# saveLayout

Signature cp.ui.ScrollArea:saveLayout() -> table
Type Method
Description Saves the current Scroll Area layout to a table.
Parameters
  • None
Returns
  • A table containing the current Scroll Area Layout.
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 374

# selectAll

Signature cp.ui.ScrollArea:selectAll(childrenUI) -> self
Type Method
Description Select all children in a scroll area.
Parameters
  • childrenUI - A table of hs.axuielement objects.
Returns
  • Self
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 286

# selectChild

Signature cp.ui.ScrollArea:selectChild(childUI) -> self
Type Method
Description Select a specific child within a Scroll Area.
Parameters
  • childUI - The hs.axuielement object of the child you want to select.
Returns
  • Self
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 250

# selectChildAt

Signature cp.ui.ScrollArea:selectChildAt(index) -> self
Type Method
Description Select a child element in a Scroll Area given a specific index.
Parameters
  • index - The index of the child you want to select.
Returns
  • Self
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 269

# shiftHorizontalBy

Signature cp.ui.ScrollArea:shiftHorizontalBy(amount) -> number
Type Method
Description Attempts to shift the horizontal scroll bar by the specified amount.
Parameters
  • amount - The amount to shift
Returns
  • The actual value of the horizontal scroll bar.
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 322

# shiftHorizontalTo

Signature cp.ui.ScrollArea:shiftHorizontalTo(value) -> number
Type Method
Description Attempts to shift the horizontal scroll bar to the specified value.
Parameters
  • value - The new value (typically between 0 and 1).
Returns
  • The actual value of the horizontal scroll bar.
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 335

# shiftVerticalBy

Signature cp.ui.ScrollArea:shiftVerticalBy(amount) -> number
Type Method
Description Attempts to shift the vertical scroll bar by the specified amount.
Parameters
  • amount - The amount to shift
Returns
  • The actual value of the vertical scroll bar.
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 348

# shiftVerticalTo

Signature cp.ui.ScrollArea:shiftVerticalTo(value) -> number
Type Method
Description Attempts to shift the vertical scroll bar to the specified value.
Parameters
  • value - The new value (typically between 0 and 1).
Returns
  • The actual value of the vertical scroll bar.
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 361

# showChild

Signature cp.ui.ScrollArea:showChild(childUI) -> self
Type Method
Description Show's a child element in a Scroll Area.
Parameters
  • childUI - The hs.axuielement object of the child you want to show.
Returns
  • Self
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 195

# showChildAt

Signature cp.ui.ScrollArea:showChildAt(index) -> self
Type Method
Description Show's a child element in a Scroll Area given a specific index.
Parameters
  • index - The index of the child you want to show.
Returns
  • Self
Notes None
Examples None
Source src/extensions/cp/ui/ScrollArea.lua line 233