TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::ElementStorage Class Reference

The frame's element tree. More...

#include <gui_core/elements/gui_element_storage.h>

Classes

struct  PostLayoutEntry
 Fired in registration order between layout and rendering. More...

Public Member Functions

 ElementStorage (StyleManager &styleManager, ElementDataStore *dataStore=nullptr)
const StyleManager & GetStyleManager () const noexcept
 ElementStorage (ElementStorage &&) noexcept=default
ElementStorage & operator= (ElementStorage &&)=delete
 holds a StyleManager reference
 ElementStorage (const ElementStorage &)=delete
ElementStorage & operator= (const ElementStorage &)=delete
ElementStorageResult BeginConstruction ()
 Starts building a new tree, clearing the previous one.
ElementStorageResult EndConstruction ()
 Finishes the tree; NotConstructing if not constructing.
AddResult Add (Element &&element, LayoutOverride &&constraints={})
 Adds element after the previous one at the current nesting level.
ElementStorageResult AddCustomDraw (const ElementRef &ref, CustomDrawCallback callback)
 Draws callback before ref's children render.
ElementStorageResult AddCustomDrawAfter (const ElementRef &ref, CustomDrawCallback callback)
 Draws callback after ref's whole subtree, in the same space as AddCustomDraw.
ElementStorageResult AddPostLayout (const ElementRef &ref, PostLayoutCallback callback)
 Runs callback after layout, before rendering, with read-only final geometry.
ElementStorageResult BeginChildren ()
 Begins adding children to the last added element; elements without BeginChildren are leaves.
ElementStorageResult EndChildren ()
 Closes the innermost BeginChildren. Fails outside construction or without one open.
ElementStorageResult MoveChild (uint32_t childDepth, uint32_t rangeBegin, uint32_t fromLocal, uint32_t toLocal, ElementMove *outMove=nullptr)
 Moves a child (with its subtree) to another sibling position, during construction.
bool Empty () const
uint32_t ElementCount () const
ID GetLastAddedID () const
ID GetLastItemID () const
 The element last added at the level being built, its children done: after a control with parts, the control's outer element rather than its last part.
ElementRef GetLastAddedRef () const
uint32_t GetCurrentNestingDepth () const
uint32_t NumberOfDepthLevels () const
uint32_t DepthSizeOf (uint32_t depth) const
const ID GetElementIDAt (ElementRef root, int2 position, ID *disabledHit=nullptr) const
 The element at position that takes input, or Invalid.
int2 ScreenToElementSpace (int2 screenPos, ElementRef ref) const
 Converts a screen point into the space ref's own rect is stored in, applying each ancestor's inverse contentTransform like hit-testing does.
