TachyonUI 0.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;
40 };
41
42 // ---- Drop position for tree reorder drops ----
44 enum class TreeDropPosition : uint8_t {
45 None = 0,
50 };
51
52 // ---- Drag & drop config for item-based views (tree, list, grid) ----
56 uint32_t payloadType = 0;
58 std::function<uintptr_t(tachyon::ID)> getPayload;
61 std::function<bool(uintptr_t payload, tachyon::ID targetID)> canDrop;
64 std::function<void(uintptr_t, tachyon::ID)> onDrop;
66 std::function<void(uintptr_t srcPayload, tachyon::ID targetID,
69 bool dropInsideOnly = false;
71 };
72
75 {
77 int64_t lastTimeNanos = 0;
78
80 struct Result { bool sameAsPrevious; float elapsedMs; };
81
84 {
85 const int64_t now = SteadyClockNowNanos();
86 Result r{
87 .sameAsPrevious = (lastID == id),
88 .elapsedMs = static_cast<float>(now - lastTimeNanos) / 1'000'000.0f,
89 };
90 lastID = id;
91 lastTimeNanos = now;
92 return r;
93 }
94
99 {
100 const Result r = Update(id);
102 return false;
103 Reset();
104 return true;
105 }
106
109 };
110
111}
TreeDropPosition
Where a tree reorder drop lands relative to the target row.
Definition gui_widget_state_types.h:44
@ InsideLast
last child of the target (rectangle around the row)
Definition gui_widget_state_types.h:48
@ After
next sibling of the target (line at the row bottom)
Definition gui_widget_state_types.h:49
@ Inside
first child of an open target branch (indented line at the row bottom)
Definition gui_widget_state_types.h:47
std::function< void(const DragVisualContext &context)> DragVisualizer
Draws the dragged item while a drag is in progress.
Definition gui_drag_drop_state.h:33
@ None
Definition gui_element_flags.h:19
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:468
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
Definition gui_widget_state_types.h:39
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:80
bool sameAsPrevious
Definition gui_widget_state_types.h:80
float elapsedMs
Definition gui_widget_state_types.h:80
Click-gesture tracker, owned per widget instance so instances (and tests) don't share it.
Definition gui_widget_state_types.h:75
int64_t lastTimeNanos
steady-clock ns; see SteadyClockNowNanos()
Definition gui_widget_state_types.h:77
void Reset()
Forgets the previous click, so the next one never counts as a repeat.
Definition gui_widget_state_types.h:108
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:98
Result Update(tachyon::ID id)
Records a click on id and compares it with the previous click.
Definition gui_widget_state_types.h:83
tachyon::ID lastID
item of the previous click
Definition gui_widget_state_types.h:76
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:55
bool dropInsideOnly
Every drop on a row means InsideLast (folder-style targets, no sibling reordering).
Definition gui_widget_state_types.h:69
std::function< uintptr_t(tachyon::ID)> getPayload
What to drag: the payload value for an item ID.
Definition gui_widget_state_types.h:58
uint32_t payloadType
0 = disabled
Definition gui_widget_state_types.h:56
tachyon::DragVisualizer visualizer
optional visual feedback
Definition gui_widget_state_types.h:70
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:61
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:64
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:67
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