# cp.ui.ElementCache

Provides caching for Element subclasses that want to cache children.


# API Overview

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

  • ElementCache

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

  • cachedElement
  • cacheElement
  • clean
  • fetchElement
  • fetchElements
  • reset

# API Documentation

# Constructors

# ElementCache

Signature cp.ui.ElementCache(parent[, createFn])
Type Constructor
Description Creates and returns a new ElementCache, with the specified parent and function which will create new elements on demand. The createFn has the signature of function(parent, ui) -> cp.ui.Element, and should take the parent provided here and the axuielement and return a new Element subclass.
Parameters
  • parent - the parent Element that contains the cached items.
  • createFn - a function that will create new Element subclasses based on cached axuielement values.
Returns
  • The new ElementCache.
Notes None
Examples None
Source src/extensions/cp/ui/ElementCache.lua line 12

# Methods

# cachedElement

Signature cp.ui.ElementCache:cachedElement(ui) -> cp.ui.Element or nil
Type Method
Description Returns the cached Element, if it is present.
Parameters
  • ui - The axuielement it is linked to. If not provided, it will be fetched by calling Element:UI().
Returns
  • cp.ui.Element or nil
Notes None
Examples None
Source src/extensions/cp/ui/ElementCache.lua line 61

# cacheElement

Signature cp.ui.ElementCache:cacheElement(element[, ui]) -> none
Type Method
Description Caches the provided Element.
Parameters
  • element - The Element
  • ui - The axuielement it is linked to. If not provided, it will be fetched by calling Element:UI().
Returns
  • None
Notes None
Examples None
Source src/extensions/cp/ui/ElementCache.lua line 81

# clean

Signature cp.ui.ElementCache:clean()
Type Method
Description Clears the cache of any invalid (aka dead) items.
Parameters
  • None
Returns
  • None
Notes None
Examples None
Source src/extensions/cp/ui/ElementCache.lua line 28

# fetchElement

Signature cp.ui.ElementCache:fetchElement(ui) -> cp.ui.Element or nil
Type Method
Description Retrieves the matching Element instance from the cache. If none exists and the createFn was provided in the constructor, it will be used to create a new one, which is automatically cached for future reference.
Parameters
  • ui - The axuielement being fetched for.
Returns
  • cp.ui.Element or nil
Notes None
Examples None
Source src/extensions/cp/ui/ElementCache.lua line 99

# fetchElements

Signature cp.ui.ElementCache:fetchElements(uis) -> table of cp.ui.Elements or nil
Type Method
Description Fetches a list of Element instances linked to the provided axuielement list.
Parameters
  • uis - A table of axuielement values.
Returns
Notes
  • If any of the provided axuielement values are either not from the parent, or no longer valid, a nil value will be stored in the matching index. Note that in that case, this will break useage of ipairs due to leaving holes in the list.
Examples None
Source src/extensions/cp/ui/ElementCache.lua line 126

# reset

Signature cp.ui.ElementCache:reset() -> none
Type Method
Description Removes all cached items from the cache.
Parameters
  • None
Returns
  • None
Notes None
Examples None
Source src/extensions/cp/ui/ElementCache.lua line 48