Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
imgui_helpers.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6#include <Utility/TSpan.h>
7#include <Math/TVector2.h>
8#include <Math/TVector4.h>
9
10#include <cstddef>
11#include <string_view>
12#include <vector>
13
14namespace ph::editor::imgui
15{
16
17void text_unformatted(std::string_view text);
18
20 ImTextureID textureID,
21 const math::Vector2F& sizePx,
22 const math::Vector4F& tintColorRGBA = math::Vector4F(1, 1, 1, 1),
23 const math::Vector4F& borderColorRGBA = math::Vector4F(0, 0, 0, 0));
24
26 const char* strId,
27 ImTextureID textureID,
28 const math::Vector2F& sizePx,
29 const math::Vector4F& backgroundColorRGBA = math::Vector4F(0, 0, 0, 0),
30 const math::Vector4F& tintColorRGBA = math::Vector4F(1, 1, 1, 1));
31
35void copy_to(TSpan<char> dstBuffer, std::string_view srcStr);
36
37class StringCache final
38{
39public:
41 explicit StringCache(std::size_t cacheSize);
42
46 void fixedCopy(TSpanView<char> inputContent);
47
50 void resizableCopy(TSpanView<char> inputContent);
51
52 bool inputText(
53 const char* idName,
54 ImGuiInputTextFlags flags = 0);
55
56 bool inputText(
57 const char* idName,
58 TSpanView<char> inputContent,
59 ImGuiInputTextFlags flags = 0);
60
63 void clear();
64
69 TSpan<char> getData();
70 TSpanView<char> getData() const;
72
76 char* getContent();
77 const char* getContent() const;
79
84 bool isEmpty() const;
85
86
87
88private:
89 std::vector<char> m_cache;
90};
91
92inline void StringCache::clear()
93{
94 PH_ASSERT(!m_cache.empty());
95 m_cache.front() = '\0';
96}
97
98inline TSpan<char> StringCache::getData()
99{
100 return m_cache;
101}
102
103inline TSpanView<char> StringCache::getData() const
104{
105 return m_cache;
106}
107
109{
110 return m_cache.data();
111}
112
113inline const char* StringCache::getContent() const
114{
115 return m_cache.data();
116}
117
118inline bool StringCache::isEmpty() const
119{
120 return !m_cache.empty() && m_cache.front() != '\0';
121}
122
123}// end ph::editor::imgui
std::string text
Definition ImguiEditorLog.cpp:23
Definition imgui_helpers.h:38
void clear()
Make the cache empty.
Definition imgui_helpers.h:92
bool inputText(const char *idName, ImGuiInputTextFlags flags=0)
Definition imgui_helpers.cpp:103
void resizableCopy(TSpanView< char > inputContent)
Fully copy inputContent into cache. Resize the cache if needed.
Definition imgui_helpers.cpp:92
void fixedCopy(TSpanView< char > inputContent)
Copy inputContent into cache without changing the cache's size. The resulting content may get truncat...
Definition imgui_helpers.cpp:87
TSpan< char > getData()
Get cached data. The resulting span is over the full cache and multiple null terminators may present.
Definition imgui_helpers.h:98
StringCache()
Definition imgui_helpers.cpp:79
char * getContent()
Get the string in cache. The result should always be null terminated.
Definition imgui_helpers.h:108
bool isEmpty() const
Definition imgui_helpers.h:118
Definition imgui_helpers.cpp:7
void text_unformatted(std::string_view text)
Definition imgui_helpers.cpp:9
bool image_button_with_fallback(const char *strId, ImTextureID textureID, const math::Vector2F &sizePx, const math::Vector4F &backgroundColorRGBA, const math::Vector4F &tintColorRGBA)
Definition imgui_helpers.cpp:36
void copy_to(TSpan< char > dstBuffer, std::string_view srcStr)
Copy string to a buffer. The result is always null-terminated.
Definition imgui_helpers.cpp:60
void image_with_fallback(ImTextureID textureID, const math::Vector2F &sizePx, const math::Vector4F &tintColorRGBA, const math::Vector4F &borderColorRGBA)
Definition imgui_helpers.cpp:14