mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
InputText: Internals: moved "apply_new_text" application code to reduce noise in a future commit (will be for #4714) + removed unused fields.
The move would ideally be no-op. technically we now clear state->Flags before calling ResizeCallback but those are unrelated. The 2 unused fields were incorrectly added by 24ff25981
.
This commit is contained in:
parent
5ac25e7c7a
commit
65f4be1a10
4
imgui.h
4
imgui.h
@ -64,7 +64,7 @@ Index of this file:
|
|||||||
// Version
|
// Version
|
||||||
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
|
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
|
||||||
#define IMGUI_VERSION "1.86 WIP"
|
#define IMGUI_VERSION "1.86 WIP"
|
||||||
#define IMGUI_VERSION_NUM 18510
|
#define IMGUI_VERSION_NUM 18511
|
||||||
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
|
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
|
||||||
#define IMGUI_HAS_TABLE
|
#define IMGUI_HAS_TABLE
|
||||||
|
|
||||||
@ -974,7 +974,7 @@ enum ImGuiWindowFlags_
|
|||||||
ImGuiWindowFlags_NoInputs = ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus,
|
ImGuiWindowFlags_NoInputs = ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus,
|
||||||
|
|
||||||
// [Internal]
|
// [Internal]
|
||||||
ImGuiWindowFlags_NavFlattened = 1 << 23, // [BETA] Allow gamepad/keyboard navigation to cross over parent border to this child (only use on child that have no scrolling!)
|
ImGuiWindowFlags_NavFlattened = 1 << 23, // [BETA] On child window: allow gamepad/keyboard navigation to cross over parent border to this child or between sibling child windows.
|
||||||
ImGuiWindowFlags_ChildWindow = 1 << 24, // Don't use! For internal use by BeginChild()
|
ImGuiWindowFlags_ChildWindow = 1 << 24, // Don't use! For internal use by BeginChild()
|
||||||
ImGuiWindowFlags_Tooltip = 1 << 25, // Don't use! For internal use by BeginTooltip()
|
ImGuiWindowFlags_Tooltip = 1 << 25, // Don't use! For internal use by BeginTooltip()
|
||||||
ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup()
|
ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup()
|
||||||
|
@ -1027,8 +1027,6 @@ struct IMGUI_API ImGuiInputTextState
|
|||||||
bool SelectedAllMouseLock; // after a double-click to select all, we ignore further mouse drags to update selection
|
bool SelectedAllMouseLock; // after a double-click to select all, we ignore further mouse drags to update selection
|
||||||
bool Edited; // edited this frame
|
bool Edited; // edited this frame
|
||||||
ImGuiInputTextFlags Flags; // copy of InputText() flags
|
ImGuiInputTextFlags Flags; // copy of InputText() flags
|
||||||
ImGuiInputTextCallback UserCallback; // "
|
|
||||||
void* UserCallbackData; // "
|
|
||||||
|
|
||||||
ImGuiInputTextState() { memset(this, 0, sizeof(*this)); }
|
ImGuiInputTextState() { memset(this, 0, sizeof(*this)); }
|
||||||
void ClearText() { CurLenW = CurLenA = 0; TextW[0] = 0; TextA[0] = 0; CursorClamp(); }
|
void ClearText() { CurLenW = CurLenA = 0; TextW[0] = 0; TextA[0] = 0; CursorClamp(); }
|
||||||
|
@ -4165,8 +4165,6 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
state->Edited = false;
|
state->Edited = false;
|
||||||
state->BufCapacityA = buf_size;
|
state->BufCapacityA = buf_size;
|
||||||
state->Flags = flags;
|
state->Flags = flags;
|
||||||
state->UserCallback = callback;
|
|
||||||
state->UserCallbackData = callback_user_data;
|
|
||||||
|
|
||||||
// Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
|
// Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
|
||||||
// Down the line we should have a cleaner library-wide concept of Selected vs Active.
|
// Down the line we should have a cleaner library-wide concept of Selected vs Active.
|
||||||
@ -4404,11 +4402,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process callbacks and apply result back to user's buffer.
|
// Process callbacks and apply result back to user's buffer.
|
||||||
|
const char* apply_new_text = NULL;
|
||||||
|
int apply_new_text_length = 0;
|
||||||
if (g.ActiveId == id)
|
if (g.ActiveId == id)
|
||||||
{
|
{
|
||||||
IM_ASSERT(state != NULL);
|
IM_ASSERT(state != NULL);
|
||||||
const char* apply_new_text = NULL;
|
|
||||||
int apply_new_text_length = 0;
|
|
||||||
if (cancel_edit)
|
if (cancel_edit)
|
||||||
{
|
{
|
||||||
// Restore initial value. Only return true if restoring to the initial value changes the current buffer contents.
|
// Restore initial value. Only return true if restoring to the initial value changes the current buffer contents.
|
||||||
@ -4528,39 +4526,37 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy result to user buffer
|
|
||||||
if (apply_new_text)
|
|
||||||
{
|
|
||||||
// We cannot test for 'backup_current_text_length != apply_new_text_length' here because we have no guarantee that the size
|
|
||||||
// of our owned buffer matches the size of the string object held by the user, and by design we allow InputText() to be used
|
|
||||||
// without any storage on user's side.
|
|
||||||
IM_ASSERT(apply_new_text_length >= 0);
|
|
||||||
if (is_resizable)
|
|
||||||
{
|
|
||||||
ImGuiInputTextCallbackData callback_data;
|
|
||||||
callback_data.EventFlag = ImGuiInputTextFlags_CallbackResize;
|
|
||||||
callback_data.Flags = flags;
|
|
||||||
callback_data.Buf = buf;
|
|
||||||
callback_data.BufTextLen = apply_new_text_length;
|
|
||||||
callback_data.BufSize = ImMax(buf_size, apply_new_text_length + 1);
|
|
||||||
callback_data.UserData = callback_user_data;
|
|
||||||
callback(&callback_data);
|
|
||||||
buf = callback_data.Buf;
|
|
||||||
buf_size = callback_data.BufSize;
|
|
||||||
apply_new_text_length = ImMin(callback_data.BufTextLen, buf_size - 1);
|
|
||||||
IM_ASSERT(apply_new_text_length <= buf_size);
|
|
||||||
}
|
|
||||||
//IMGUI_DEBUG_LOG("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length);
|
|
||||||
|
|
||||||
// If the underlying buffer resize was denied or not carried to the next frame, apply_new_text_length+1 may be >= buf_size.
|
|
||||||
ImStrncpy(buf, apply_new_text, ImMin(apply_new_text_length + 1, buf_size));
|
|
||||||
value_changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear temporary user storage
|
// Clear temporary user storage
|
||||||
state->Flags = ImGuiInputTextFlags_None;
|
state->Flags = ImGuiInputTextFlags_None;
|
||||||
state->UserCallback = NULL;
|
}
|
||||||
state->UserCallbackData = NULL;
|
|
||||||
|
// Copy result to user buffer. This can currently only happen when (g.ActiveId == id)
|
||||||
|
if (apply_new_text != NULL)
|
||||||
|
{
|
||||||
|
// We cannot test for 'backup_current_text_length != apply_new_text_length' here because we have no guarantee that the size
|
||||||
|
// of our owned buffer matches the size of the string object held by the user, and by design we allow InputText() to be used
|
||||||
|
// without any storage on user's side.
|
||||||
|
IM_ASSERT(apply_new_text_length >= 0);
|
||||||
|
if (is_resizable)
|
||||||
|
{
|
||||||
|
ImGuiInputTextCallbackData callback_data;
|
||||||
|
callback_data.EventFlag = ImGuiInputTextFlags_CallbackResize;
|
||||||
|
callback_data.Flags = flags;
|
||||||
|
callback_data.Buf = buf;
|
||||||
|
callback_data.BufTextLen = apply_new_text_length;
|
||||||
|
callback_data.BufSize = ImMax(buf_size, apply_new_text_length + 1);
|
||||||
|
callback_data.UserData = callback_user_data;
|
||||||
|
callback(&callback_data);
|
||||||
|
buf = callback_data.Buf;
|
||||||
|
buf_size = callback_data.BufSize;
|
||||||
|
apply_new_text_length = ImMin(callback_data.BufTextLen, buf_size - 1);
|
||||||
|
IM_ASSERT(apply_new_text_length <= buf_size);
|
||||||
|
}
|
||||||
|
//IMGUI_DEBUG_LOG("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length);
|
||||||
|
|
||||||
|
// If the underlying buffer resize was denied or not carried to the next frame, apply_new_text_length+1 may be >= buf_size.
|
||||||
|
ImStrncpy(buf, apply_new_text, ImMin(apply_new_text_length + 1, buf_size));
|
||||||
|
value_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release active ID at the end of the function (so e.g. pressing Return still does a final application of the value)
|
// Release active ID at the end of the function (so e.g. pressing Return still does a final application of the value)
|
||||||
|
Loading…
Reference in New Issue
Block a user