TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_element_iterators.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <iterator>
6#include <span>
7
8namespace tachyon
9{
12
13 class ElementStorage;
14
15 // ------------------------------------------------------------------------
16 // Depth-Scan Cursor
17 // ------------------------------------------------------------------------
18
20 {
21 uint32_t parentDepth = 0;
22 uint32_t parentIndex = 0;
23 uint32_t parentCountAtDepth = 0;
24
27
28 inline bool IsDone() const { return *this == EndCursor(); }
29 inline bool HasChildren() const { return !childRange.Empty(); }
31
32 const Element& CurrentElement(const ElementStorage &storage) const;
34 const ElementRect& CurrentElementRect(const ElementStorage &storage) const;
36 std::span<const Element> GetChildren(const ElementStorage& storage) const;
37 std::span<Element> GetChildren(ElementStorage &storage) const;
38 std::span<const ElementRect> GetChildRects(const ElementStorage& storage) const;
39 std::span<ElementRect> GetChildRects(ElementStorage &storage) const;
40
41 inline bool operator==(const DepthScanCursor& rhs) const
42 {
43 return parentDepth == rhs.parentDepth &&
44 parentIndex == rhs.parentIndex &&
46 }
47 inline bool operator!=(const DepthScanCursor& rhs) const { return !(*this == rhs); }
48
49 static constexpr DepthScanCursor EndCursor() { return {}; }
50 inline void SetDone() { *this = EndCursor(); }
51 };
52
53 #define TACHYON_ITERATOR_TRAITS_USING_DECLS(type) \
54 using value_type = type; \
55 using difference_type = std::ptrdiff_t; \
56 using reference = const value_type&; \
57 using pointer = const value_type*;
58
59 // ------------------------------------------------------------------------
60 // Top-down depth-scan iterator: depth 0 to deepest, parents in index order.
61 // Storage must not change during iteration.
62 // ------------------------------------------------------------------------
64 {
66 uint64_t generation = 0;
68
70 using iterator_category = std::input_iterator_tag;
71
72 inline bool Validate() const;
73
74 inline const DepthScanCursor& operator*() const { return cursor; }
75 inline const DepthScanCursor* operator->() const { return &cursor; }
76
77 inline bool operator==(const TopDownDepthScanIterator& rhs) const { return &storage == &rhs.storage && generation == rhs.generation && cursor == rhs.cursor; }
78 inline bool operator!=(const TopDownDepthScanIterator& rhs) const { return !(*this == rhs); }
79
82 };
83
84 // ------------------------------------------------------------------------
85 // Bottom-up depth-scan iterator: deepest depth to 0, parents in index order.
86 // Storage must not change during iteration.
87 // ------------------------------------------------------------------------
89 {
91 uint64_t generation = 0;
93
95 using iterator_category = std::input_iterator_tag;
96
97 inline bool Validate() const;
98
99 inline const DepthScanCursor& operator*() const { return cursor; }
100 inline const DepthScanCursor* operator->() const { return &cursor; }
101
102 inline bool operator==(const BottomUpDepthScanIterator& rhs) const { return &storage == &rhs.storage && generation == rhs.generation && cursor == rhs.cursor; }
103 inline bool operator!=(const BottomUpDepthScanIterator& rhs) const { return !(*this == rhs); }
104
107 };
108
109 #undef TACHYON_ITERATOR_TRAITS_USING_DECLS
110
111 // ------------------------------------------------------------------------
112 // Range Wrappers - Enable idiomatic for-each loops
113 // ------------------------------------------------------------------------
114
115 template<typename Iterator>
116 class Range
117 {
118 public:
119 Range(Iterator begin, Iterator end) : m_begin(begin), m_end(end) {}
120
121 Iterator begin() const { return m_begin; }
122 Iterator end() const { return m_end; }
123
124 bool empty() const { return m_begin == m_end; }
125
126 private:
127 Iterator m_begin;
128 Iterator m_end;
129 };
130
133
135} // namespace tachyon
The frame's element tree.
Definition gui_element_storage.h:100
Definition gui_element_iterators.h:117
TopDownDepthScanIterator begin() const
Definition gui_element_iterators.h:121
Range(Iterator begin, Iterator end)
Definition gui_element_iterators.h:119
TopDownDepthScanIterator end() const
Definition gui_element_iterators.h:122
bool empty() const
Definition gui_element_iterators.h:124
Range< BottomUpDepthScanIterator > BottomUpDepthScanRangeIterator
Definition gui_element_iterators.h:132
TopDownDepthScanIterator & operator++()
Definition gui_element_storage.h:509
Range< TopDownDepthScanIterator > TopDownDepthScanRangeIterator
Definition gui_element_iterators.h:131
bool Validate() const
Definition gui_element_storage.h:506
BottomUpDepthScanIterator & operator++()
Definition gui_element_storage.h:512
bool Validate() const
Definition gui_element_storage.h:507
Definition gui_logging.h:24
Definition gui_element_iterators.h:89
const ElementStorage & storage
Definition gui_element_iterators.h:90
const DepthScanCursor & operator*() const
Definition gui_element_iterators.h:99
std::input_iterator_tag iterator_category
Definition gui_element_iterators.h:95
bool operator==(const BottomUpDepthScanIterator &rhs) const
Definition gui_element_iterators.h:102
bool operator!=(const BottomUpDepthScanIterator &rhs) const
Definition gui_element_iterators.h:103
const DepthScanCursor * operator->() const
Definition gui_element_iterators.h:100
DepthScanCursor cursor
Definition gui_element_iterators.h:92
TACHYON_ITERATOR_TRAITS_USING_DECLS(DepthScanCursor)
uint64_t generation
Definition gui_element_iterators.h:91
Definition gui_element_iterators.h:20
uint32_t parentDepth
Definition gui_element_iterators.h:21
static constexpr DepthScanCursor EndCursor()
Definition gui_element_iterators.h:49
Element & CurrentElement(ElementStorage &storage) const
std::span< const ElementRect > GetChildRects(const ElementStorage &storage) const
uint32_t parentCountAtDepth
Definition gui_element_iterators.h:23
ElementRect & CurrentElementRect(ElementStorage &storage) const
bool HasChildren() const
Definition gui_element_iterators.h:29
bool operator==(const DepthScanCursor &rhs) const
Definition gui_element_iterators.h:41
IndexRange childRange
This parent's children at parentDepth + 1.
Definition gui_element_iterators.h:26
std::span< const Element > GetChildren(const ElementStorage &storage) const
bool IsDone() const
Definition gui_element_iterators.h:28
bool operator!=(const DepthScanCursor &rhs) const
Definition gui_element_iterators.h:47
void SetDone()
Definition gui_element_iterators.h:50
uint32_t parentIndex
Definition gui_element_iterators.h:22
std::span< ElementRect > GetChildRects(ElementStorage &storage) const
const Element & CurrentElement(const ElementStorage &storage) const
std::span< Element > GetChildren(ElementStorage &storage) const
const ElementRect & CurrentElementRect(const ElementStorage &storage) const
ElementRef CurrentRef() const
Definition gui_element_iterators.h:30
Definition gui_element.h:57
An element's slot in ElementStorage: its depth and index within that depth.
Definition gui_element.h:127
Definition gui_element.h:33
A half-open range [begin, end) of indices within one depth.
Definition gui_element.h:148
bool Empty() const
Definition gui_element.h:152
Definition gui_element_iterators.h:64
TACHYON_ITERATOR_TRAITS_USING_DECLS(DepthScanCursor)
const DepthScanCursor * operator->() const
Definition gui_element_iterators.h:75
const ElementStorage & storage
Definition gui_element_iterators.h:65
DepthScanCursor cursor
Definition gui_element_iterators.h:67
bool operator!=(const TopDownDepthScanIterator &rhs) const
Definition gui_element_iterators.h:78
std::input_iterator_tag iterator_category
Definition gui_element_iterators.h:70
const DepthScanCursor & operator*() const
Definition gui_element_iterators.h:74
bool operator==(const TopDownDepthScanIterator &rhs) const
Definition gui_element_iterators.h:77
uint64_t generation
Definition gui_element_iterators.h:66