TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_label_group_subsystem.h
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_map>
4#include <vector>
5
6#include <gui_core/gui_id.h>
10
11namespace tachyon
12{
15
16 class FramePipeline;
17 struct FrameContext;
18 class ElementStorage;
19 class GUIStateManager;
20 class GUITheme;
21
28 {
29 public:
31 struct State
32 {
33 int32_t labelWidth = 120;
34 int32_t defaultWidth = 120;
35 int32_t minWidth = 40;
36 int32_t maxWidth = 500;
37 bool resizable = true;
38 bool edgeHovered = false;
40 bool anyLabelHovered = false;
41 std::vector<tachyon::TextID> labelTextIDs;
43 std::vector<tachyon::ElementRef> labelRefs;
44 uint64_t lastUsedFrame = 0;
45 };
46
48 ElementStorage& elementStorage,
49 GUIStateManager& guiStateManager,
50 GUITheme& theme);
51
54 void BeginGroup(tachyon::ID id, int32_t defaultWidth, int32_t minWidth, int32_t maxWidth, bool resizable = true);
56 void EndGroup();
61
63 bool IsBalanced() const { return m_stack.empty(); }
64
65 private:
66 void OnPreConstruct();
67 void OnPostConstruct();
68 void OnEndFrame();
69
70 struct StackEntry {
71 State* state;
72 uint32_t nestingDepth;
73 };
74
75 std::unordered_map<tachyon::ID, State> m_states;
76 std::vector<StackEntry> m_stack;
77 std::vector<State*> m_used;
78 uint64_t m_frame = 1;
79 static constexpr uint64_t kForgetAfterFrames = 300;
80
81 ElementStorage& m_elementStorage;
82 GUIStateManager& m_guiStateManager;
83 GUITheme& m_theme;
84 };
85
86}
The frame's element tree.
Definition gui_element_storage.h:96
Stage callbacks run in registration order (no priorities): if A must run before B,...
Definition gui_frame_pipeline.h:74
Owns the per-frame state objects and runs their BeginFrame / EndFrame in order.
Definition gui_state_manager.h:65
The library's styles, icons and theme metrics, the defaults the controls draw with.
Definition gui_theme.h:80
State * GetActiveGroup()
The innermost group when it was opened at the current nesting depth, else nullptr.
void EndGroup()
Closes the innermost group.
void AddDragger(tachyon::ElementRef labelRef)
Adds a label to the innermost group and draws its resize edge; a group must be open.
LabelGroupSubsystem(FramePipeline &frame, ElementStorage &elementStorage, GUIStateManager &guiStateManager, GUITheme &theme)
bool IsBalanced() const
True iff every BeginGroup was matched by EndGroup.
Definition gui_label_group_subsystem.h:63
void BeginGroup(tachyon::ID id, int32_t defaultWidth, int32_t minWidth, int32_t maxWidth, bool resizable=true)
Opens group id at the current nesting depth; widths are CSS px, and defaultWidth applies only when th...
Definition gui_logging.h:24
An element's slot in ElementStorage: its depth and index within that depth.
Definition gui_element.h:126
Per-frame values plus references to long-lived managers, passed to every stage callback.
Definition gui_frame_pipeline.h:32
One press that may become a drag, with what every control does around it: the focus and the capture o...
Definition gui_gesture.h:60
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
State of one label group, kept across frames by group ID.
Definition gui_label_group_subsystem.h:32
std::vector< tachyon::TextID > labelTextIDs
transient: rebuilt each frame for auto-size
Definition gui_label_group_subsystem.h:41
int32_t minWidth
CSS px.
Definition gui_label_group_subsystem.h:35
std::vector< tachyon::ElementRef > labelRefs
transient: this frame's labels, in order
Definition gui_label_group_subsystem.h:43
Gesture< int32_t > edgeDrag
a label's resize edge dragged; the width as it was, put back by Escape
Definition gui_label_group_subsystem.h:39
int32_t maxLabelWidthThisFrame
transient: widest label (pixels), for auto-width
Definition gui_label_group_subsystem.h:42
int32_t labelWidth
shared label width, CSS px
Definition gui_label_group_subsystem.h:33
bool resizable
false: the width fits the widest label instead
Definition gui_label_group_subsystem.h:37
int32_t maxWidth
CSS px.
Definition gui_label_group_subsystem.h:36
bool anyLabelHovered
transient: set during construction if any label has hover
Definition gui_label_group_subsystem.h:40
bool edgeHovered
a label's resize edge is hovered
Definition gui_label_group_subsystem.h:38
int32_t defaultWidth
the width it starts at; one still at it has nothing to keep
Definition gui_label_group_subsystem.h:34
uint64_t lastUsedFrame
the frame it was last begun in
Definition gui_label_group_subsystem.h:44