IntRect ElementRectOnScreen (ElementRef ref) const
 ref's border box on the screen: through its ancestors' contentTransforms (a canvas's pan and zoom), the box around it when it's turned.
ElementRef FindElementRefByID (ID id) const
 The element with id; Invalid when not found (always for ID::Invalid).
bool IsValidRef (const ElementRef &ref) const
ElementRef GetFirstElementRef () const
bool HasChildren (const ElementRef &ref) const
uint32_t GetChildCount (const ElementRef &ref) const
ElementRef GetParentRef (const ElementRef &ref) const
ElementRef GetNextSiblingRef (const ElementRef &ref) const
Element * GetElementPtr (const ElementRef &elementRef)
 The element, or nullptr for an invalid ref.
const Element * GetElementPtr (const ElementRef &elementRef) const
Element & GetElementUnsafe (const ElementRef &elementRef)
const Element & GetElementUnsafe (const ElementRef &elementRef) const
ElementRect * GetElementRectPtr (const ElementRef &elementRef)
const ElementRect * GetElementRectPtr (const ElementRef &elementRef) const
ElementRect & GetElementRectUnsafe (const ElementRef &elementRef)
const ElementRect & GetElementRectUnsafe (const ElementRef &elementRef) const
bool SetContentTransform (const ElementRef &ref, const float3x2 &transform)
 Sets the transform applied to ref's children at render / hit-test time (pan, zoom).
const ElementCustomDraw * GetCustomDraw (const ElementRef &elementRef) const
const std::vector< PostLayoutEntry > & GetPostLayoutEntries () const
ElementCustomDraw & GetElementCustomDrawUnsafe (const ElementRef &elementRef)
PostDrawEntry & GetPostDrawEntryUnsafe (uint32_t index)
std::span< Element > GetChildrenSpan (const ElementRef &parentRef)
 Valid until the next BeginConstruction. Empty on invalid ref or no children.
std::span< Element > GetChildrenSpanUnsafe (int depth, const IndexRange range)
 Unchecked. Valid until the next BeginConstruction.
std::span< const Element > GetChildrenSpanUnsafe (int depth, const IndexRange range) const
 Unchecked. Valid until the next BeginConstruction.
std::span< ElementRect > GetChildRectSpanUnsafe (int depth, const IndexRange range)
std::span< const ElementRect > GetChildRectSpanUnsafe (int depth, const IndexRange range) const
std::span< const Element > GetChildrenSpan (const ElementRef &parentRef) const
 Valid until the next BeginConstruction. Empty on invalid ref or no children.
IndexRange GetChildRange (const ElementRef &parentRef) const
 The indices of parentRef's children at the next depth; empty on invalid ref or no children.
TopDownDepthScanIterator TopDownDepthScanBegin () const
TopDownDepthScanIterator TopDownDepthScanEnd () const
BottomUpDepthScanIterator BottomUpDepthScanBegin () const
BottomUpDepthScanIterator BottomUpDepthScanEnd () const
TopDownDepthScanRangeIterator TopDownDepthScanRange () const
BottomUpDepthScanRangeIterator BottomUpDepthScanRange () const

Friends

struct TopDownDepthScanIterator
struct BottomUpDepthScanIterator

Detailed Description

The frame's element tree.

Not thread safe. Elements are added per frame, in order, between BeginConstruction/EndConstruction. Afterwards elements can be queried and modified, but the structure is immutable until the next BeginConstruction resets it. Elements are never removed.

All children of parents at depth D are stored contiguously at depth D+1, in the same order as their parents.

Depth-scan iterators (top-down / bottom-up) are const-only and valid only after EndConstruction.

Example:

storage.BeginConstruction();
storage.Add(root);
storage.BeginChildren();
    storage.Add(leaf);
    storage.Add(elementWithChildren);
    storage.BeginChildren();
        storage.Add(leaf);
        storage.Add(leaf);
    storage.EndChildren();
    storage.Add(leaf);
storage.EndChildren();
storage.Add(secondRoot);
storage.EndConstruction(); 

Constructor & Destructor Documentation

◆ ElementStorage() [1/3]

tachyon::ElementStorage::ElementStorage ( StyleManager & styleManager,
ElementDataStore * dataStore = nullptr )
inline

◆ ElementStorage() [2/3]

tachyon::ElementStorage::ElementStorage ( ElementStorage && )
defaultnoexcept

◆ ElementStorage() [3/3]

tachyon::ElementStorage::ElementStorage ( const ElementStorage & )
delete

Member Function Documentation

◆ GetStyleManager()

const StyleManager & tachyon::ElementStorage::GetStyleManager ( ) const
inlinenoexcept

◆ operator=() [1/2]

ElementStorage & tachyon::ElementStorage::operator= ( ElementStorage && )
delete

holds a StyleManager reference

◆ operator=() [2/2]

ElementStorage & tachyon::ElementStorage::operator= ( const ElementStorage & )
delete

◆ BeginConstruction()

ElementStorageResult tachyon::ElementStorage::BeginConstruction ( )
inlinenodiscard

Starts building a new tree, clearing the previous one.

DuplicateCall if already constructing.

◆ EndConstruction()

ElementStorageResult tachyon::ElementStorage::EndConstruction ( )
inlinenodiscard

Finishes the tree; NotConstructing if not constructing.

An unmatched BeginChildren is closed here, so the frame still completes, and reported as MissingEndChildren.

◆ Add()

AddResult tachyon::ElementStorage::Add ( Element && element,
LayoutOverride && constraints = {} )
nodiscard

Adds element after the previous one at the current nesting level.

constraints are resolved from CSS px to pixels here. Fails outside construction or with an invalid style.

◆ AddCustomDraw()

ElementStorageResult tachyon::ElementStorage::AddCustomDraw ( const ElementRef & ref,
CustomDrawCallback callback )
nodiscard

Draws callback before ref's children render.

Coords are inner-rect-local LAYOUT pixels in ref's content space (they pan/zoom with its contentTransform).

◆ AddCustomDrawAfter()

ElementStorageResult tachyon::ElementStorage::AddCustomDrawAfter ( const ElementRef & ref,
CustomDrawCallback callback )
nodiscard

Draws callback after ref's whole subtree, in the same space as AddCustomDraw.

Call after ref's EndChildren().

◆ AddPostLayout()

ElementStorageResult tachyon::ElementStorage::AddPostLayout ( const ElementRef & ref,
PostLayoutCallback callback )
nodiscard

Runs callback after layout, before rendering, with read-only final geometry.

◆ BeginChildren()

ElementStorageResult tachyon::ElementStorage::BeginChildren ( )
nodiscard

Begins adding children to the last added element; elements without BeginChildren are leaves.

MissingAdd when no element is open for children (none added, or just closed); DuplicateCall when called twice for one element.

◆ EndChildren()

ElementStorageResult tachyon::ElementStorage::EndChildren ( )
nodiscard

Closes the innermost BeginChildren. Fails outside construction or without one open.

◆ MoveChild()

ElementStorageResult tachyon::ElementStorage::MoveChild ( uint32_t childDepth,
uint32_t rangeBegin,
uint32_t fromLocal,
uint32_t toLocal,
ElementMove * outMove = nullptr )
nodiscard

Moves a child (with its subtree) to another sibling position, during construction.

fromLocal / toLocal are relative to rangeBegin, the absolute index of the first child at childDepth. Refs inside the storage follow; outMove lets other holders remap theirs.

◆ Empty()

bool tachyon::ElementStorage::Empty ( ) const
inline

◆ ElementCount()

uint32_t tachyon::ElementStorage::ElementCount ( ) const
inline

◆ GetLastAddedID()

ID tachyon::ElementStorage::GetLastAddedID ( ) const
inline

◆ GetLastItemID()

ID tachyon::ElementStorage::GetLastItemID ( ) const
inline

The element last added at the level being built, its children done: after a control with parts, the control's outer element rather than its last part.

A window (a popup the control opened) and what's in it don't count.

◆ GetLastAddedRef()

ElementRef tachyon::ElementStorage::GetLastAddedRef ( ) const
inline

◆ GetCurrentNestingDepth()

uint32_t tachyon::ElementStorage::GetCurrentNestingDepth ( ) const
inline

◆ NumberOfDepthLevels()

uint32_t tachyon::ElementStorage::NumberOfDepthLevels ( ) const
inline

◆ DepthSizeOf()

uint32_t tachyon::ElementStorage::DepthSizeOf ( uint32_t depth) const
inline

◆ GetElementIDAt()

const ID tachyon::ElementStorage::GetElementIDAt ( ElementRef root,
int2 position,
ID * disabledHit = nullptr ) const

The element at position that takes input, or Invalid.

A disabled element there takes the hit (Invalid); disabledHit, when given, gets the deepest element under position inside it, which shows its tooltip though it takes no input.

◆ ScreenToElementSpace()

int2 tachyon::ElementStorage::ScreenToElementSpace ( int2 screenPos,
ElementRef ref ) const

Converts a screen point into the space ref's own rect is stored in, applying each ancestor's inverse contentTransform like hit-testing does.

Use it to compare event.state.screenPos with an element's rect under transformed ancestors.

◆ ElementRectOnScreen()

IntRect tachyon::ElementStorage::ElementRectOnScreen ( ElementRef ref) const

ref's border box on the screen: through its ancestors' contentTransforms (a canvas's pan and zoom), the box around it when it's turned.

◆ FindElementRefByID()

ElementRef tachyon::ElementStorage::FindElementRefByID ( ID id) const

The element with id; Invalid when not found (always for ID::Invalid).

O(1). If an ID is used twice, the shallowest, earliest element wins.

◆ IsValidRef()

bool tachyon::ElementStorage::IsValidRef ( const ElementRef & ref) const
inline

◆ GetFirstElementRef()

ElementRef tachyon::ElementStorage::GetFirstElementRef ( ) const
inline

◆ HasChildren()

bool tachyon::ElementStorage::HasChildren ( const ElementRef & ref) const
inline

◆ GetChildCount()

uint32_t tachyon::ElementStorage::GetChildCount ( const ElementRef & ref) const
inline

◆ GetParentRef()

ElementRef tachyon::ElementStorage::GetParentRef ( const ElementRef & ref) const
inline

◆ GetNextSiblingRef()

ElementRef tachyon::ElementStorage::GetNextSiblingRef ( const ElementRef & ref) const
inline

◆ GetElementPtr() [1/2]

Element * tachyon::ElementStorage::GetElementPtr ( const ElementRef & elementRef)
inline

The element, or nullptr for an invalid ref.

◆ GetElementPtr() [2/2]

const Element * tachyon::ElementStorage::GetElementPtr ( const ElementRef & elementRef) const
inline

◆ GetElementUnsafe() [1/2]

Element & tachyon::ElementStorage::GetElementUnsafe ( const ElementRef & elementRef)
inline

◆ GetElementUnsafe() [2/2]

const Element & tachyon::ElementStorage::GetElementUnsafe ( const ElementRef & elementRef) const
inline

◆ GetElementRectPtr() [1/2]

ElementRect * tachyon::ElementStorage::GetElementRectPtr ( const ElementRef & elementRef)
inline

◆ GetElementRectPtr() [2/2]

const ElementRect * tachyon::ElementStorage::GetElementRectPtr ( const ElementRef & elementRef) const
inline

◆ GetElementRectUnsafe() [1/2]

ElementRect & tachyon::ElementStorage::GetElementRectUnsafe ( const ElementRef & elementRef)
inline

◆ GetElementRectUnsafe() [2/2]

const ElementRect & tachyon::ElementStorage::GetElementRectUnsafe ( const ElementRef & elementRef) const
inline

◆ SetContentTransform()

bool tachyon::ElementStorage::SetContentTransform ( const ElementRef & ref,
const float3x2 & transform )
inline

Sets the transform applied to ref's children at render / hit-test time (pan, zoom).

Call after Add() and before layout. False for an invalid ref.

◆ GetCustomDraw()

const ElementCustomDraw * tachyon::ElementStorage::GetCustomDraw ( const ElementRef & elementRef) const
inline

◆ GetPostLayoutEntries()

const std::vector< PostLayoutEntry > & tachyon::ElementStorage::GetPostLayoutEntries ( ) const
inline

◆ GetElementCustomDrawUnsafe()

ElementCustomDraw & tachyon::ElementStorage::GetElementCustomDrawUnsafe ( const ElementRef & elementRef)
inline

◆ GetPostDrawEntryUnsafe()

PostDrawEntry & tachyon::ElementStorage::GetPostDrawEntryUnsafe ( uint32_t index)
inline

◆ GetChildrenSpan() [1/2]

std::span< Element > tachyon::ElementStorage::GetChildrenSpan ( const ElementRef & parentRef)
inline

Valid until the next BeginConstruction. Empty on invalid ref or no children.

◆ GetChildrenSpanUnsafe() [1/2]

std::span< Element > tachyon::ElementStorage::GetChildrenSpanUnsafe ( int depth,
const IndexRange range )
inline

Unchecked. Valid until the next BeginConstruction.

◆ GetChildrenSpanUnsafe() [2/2]

std::span< const Element > tachyon::ElementStorage::GetChildrenSpanUnsafe ( int depth,
const IndexRange range ) const
inline

Unchecked. Valid until the next BeginConstruction.

◆ GetChildRectSpanUnsafe() [1/2]

std::span< ElementRect > tachyon::ElementStorage::GetChildRectSpanUnsafe ( int depth,
const IndexRange range )
inline

◆ GetChildRectSpanUnsafe() [2/2]

std::span< const ElementRect > tachyon::ElementStorage::GetChildRectSpanUnsafe ( int depth,
const IndexRange range ) const
inline

◆ GetChildrenSpan() [2/2]

std::span< const Element > tachyon::ElementStorage::GetChildrenSpan ( const ElementRef & parentRef) const
inline

Valid until the next BeginConstruction. Empty on invalid ref or no children.

◆ GetChildRange()

IndexRange tachyon::ElementStorage::GetChildRange ( const ElementRef & parentRef) const
inline

The indices of parentRef's children at the next depth; empty on invalid ref or no children.

◆ TopDownDepthScanBegin()

TopDownDepthScanIterator tachyon::ElementStorage::TopDownDepthScanBegin ( ) const
inline

◆ TopDownDepthScanEnd()

TopDownDepthScanIterator tachyon::ElementStorage::TopDownDepthScanEnd ( ) const
inline

◆ BottomUpDepthScanBegin()

BottomUpDepthScanIterator tachyon::ElementStorage::BottomUpDepthScanBegin ( ) const
inline

◆ BottomUpDepthScanEnd()

BottomUpDepthScanIterator tachyon::ElementStorage::BottomUpDepthScanEnd ( ) const
inline

◆ TopDownDepthScanRange()

TopDownDepthScanRangeIterator tachyon::ElementStorage::TopDownDepthScanRange ( ) const
inline

◆ BottomUpDepthScanRange()

BottomUpDepthScanRangeIterator tachyon::ElementStorage::BottomUpDepthScanRange ( ) const
inline

◆ TopDownDepthScanIterator

friend struct TopDownDepthScanIterator
friend

◆ BottomUpDepthScanIterator

friend struct BottomUpDepthScanIterator
friend

The documentation for this class was generated from the following file: