TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_scroll_management.h
Go to the documentation of this file.
1#pragma once
2
5#include <gui_core/gui_id.h>
6
7#include <unordered_map>
8#include <vector>
9
10namespace tachyon
11{
14
15 class IDManager;
16 class ElementStorage;
17 struct ElementRef;
18 enum class ScrollOffsetHandle : uint32_t;
19
21 enum class ScrollAxis : uint8_t
22 {
23 None = 0,
24 X = 1 << 0,
25 Y = 1 << 1,
26 Both = X | Y,
27 };
29
30
33 {
34 struct ScrollOffsetEntry
35 {
36 ID id = ID::Invalid();
37 int2 offset = int2{0, 0};
38 uint32_t lastSeenFrame = 0;
39 bool inUse = false;
40 };
41
42 uint32_t m_frameIndex = 0;
43 std::unordered_map<ID, ScrollOffsetHandle> m_scrollOffsetHandlesByID;
44 std::vector<ScrollOffsetEntry> m_scrollOffsets;
45 std::vector<ScrollOffsetHandle> m_scrollOffsetFreeList;
46
47 public:
48 void BeginFrame();
49 void EndFrame(IDManager& idManager);
50
54
57
60 bool MakeRectVisibleInScroll(ScrollOffsetHandle scrollHandle, int2 rectMin, int2 rectMax, int2 containerSize, ScrollAxis axis = ScrollAxis::Both);
62 bool MakeRectVisibleHierarchically(ElementStorage& elementStorage, int2 targetRectMin, int2 targetRectMax, const ElementRef& elementRef, ScrollAxis axis = ScrollAxis::Both);
63 bool MakeRectVisibleHierarchically(ElementStorage& elementStorage, IntRect targetRect, const ElementRef& elementRef, ScrollAxis axis = ScrollAxis::Both)
64 {
65 return MakeRectVisibleHierarchically(elementStorage, targetRect.position, targetRect.position + targetRect.size, elementRef, axis);
66 }
69 bool MakeTextCursorVisibleInTextBox(ElementStorage& elementStorage, const ElementRef& textEditorRef, int2 cursorPos, int cursorHeight = 1);
70 };
71
72}
The frame's element tree.
Definition gui_element_storage.h:100
Makes element IDs: per-frame dynamic / ranged IDs (hashed from the call site or a hint and the parent...
Definition gui_id_manager.h:27
Scroll containers' offsets (pixels), kept across frames by ID behind handles.
Definition gui_scroll_management.h:33
void SetScrollOffset(ScrollOffsetHandle handle, int2 offset)
ScrollOffsetHandle GetOrCreateScrollOffsetHandle(ID id)
void EndFrame(IDManager &idManager)
bool MakeTextCursorVisibleInTextBox(ElementStorage &elementStorage, const ElementRef &textEditorRef, int2 cursorPos, int cursorHeight=1)
Scrolls a text editor to show its cursor; cursorPos is in the editor's content space.
bool MakeRectVisibleHierarchically(ElementStorage &elementStorage, int2 targetRectMin, int2 targetRectMax, const ElementRef &elementRef, ScrollAxis axis=ScrollAxis::Both)
Scrolls elementRef's scroll ancestors to show the target rect (screen space).
bool MakeElementVisibleHierarchically(ElementStorage &elementStorage, const ElementRef &elementRef, ScrollAxis axis=ScrollAxis::Both)
int2 GetScrollOffset(ScrollOffsetHandle handle)
bool IsScrollOffsetHandleValid(ScrollOffsetHandle handle) const
bool MakeRectVisibleHierarchically(ElementStorage &elementStorage, IntRect targetRect, const ElementRef &elementRef, ScrollAxis axis=ScrollAxis::Both)
Definition gui_scroll_management.h:63
bool MakeRectVisibleInScroll(ScrollOffsetHandle scrollHandle, int2 rectMin, int2 rectMax, int2 containerSize, ScrollAxis axis=ScrollAxis::Both)
Scrolls just enough to show rectMin..rectMax (content space) in a container of containerSize; true wh...
ScrollOffsetHandle GetScrollOffsetHandle(ID id)
ScrollOffsetHandle
A handle to a stored scroll offset.
Definition gui_element_storage.h:35
ScrollAxis
Axis mask for scroll-into-view, so e.g. a horizontal sizer doesn't scroll vertically.
Definition gui_scroll_management.h:22
@ None
Definition gui_element_flags.h:19
@ X
Definition gui_scroll_management.h:24
@ Both
Definition gui_scroll_management.h:26
@ Y
Definition gui_scroll_management.h:25
#define TACHYON_ENUM_OPERATORS(EnumType)
Definition gui_enum_operators.h:6
Definition gui_logging.h:24
An element's slot in ElementStorage: its depth and index within that depth.
Definition gui_element.h:127
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
Definition gui_base_types.h:407
Integer 2D vector.
Definition gui_base_types.h:19