mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-13 18:50:58 +01:00
Prefixed internal structs exposed in imgui.h with a fully qualified name to facilitate auto-generation with cimgui.
This commit is contained in:
parent
3436132d4b
commit
e66799f79a
62
imgui.cpp
62
imgui.cpp
@ -1923,15 +1923,15 @@ ImU32 ImGui::GetColorU32(ImU32 col)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// std::lower_bound but without the bullshit
|
// std::lower_bound but without the bullshit
|
||||||
static ImGuiStorage::Pair* LowerBound(ImVector<ImGuiStorage::Pair>& data, ImGuiID key)
|
static ImGuiStorage::ImGuiStoragePair* LowerBound(ImVector<ImGuiStorage::ImGuiStoragePair>& data, ImGuiID key)
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* first = data.Data;
|
ImGuiStorage::ImGuiStoragePair* first = data.Data;
|
||||||
ImGuiStorage::Pair* last = data.Data + data.Size;
|
ImGuiStorage::ImGuiStoragePair* last = data.Data + data.Size;
|
||||||
size_t count = (size_t)(last - first);
|
size_t count = (size_t)(last - first);
|
||||||
while (count > 0)
|
while (count > 0)
|
||||||
{
|
{
|
||||||
size_t count2 = count >> 1;
|
size_t count2 = count >> 1;
|
||||||
ImGuiStorage::Pair* mid = first + count2;
|
ImGuiStorage::ImGuiStoragePair* mid = first + count2;
|
||||||
if (mid->key < key)
|
if (mid->key < key)
|
||||||
{
|
{
|
||||||
first = ++mid;
|
first = ++mid;
|
||||||
@ -1953,18 +1953,18 @@ void ImGuiStorage::BuildSortByKey()
|
|||||||
static int IMGUI_CDECL PairCompareByID(const void* lhs, const void* rhs)
|
static int IMGUI_CDECL PairCompareByID(const void* lhs, const void* rhs)
|
||||||
{
|
{
|
||||||
// We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that.
|
// We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that.
|
||||||
if (((const Pair*)lhs)->key > ((const Pair*)rhs)->key) return +1;
|
if (((const ImGuiStoragePair*)lhs)->key > ((const ImGuiStoragePair*)rhs)->key) return +1;
|
||||||
if (((const Pair*)lhs)->key < ((const Pair*)rhs)->key) return -1;
|
if (((const ImGuiStoragePair*)lhs)->key < ((const ImGuiStoragePair*)rhs)->key) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (Data.Size > 1)
|
if (Data.Size > 1)
|
||||||
ImQsort(Data.Data, (size_t)Data.Size, sizeof(Pair), StaticFunc::PairCompareByID);
|
ImQsort(Data.Data, (size_t)Data.Size, sizeof(ImGuiStoragePair), StaticFunc::PairCompareByID);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ImGuiStorage::GetInt(ImGuiID key, int default_val) const
|
int ImGuiStorage::GetInt(ImGuiID key, int default_val) const
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
|
ImGuiStoragePair* it = LowerBound(const_cast<ImVector<ImGuiStoragePair>&>(Data), key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
return default_val;
|
return default_val;
|
||||||
return it->val_i;
|
return it->val_i;
|
||||||
@ -1977,7 +1977,7 @@ bool ImGuiStorage::GetBool(ImGuiID key, bool default_val) const
|
|||||||
|
|
||||||
float ImGuiStorage::GetFloat(ImGuiID key, float default_val) const
|
float ImGuiStorage::GetFloat(ImGuiID key, float default_val) const
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
|
ImGuiStoragePair* it = LowerBound(const_cast<ImVector<ImGuiStoragePair>&>(Data), key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
return default_val;
|
return default_val;
|
||||||
return it->val_f;
|
return it->val_f;
|
||||||
@ -1985,7 +1985,7 @@ float ImGuiStorage::GetFloat(ImGuiID key, float default_val) const
|
|||||||
|
|
||||||
void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
|
void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
|
ImGuiStoragePair* it = LowerBound(const_cast<ImVector<ImGuiStoragePair>&>(Data), key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
return NULL;
|
return NULL;
|
||||||
return it->val_p;
|
return it->val_p;
|
||||||
@ -1994,9 +1994,9 @@ void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
|
|||||||
// References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer.
|
// References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer.
|
||||||
int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val)
|
int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val)
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(Data, key);
|
ImGuiStoragePair* it = LowerBound(Data, key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
it = Data.insert(it, Pair(key, default_val));
|
it = Data.insert(it, ImGuiStoragePair(key, default_val));
|
||||||
return &it->val_i;
|
return &it->val_i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2007,27 +2007,27 @@ bool* ImGuiStorage::GetBoolRef(ImGuiID key, bool default_val)
|
|||||||
|
|
||||||
float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
|
float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(Data, key);
|
ImGuiStoragePair* it = LowerBound(Data, key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
it = Data.insert(it, Pair(key, default_val));
|
it = Data.insert(it, ImGuiStoragePair(key, default_val));
|
||||||
return &it->val_f;
|
return &it->val_f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void** ImGuiStorage::GetVoidPtrRef(ImGuiID key, void* default_val)
|
void** ImGuiStorage::GetVoidPtrRef(ImGuiID key, void* default_val)
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(Data, key);
|
ImGuiStoragePair* it = LowerBound(Data, key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
it = Data.insert(it, Pair(key, default_val));
|
it = Data.insert(it, ImGuiStoragePair(key, default_val));
|
||||||
return &it->val_p;
|
return &it->val_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME-OPT: Need a way to reuse the result of lower_bound when doing GetInt()/SetInt() - not too bad because it only happens on explicit interaction (maximum one a frame)
|
// FIXME-OPT: Need a way to reuse the result of lower_bound when doing GetInt()/SetInt() - not too bad because it only happens on explicit interaction (maximum one a frame)
|
||||||
void ImGuiStorage::SetInt(ImGuiID key, int val)
|
void ImGuiStorage::SetInt(ImGuiID key, int val)
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(Data, key);
|
ImGuiStoragePair* it = LowerBound(Data, key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
{
|
{
|
||||||
Data.insert(it, Pair(key, val));
|
Data.insert(it, ImGuiStoragePair(key, val));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it->val_i = val;
|
it->val_i = val;
|
||||||
@ -2040,10 +2040,10 @@ void ImGuiStorage::SetBool(ImGuiID key, bool val)
|
|||||||
|
|
||||||
void ImGuiStorage::SetFloat(ImGuiID key, float val)
|
void ImGuiStorage::SetFloat(ImGuiID key, float val)
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(Data, key);
|
ImGuiStoragePair* it = LowerBound(Data, key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
{
|
{
|
||||||
Data.insert(it, Pair(key, val));
|
Data.insert(it, ImGuiStoragePair(key, val));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it->val_f = val;
|
it->val_f = val;
|
||||||
@ -2051,10 +2051,10 @@ void ImGuiStorage::SetFloat(ImGuiID key, float val)
|
|||||||
|
|
||||||
void ImGuiStorage::SetVoidPtr(ImGuiID key, void* val)
|
void ImGuiStorage::SetVoidPtr(ImGuiID key, void* val)
|
||||||
{
|
{
|
||||||
ImGuiStorage::Pair* it = LowerBound(Data, key);
|
ImGuiStoragePair* it = LowerBound(Data, key);
|
||||||
if (it == Data.end() || it->key != key)
|
if (it == Data.end() || it->key != key)
|
||||||
{
|
{
|
||||||
Data.insert(it, Pair(key, val));
|
Data.insert(it, ImGuiStoragePair(key, val));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it->val_p = val;
|
it->val_p = val;
|
||||||
@ -2095,7 +2095,7 @@ bool ImGuiTextFilter::Draw(const char* label, float width)
|
|||||||
return value_changed;
|
return value_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>* out) const
|
void ImGuiTextFilter::ImGuiTextRange::split(char separator, ImVector<ImGuiTextRange>* out) const
|
||||||
{
|
{
|
||||||
out->resize(0);
|
out->resize(0);
|
||||||
const char* wb = b;
|
const char* wb = b;
|
||||||
@ -2104,25 +2104,25 @@ void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>* out)
|
|||||||
{
|
{
|
||||||
if (*we == separator)
|
if (*we == separator)
|
||||||
{
|
{
|
||||||
out->push_back(TextRange(wb, we));
|
out->push_back(ImGuiTextRange(wb, we));
|
||||||
wb = we + 1;
|
wb = we + 1;
|
||||||
}
|
}
|
||||||
we++;
|
we++;
|
||||||
}
|
}
|
||||||
if (wb != we)
|
if (wb != we)
|
||||||
out->push_back(TextRange(wb, we));
|
out->push_back(ImGuiTextRange(wb, we));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiTextFilter::Build()
|
void ImGuiTextFilter::Build()
|
||||||
{
|
{
|
||||||
Filters.resize(0);
|
Filters.resize(0);
|
||||||
TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
|
ImGuiTextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
|
||||||
input_range.split(',', &Filters);
|
input_range.split(',', &Filters);
|
||||||
|
|
||||||
CountGrep = 0;
|
CountGrep = 0;
|
||||||
for (int i = 0; i != Filters.Size; i++)
|
for (int i = 0; i != Filters.Size; i++)
|
||||||
{
|
{
|
||||||
TextRange& f = Filters[i];
|
ImGuiTextRange& f = Filters[i];
|
||||||
while (f.b < f.e && ImCharIsBlankA(f.b[0]))
|
while (f.b < f.e && ImCharIsBlankA(f.b[0]))
|
||||||
f.b++;
|
f.b++;
|
||||||
while (f.e > f.b && ImCharIsBlankA(f.e[-1]))
|
while (f.e > f.b && ImCharIsBlankA(f.e[-1]))
|
||||||
@ -2144,19 +2144,19 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
|
|||||||
|
|
||||||
for (int i = 0; i != Filters.Size; i++)
|
for (int i = 0; i != Filters.Size; i++)
|
||||||
{
|
{
|
||||||
const TextRange& f = Filters[i];
|
const ImGuiTextRange& f = Filters[i];
|
||||||
if (f.empty())
|
if (f.empty())
|
||||||
continue;
|
continue;
|
||||||
if (f.b[0] == '-')
|
if (f.b[0] == '-')
|
||||||
{
|
{
|
||||||
// Subtract
|
// Subtract
|
||||||
if (ImStristr(text, text_end, f.begin()+1, f.end()) != NULL)
|
if (ImStristr(text, text_end, f.b + 1, f.e) != NULL)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Grep
|
// Grep
|
||||||
if (ImStristr(text, text_end, f.begin(), f.end()) != NULL)
|
if (ImStristr(text, text_end, f.b, f.e) != NULL)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10102,7 +10102,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
NodeColumns(&window->ColumnsStorage[n]);
|
NodeColumns(&window->ColumnsStorage[n]);
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.Size * (int)sizeof(ImGuiStorage::Pair));
|
ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.size_in_bytes());
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
imgui.h
24
imgui.h
@ -1591,20 +1591,18 @@ struct ImGuiTextFilter
|
|||||||
bool IsActive() const { return !Filters.empty(); }
|
bool IsActive() const { return !Filters.empty(); }
|
||||||
|
|
||||||
// [Internal]
|
// [Internal]
|
||||||
struct TextRange
|
struct ImGuiTextRange
|
||||||
{
|
{
|
||||||
const char* b;
|
const char* b;
|
||||||
const char* e;
|
const char* e;
|
||||||
|
|
||||||
TextRange() { b = e = NULL; }
|
ImGuiTextRange() { b = e = NULL; }
|
||||||
TextRange(const char* _b, const char* _e) { b = _b; e = _e; }
|
ImGuiTextRange(const char* _b, const char* _e) { b = _b; e = _e; }
|
||||||
const char* begin() const { return b; }
|
|
||||||
const char* end () const { return e; }
|
|
||||||
bool empty() const { return b == e; }
|
bool empty() const { return b == e; }
|
||||||
IMGUI_API void split(char separator, ImVector<TextRange>* out) const;
|
IMGUI_API void split(char separator, ImVector<ImGuiTextRange>* out) const;
|
||||||
};
|
};
|
||||||
char InputBuf[256];
|
char InputBuf[256];
|
||||||
ImVector<TextRange> Filters;
|
ImVector<ImGuiTextRange>Filters;
|
||||||
int CountGrep;
|
int CountGrep;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1639,15 +1637,17 @@ struct ImGuiTextBuffer
|
|||||||
// Types are NOT stored, so it is up to you to make sure your Key don't collide with different types.
|
// Types are NOT stored, so it is up to you to make sure your Key don't collide with different types.
|
||||||
struct ImGuiStorage
|
struct ImGuiStorage
|
||||||
{
|
{
|
||||||
struct Pair
|
// [Internal]
|
||||||
|
struct ImGuiStoragePair
|
||||||
{
|
{
|
||||||
ImGuiID key;
|
ImGuiID key;
|
||||||
union { int val_i; float val_f; void* val_p; };
|
union { int val_i; float val_f; void* val_p; };
|
||||||
Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
|
ImGuiStoragePair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
|
||||||
Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
|
ImGuiStoragePair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
|
||||||
Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
|
ImGuiStoragePair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
|
||||||
};
|
};
|
||||||
ImVector<Pair> Data;
|
|
||||||
|
ImVector<ImGuiStoragePair> Data;
|
||||||
|
|
||||||
// - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N)
|
// - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N)
|
||||||
// - Set***() functions find pair, insertion on demand if missing.
|
// - Set***() functions find pair, insertion on demand if missing.
|
||||||
|
Loading…
Reference in New Issue
Block a user