TachyonUI 1.1.0
High-performance UI for building tools.
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
8namespace tachyon
9{
12
13 struct NoSwatchData {};
14
19 template <class Data = NoSwatchData>
21 {
22 public:
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}
Swatches' color styles, by swatch ID: each kept while it's claimed every frame, and destroyed the fra...
Definition gui_swatch_styles.h:21
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
void Forget()
Drops every entry without destroying its style (a theme reload freed them all).
Definition gui_swatch_styles.h:67
Entry & Claim(ID id)
id's entry, kept this frame: a new one has no style yet.
Definition gui_swatch_styles.h:31
Entry * Find(ID id)
id's entry as last claimed, or null.
Definition gui_swatch_styles.h:39
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
VisualColorStyleIndex
Index into StyleManager's color style pool; Invalid (0) draws nothing (transparent).
Definition gui_style.h:33
@ Invalid
Definition gui_style.h:33
Definition gui_logging.h:24
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
Definition gui_swatch_styles.h:13
Definition gui_swatch_styles.h:24
VisualColorStyleIndex index
Invalid until the caller makes it.
Definition gui_swatch_styles.h:25
uint64_t claimed
the frame it was last claimed in
Definition gui_swatch_styles.h:26
Data data
Definition gui_swatch_styles.h:27