TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_widget_state_types.h
Go to the documentation of this file.
1#pragma once
2
3#include <gui_core/gui_base_types.h> // SteadyClockNowNanos, int2
4#include <gui_core/gui_id.h>
5#include <gui_core/input/gui_input_enums.h> // DoubleClickMilliseconds
6#include <gui_core/state/gui_drag_drop_state.h> // DragVisualizer
7
8#include <functional>
9#include <string>
10#include <unordered_set>
11#include <vector>
12
13// Widget-state types shared by several control families (node view, table, tree/grid).
14
15namespace tachyon
16{
19
20 // ---- Multi-selection state (user-owned) ----
23 std::unordered_set<tachyon::ID> selectedIDs;
26 std::vector<tachyon::ID> orderedItemIDs;
27 };
28
29 // ---- Command search (user-owned; see GUIApplication::CommandSearch) ----
32 std::string query;
33 std::string hint = "Search or run a command";
35 std::string shortcut;
36 int current = 0;
37 bool focusRequested = false;
38 bool ranCommand = false;
42 };
43
44 // ---- Drop position for tree reorder drops ----
46 enum class TreeDropPosition : uint8_t {
47 None = 0,
52 };
53
54 // ---- Drag & drop config for item-based views (tree, list, grid) ----
58 uint32_t payloadType = 0;
60 std::function<uintptr_t(tachyon::ID)> getPayload;
63 std::function<bool(uintptr_t payload, tachyon::ID targetID)> canDrop;
66 std::function<void(uintptr_t, tachyon::ID)> onDrop;
68 std::function<void(uintptr_t srcPayload, tachyon::ID targetID,
71 bool dropInsideOnly = false;
73 };
74
77 {
79 int64_t lastTimeNanos = 0;
80
82 struct Result { bool sameAsPrevious; float elapsedMs; };
83
86 {
87 const int64_t now = SteadyClockNowNanos();
88 Result r{
89 .sameAsPrevious = (lastID == id),
90 .elapsedMs = static_cast<float>(now - lastTimeNanos) / 1'000'000.0f,
91 };
92 lastID = id;
93 lastTimeNanos = now;
94 return r;
95 }
96
101 {
102 const Result r = Update(id);
104 return false;
105 Reset();
106 return true;
107 }
108
111 };
112
113}
TreeDropPosition
Where a tree reorder drop lands relative to the target row.
Definition gui_widget_state_types.h:46
@ InsideLast
last child of the target (rectangle around the row)
Definition gui_widget_state_types.h:50
@ After
next sibling of the target (line at the row bottom)
Definition gui_widget_state_types.h:51
@ Inside
first child of an open target branch (indented line at the row bottom)
Definition gui_widget_state_types.h:49
std::function< void(const DragVisualContext &context)> DragVisualizer
Draws the dragged item while a drag is in progress.
Definition gui_drag_drop_state.h:62
@ None
Definition gui_element_flags.h:18
float DoubleClickMilliseconds() noexcept
The most time between the two clicks of a double-click, milliseconds: the OS's setting,...
@ Before
Force a line break before this element (CSS: left).
Definition gui_style.h:471
int64_t SteadyClockNowNanos()
Monotonic steady_clock time in nanoseconds; a plain int64_t keeps <chrono> out of widely-included hea...
Definition gui_logging.h:24
State of a CommandSearch box; user-owned, keep it alive across frames.
Definition gui_widget_state_types.h:31
tachyon::ID listWindowID
Internal: the results popup's window, made the first time it's shown.
Definition gui_widget_state_types.h:41
std::string shortcut
Keycap at the right, e.g. the key that focuses the search.
Definition gui_widget_state_types.h:35
int current
highlighted match, moved by Up / Down
Definition gui_widget_state_types.h:36
std::string hint
shown while the query is empty
Definition gui_widget_state_types.h:33
bool focusRequested
set by FocusCommandSearch, taken next frame
Definition gui_widget_state_types.h:37
std::string query
the typed text
Definition gui_widget_state_types.h:32
bool ranCommand
a command ran since the last CommandSearch call
Definition gui_widget_state_types.h:38
Whether this click hit the same item as the previous one, and the time since it.
Definition gui_widget_state_types.h:82
bool sameAsPrevious
Definition gui_widget_state_types.h:82
float elapsedMs
Definition gui_widget_state_types.h:82
Click-gesture tracker, owned per widget instance so instances (and tests) don't share it.
Definition gui_widget_state_types.h:77
int64_t lastTimeNanos
steady-clock ns; see SteadyClockNowNanos()
Definition gui_widget_state_types.h:79
void Reset()
Forgets the previous click, so the next one never counts as a repeat.
Definition gui_widget_state_types.h:110
bool IsDoubleClick(tachyon::ID id)
Records a click on id: true when it is the second click of a double-click (the same item,...
Definition gui_widget_state_types.h:100
Result Update(tachyon::ID id)
Records a click on id and compares it with the previous click.
Definition gui_widget_state_types.h:85
tachyon::ID lastID
item of the previous click
Definition gui_widget_state_types.h:78
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
Drag & drop setup for item-based views (tree, list, grid): items drag a payload and accept drops of t...
Definition gui_widget_state_types.h:57
bool dropInsideOnly
Every drop on a row means InsideLast (folder-style targets, no sibling reordering).
Definition gui_widget_state_types.h:71
std::function< uintptr_t(tachyon::ID)> getPayload
What to drag: the payload value for an item ID.
Definition gui_widget_state_types.h:60
uint32_t payloadType
0 = disabled
Definition gui_widget_state_types.h:58
tachyon::DragVisualizer visualizer
optional visual feedback
Definition gui_widget_state_types.h:72
std::function< bool(uintptr_t payload, tachyon::ID targetID)> canDrop
Optional: returning false refuses the payload at that target (e.g.
Definition gui_widget_state_types.h:63
std::function< void(uintptr_t, tachyon::ID)> onDrop
Called with the dropped payload and the target ID (in a grid, the view's ID for a drop on the backgro...
Definition gui_widget_state_types.h:66
std::function< void(uintptr_t srcPayload, tachyon::ID targetID, TreeDropPosition pos)> onReorder
Tree reorder; when set, rows become drop targets with sibling and child zones.
Definition gui_widget_state_types.h:69
Selected item IDs of a multi-select view; user-owned, keep it alive across frames.
Definition gui_widget_state_types.h:22
std::unordered_set< tachyon::ID > selectedIDs
Definition gui_widget_state_types.h:23
std::vector< tachyon::ID > orderedItemIDs
Transient: rebuilt each frame for Shift+Click range selection.
Definition gui_widget_state_types.h:26
tachyon::ID lastClickedID
anchor for Shift+Click ranges
Definition gui_widget_state_types.h:24