TachyonUI
1.1.0
High-performance UI for building tools.
Toggle main menu visibility
Loading...
Searching...
No Matches
gui_swatch_styles.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
gui_core/gui_id.h
>
4
#include <
gui_core/style/gui_style.h
>
// VisualColorStyleIndex
5
6
#include <unordered_map>
7
8
namespace
tachyon
9
{
12
13
struct
NoSwatchData
{};
14
19
template
<
class
Data = NoSwatchData>
20
class
SwatchStyles
21
{
22
public
:
23
struct
Entry
24
{
25
VisualColorStyleIndex
index
=
VisualColorStyleIndex::Invalid
;
26
uint64_t
claimed
= 0;
27
Data
data
{};
28
};
29
31
Entry&
Claim
(
ID
id
)
32
{
33
Entry& entry = m_entries[id];
34
entry.claimed = m_frame;
35
return
entry;
36
}
37
39
Entry*
Find
(
ID
id
)
40
{
41
const
auto
it = m_entries.find(
id
);
42
return
it != m_entries.end() ? &it->second :
nullptr
;
43
}
44
47
void
KeepAlive
(
ID
id
)
48
{
49
if
(Entry* entry =
Find
(
id
))
50
entry->claimed = m_frame;
51
}
52
54
template
<
class
StyleManagerT>
55
void
NextFrame
(StyleManagerT& styleManager)
56
{
57
std::erase_if(m_entries, [&](
auto
& item) {
58
if
(item.second.claimed == m_frame)
59
return
false
;
60
styleManager.DestroyColorStyle(item.second.index);
61
return
true
;
62
});
63
++m_frame;
64
}
65
67
void
Forget
() { m_entries.clear(); }
68
69
private
:
70
std::unordered_map<ID, Entry> m_entries;
71
uint64_t m_frame = 1;
72
};
73
74
}
tachyon::SwatchStyles
Swatches' color styles, by swatch ID: each kept while it's claimed every frame, and destroyed the fra...
Definition
gui_swatch_styles.h:21
tachyon::SwatchStyles::KeepAlive
void KeepAlive(ID id)
Keeps id's entry this frame without claiming it anew (a cached scope replays its swatches without bui...
Definition
gui_swatch_styles.h:47
tachyon::SwatchStyles::Forget
void Forget()
Drops every entry without destroying its style (a theme reload freed them all).
Definition
gui_swatch_styles.h:67
tachyon::SwatchStyles::Claim
Entry & Claim(ID id)
id's entry, kept this frame: a new one has no style yet.
Definition
gui_swatch_styles.h:31
tachyon::SwatchStyles::Find
Entry * Find(ID id)
id's entry as last claimed, or null.
Definition
gui_swatch_styles.h:39
tachyon::SwatchStyles::NextFrame
void NextFrame(StyleManagerT &styleManager)
At the start of a frame: the styles of the swatches not claimed in the last one go.
Definition
gui_swatch_styles.h:55
tachyon::VisualColorStyleIndex
VisualColorStyleIndex
Index into StyleManager's color style pool; Invalid (0) draws nothing (transparent).
Definition
gui_style.h:33
tachyon::VisualColorStyleIndex::Invalid
@ Invalid
Definition
gui_style.h:33
gui_id.h
gui_style.h
tachyon
Definition
gui_logging.h:24
tachyon::ID
A 64-bit element ID whose bit layout depends on its IDMode.
Definition
gui_id.h:23
tachyon::NoSwatchData
Definition
gui_swatch_styles.h:13
tachyon::SwatchStyles::Entry
Definition
gui_swatch_styles.h:24
tachyon::SwatchStyles::Entry::index
VisualColorStyleIndex index
Invalid until the caller makes it.
Definition
gui_swatch_styles.h:25
tachyon::SwatchStyles::Entry::claimed
uint64_t claimed
the frame it was last claimed in
Definition
gui_swatch_styles.h:26
tachyon::SwatchStyles::Entry::data
Data data
Definition
gui_swatch_styles.h:27
gui_controls
subsystems
gui_swatch_styles.h
Generated by
1.18.0