mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-04-24 10:38:53 +00:00
Adapted imgui_stdlib to idStr
This commit is contained in:
parent
86dd5558da
commit
f4e84b50db
3 changed files with 29 additions and 13 deletions
|
@ -3700,4 +3700,7 @@ enum ImGuiKeyModFlags_ { ImGuiKeyModFlags_None = ImGuiModFlags_None, ImGuiKeyMod
|
|||
#include "imgui_user.h"
|
||||
#endif
|
||||
|
||||
// RB: added idlib idStr integration for string inputs
|
||||
#include "imgui_stdlib.h"
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
|
|
|
@ -7,9 +7,22 @@
|
|||
#include "imgui.h"
|
||||
#include "imgui_stdlib.h"
|
||||
|
||||
// RB: replaced std::string with idStr
|
||||
#include "sys/sys_defines.h"
|
||||
#include "sys/sys_builddefines.h"
|
||||
#include "sys/sys_includes.h"
|
||||
#include "sys/sys_assert.h"
|
||||
#include "sys/sys_types.h"
|
||||
#include "sys/sys_intrinsics.h"
|
||||
#include "sys/sys_threading.h"
|
||||
|
||||
#include "CmdArgs.h"
|
||||
#include "containers/Sort.h"
|
||||
#include "Str.h"
|
||||
|
||||
struct InputTextCallback_UserData
|
||||
{
|
||||
std::string* Str;
|
||||
idStr* Str;
|
||||
ImGuiInputTextCallback ChainCallback;
|
||||
void* ChainCallbackUserData;
|
||||
};
|
||||
|
@ -21,9 +34,9 @@ static int InputTextCallback( ImGuiInputTextCallbackData* data )
|
|||
{
|
||||
// Resize string callback
|
||||
// If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back to what we want.
|
||||
std::string* str = user_data->Str;
|
||||
idStr* str = user_data->Str;
|
||||
IM_ASSERT( data->Buf == str->c_str() );
|
||||
str->resize( data->BufTextLen );
|
||||
str->ReAllocate( data->BufTextLen, true );
|
||||
data->Buf = ( char* )str->c_str();
|
||||
}
|
||||
else if( user_data->ChainCallback )
|
||||
|
@ -35,7 +48,7 @@ static int InputTextCallback( ImGuiInputTextCallbackData* data )
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool ImGui::InputText( const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data )
|
||||
bool ImGui::InputText( const char* label, idStr* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data )
|
||||
{
|
||||
IM_ASSERT( ( flags & ImGuiInputTextFlags_CallbackResize ) == 0 );
|
||||
flags |= ImGuiInputTextFlags_CallbackResize;
|
||||
|
@ -44,10 +57,10 @@ bool ImGui::InputText( const char* label, std::string* str, ImGuiInputTextFlags
|
|||
cb_user_data.Str = str;
|
||||
cb_user_data.ChainCallback = callback;
|
||||
cb_user_data.ChainCallbackUserData = user_data;
|
||||
return InputText( label, ( char* )str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data );
|
||||
return InputText( label, ( char* )str->c_str(), str->Size() + 1, flags, InputTextCallback, &cb_user_data );
|
||||
}
|
||||
|
||||
bool ImGui::InputTextMultiline( const char* label, std::string* str, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data )
|
||||
bool ImGui::InputTextMultiline( const char* label, idStr* str, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data )
|
||||
{
|
||||
IM_ASSERT( ( flags & ImGuiInputTextFlags_CallbackResize ) == 0 );
|
||||
flags |= ImGuiInputTextFlags_CallbackResize;
|
||||
|
@ -56,10 +69,10 @@ bool ImGui::InputTextMultiline( const char* label, std::string* str, const ImVec
|
|||
cb_user_data.Str = str;
|
||||
cb_user_data.ChainCallback = callback;
|
||||
cb_user_data.ChainCallbackUserData = user_data;
|
||||
return InputTextMultiline( label, ( char* )str->c_str(), str->capacity() + 1, size, flags, InputTextCallback, &cb_user_data );
|
||||
return InputTextMultiline( label, ( char* )str->c_str(), str->Size() + 1, size, flags, InputTextCallback, &cb_user_data );
|
||||
}
|
||||
|
||||
bool ImGui::InputTextWithHint( const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data )
|
||||
bool ImGui::InputTextWithHint( const char* label, const char* hint, idStr* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data )
|
||||
{
|
||||
IM_ASSERT( ( flags & ImGuiInputTextFlags_CallbackResize ) == 0 );
|
||||
flags |= ImGuiInputTextFlags_CallbackResize;
|
||||
|
@ -68,5 +81,5 @@ bool ImGui::InputTextWithHint( const char* label, const char* hint, std::string*
|
|||
cb_user_data.Str = str;
|
||||
cb_user_data.ChainCallback = callback;
|
||||
cb_user_data.ChainCallbackUserData = user_data;
|
||||
return InputTextWithHint( label, hint, ( char* )str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data );
|
||||
return InputTextWithHint( label, hint, ( char* )str->c_str(), str->Size() + 1, flags, InputTextCallback, &cb_user_data );
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
class idStr;
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
// ImGui::InputText() with std::string
|
||||
// Because text input needs dynamic resizing, we need to setup a callback to grow the capacity
|
||||
IMGUI_API bool InputText( const char* label, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL );
|
||||
IMGUI_API bool InputTextMultiline( const char* label, std::string* str, const ImVec2& size = ImVec2( 0, 0 ), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL );
|
||||
IMGUI_API bool InputTextWithHint( const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL );
|
||||
IMGUI_API bool InputText( const char* label, idStr* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL );
|
||||
IMGUI_API bool InputTextMultiline( const char* label, idStr* str, const ImVec2& size = ImVec2( 0, 0 ), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL );
|
||||
IMGUI_API bool InputTextWithHint( const char* label, const char* hint, idStr* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue