From a643b23486d77b6b9bdfbe9f58a17673d62eaac6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 30 Nov 2020 09:43:10 +0100 Subject: [PATCH] ImStrv: added imconfig class extension example, added natvis description. --- imconfig.h | 9 +++++++++ imgui.h | 9 +++++---- misc/debuggers/imgui.natvis | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/imconfig.h b/imconfig.h index c854832e..976f9ecd 100644 --- a/imconfig.h +++ b/imconfig.h @@ -90,6 +90,15 @@ operator MyVec4() const { return MyVec4(x,y,z,w); } */ +//---- Define constructor to convert your string type to ImStrv (which is a non-owning begin/end pair) +// This will be inlined as part of ImStrv class declaration. +// This has two benefits: you won't need to use .c_str(), if length is already computed it is faster. +//#include +//#include +//#define IM_STR_CLASS_EXTRA ImStrv(const std::string& s) { Begin = s.c_str(); End = Begin + s.length(); } +//#define IM_STR_CLASS_EXTRA ImStrv(const std::string_view& s) { Begin = s.data(); End = Begin + s.length(); } +//#define IM_STR_CLASS_EXTRA ImStrv(const MyString& s) { Begin = s.Data; End = s.end(); } + //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. diff --git a/imgui.h b/imgui.h index ad9801bb..0d286445 100644 --- a/imgui.h +++ b/imgui.h @@ -269,7 +269,8 @@ struct ImVec4 #endif }; -// String view class. +// String view (non-owning pair of begin/end pointers, not necessarily zero-terminated) +// ImStrv are used as function parameters instead of passing a pair of const char*. #define IMGUI_HAS_IMSTR struct ImStrv { @@ -280,9 +281,9 @@ struct ImStrv ImStrv(const char* b, const char* e){ Begin = b; End = e ? e : b + strlen(b); } inline size_t length() const { return (size_t)(End - Begin); } inline bool empty() const { return Begin == End; } // == "" or == NULL - inline operator bool() const { return Begin != NULL; } // != NULL -#ifdef IM_IMSTR_CLASS_EXTRA - IM_IMSTR_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your string types and ImStrv. + inline operator bool() const { return Begin != NULL; } // return true when valid ("" is valid, NULL construction is not) +#ifdef IM_STR_CLASS_EXTRA + IM_STR_CLASS_EXTRA // Define additional constructor in imconfig.h to convert your string types (e.g. std::string, std::string_view) to ImStrV. #endif // private: bool operator==(ImStrv) { return false; } // [DEBUG] Uncomment to catch undesirable uses of operators // private: bool operator!=(ImStrv) { return false; } diff --git a/misc/debuggers/imgui.natvis b/misc/debuggers/imgui.natvis index 13b63600..7d0c9dd1 100644 --- a/misc/debuggers/imgui.natvis +++ b/misc/debuggers/imgui.natvis @@ -51,6 +51,11 @@ More information at: https://docs.microsoft.com/en-us/visualstudio/debugger/crea + + + {Begin,[End-Begin]s} ({End-Begin,d}) + + {{Name {Name,s} Active {(Active||WasActive)?1:0,d} Child {(Flags & 0x01000000)?1:0,d} Popup {(Flags & 0x04000000)?1:0,d} Hidden {(Hidden)?1:0,d}}