mirror of
https://github.com/ocornut/imgui.git
synced 2025-12-21 05:45:34 +00:00
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_sdl3.cpp # examples/example_sdl3_vulkan/main.cpp
This commit is contained in:
@@ -4148,21 +4148,23 @@ static void STB_TEXTEDIT_DELETECHARS(ImGuiInputTextState* obj, int pos, int n)
|
||||
obj->TextLen -= n;
|
||||
}
|
||||
|
||||
static bool STB_TEXTEDIT_INSERTCHARS(ImGuiInputTextState* obj, int pos, const char* new_text, int new_text_len)
|
||||
static int STB_TEXTEDIT_INSERTCHARS(ImGuiInputTextState* obj, int pos, const char* new_text, int new_text_len)
|
||||
{
|
||||
const bool is_resizable = (obj->Flags & ImGuiInputTextFlags_CallbackResize) != 0;
|
||||
const int text_len = obj->TextLen;
|
||||
IM_ASSERT(pos <= text_len);
|
||||
|
||||
if (!is_resizable && (new_text_len + obj->TextLen + 1 > obj->BufCapacity))
|
||||
return false;
|
||||
// We support partial insertion (with a mod in stb_textedit.h)
|
||||
const int avail = obj->BufCapacity - 1 - obj->TextLen;
|
||||
if (!is_resizable && new_text_len > avail)
|
||||
new_text_len = avail; // 0
|
||||
if (new_text_len == 0)
|
||||
return 0;
|
||||
|
||||
// Grow internal buffer if needed
|
||||
IM_ASSERT(obj->TextSrc == obj->TextA.Data);
|
||||
if (new_text_len + text_len + 1 > obj->TextA.Size)
|
||||
if (text_len + new_text_len + 1 > obj->TextA.Size && is_resizable)
|
||||
{
|
||||
if (!is_resizable)
|
||||
return false;
|
||||
obj->TextA.resize(text_len + ImClamp(new_text_len, 32, ImMax(256, new_text_len)) + 1);
|
||||
obj->TextSrc = obj->TextA.Data;
|
||||
}
|
||||
@@ -4176,7 +4178,7 @@ static bool STB_TEXTEDIT_INSERTCHARS(ImGuiInputTextState* obj, int pos, const ch
|
||||
obj->TextLen += new_text_len;
|
||||
obj->TextA[obj->TextLen] = '\0';
|
||||
|
||||
return true;
|
||||
return new_text_len;
|
||||
}
|
||||
|
||||
// We don't use an enum so we can build even with conflicting symbols (if another user of stb_textedit.h leak their STB_TEXTEDIT_K_* symbols)
|
||||
@@ -4211,7 +4213,8 @@ static void stb_textedit_replace(ImGuiInputTextState* str, STB_TexteditState* st
|
||||
state->cursor = state->select_start = state->select_end = 0;
|
||||
if (text_len <= 0)
|
||||
return;
|
||||
if (ImStb::STB_TEXTEDIT_INSERTCHARS(str, 0, text, text_len))
|
||||
int text_len_inserted = ImStb::STB_TEXTEDIT_INSERTCHARS(str, 0, text, text_len);
|
||||
if (text_len_inserted > 0)
|
||||
{
|
||||
state->cursor = state->select_start = state->select_end = text_len;
|
||||
state->has_preferred_x = 0;
|
||||
@@ -4306,15 +4309,20 @@ void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, cons
|
||||
ImGuiContext& g = *Ctx;
|
||||
ImGuiInputTextState* obj = &g.InputTextState;
|
||||
IM_ASSERT(obj->ID != 0 && g.ActiveId == obj->ID);
|
||||
const bool is_resizable = (Flags & ImGuiInputTextFlags_CallbackResize) != 0;
|
||||
const bool is_readonly = (Flags & ImGuiInputTextFlags_ReadOnly) != 0;
|
||||
int new_text_len = new_text_end ? (int)(new_text_end - new_text) : (int)ImStrlen(new_text);
|
||||
|
||||
// We support partial insertion (with a mod in stb_textedit.h)
|
||||
const int avail = BufSize - 1 - BufTextLen;
|
||||
if (!is_resizable && new_text_len > avail)
|
||||
new_text_len = avail; // 0
|
||||
if (new_text_len == 0)
|
||||
return;
|
||||
|
||||
// Grow internal buffer if needed
|
||||
const bool is_resizable = (Flags & ImGuiInputTextFlags_CallbackResize) != 0;
|
||||
const int new_text_len = new_text_end ? (int)(new_text_end - new_text) : (int)ImStrlen(new_text);
|
||||
if (new_text_len + BufTextLen + 1 > obj->TextA.Size && (Flags & ImGuiInputTextFlags_ReadOnly) == 0)
|
||||
if (new_text_len + BufTextLen + 1 > obj->TextA.Size && is_resizable && !is_readonly)
|
||||
{
|
||||
if (!is_resizable)
|
||||
return;
|
||||
|
||||
IM_ASSERT(Buf == obj->TextA.Data);
|
||||
int new_buf_size = BufTextLen + ImClamp(new_text_len * 4, 32, ImMax(256, new_text_len)) + 1;
|
||||
obj->TextA.resize(new_buf_size + 1);
|
||||
@@ -5268,10 +5276,9 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
callback_data.BufTextLen = state->TextLen;
|
||||
callback_data.BufSize = state->BufCapacity;
|
||||
callback_data.BufDirty = false;
|
||||
|
||||
const int utf8_cursor_pos = callback_data.CursorPos = state->Stb->cursor;
|
||||
const int utf8_selection_start = callback_data.SelectionStart = state->Stb->select_start;
|
||||
const int utf8_selection_end = callback_data.SelectionEnd = state->Stb->select_end;
|
||||
callback_data.CursorPos = state->Stb->cursor;
|
||||
callback_data.SelectionStart = state->Stb->select_start;
|
||||
callback_data.SelectionEnd = state->Stb->select_end;
|
||||
|
||||
// Call user code
|
||||
callback(&callback_data);
|
||||
@@ -5281,11 +5288,12 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
IM_ASSERT(callback_data.Buf == callback_buf); // Invalid to modify those fields
|
||||
IM_ASSERT(callback_data.BufSize == state->BufCapacity);
|
||||
IM_ASSERT(callback_data.Flags == flags);
|
||||
const bool buf_dirty = callback_data.BufDirty;
|
||||
if (callback_data.CursorPos != utf8_cursor_pos || buf_dirty) { state->Stb->cursor = callback_data.CursorPos; state->CursorFollow = true; }
|
||||
if (callback_data.SelectionStart != utf8_selection_start || buf_dirty) { state->Stb->select_start = (callback_data.SelectionStart == callback_data.CursorPos) ? state->Stb->cursor : callback_data.SelectionStart; }
|
||||
if (callback_data.SelectionEnd != utf8_selection_end || buf_dirty) { state->Stb->select_end = (callback_data.SelectionEnd == callback_data.SelectionStart) ? state->Stb->select_start : callback_data.SelectionEnd; }
|
||||
if (buf_dirty)
|
||||
if (callback_data.BufDirty || callback_data.CursorPos != state->Stb->cursor)
|
||||
state->CursorFollow = true;
|
||||
state->Stb->cursor = ImClamp(callback_data.CursorPos, 0, callback_data.BufTextLen);
|
||||
state->Stb->select_start = ImClamp(callback_data.SelectionStart, 0, callback_data.BufTextLen);
|
||||
state->Stb->select_end = ImClamp(callback_data.SelectionEnd, 0, callback_data.BufTextLen);
|
||||
if (callback_data.BufDirty)
|
||||
{
|
||||
// Callback may update buffer and thus set buf_dirty even in read-only mode.
|
||||
IM_ASSERT(callback_data.BufTextLen == (int)ImStrlen(callback_data.Buf)); // You need to maintain BufTextLen if you change the text!
|
||||
@@ -8219,8 +8227,8 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
|
||||
}
|
||||
|
||||
// Right-click handling.
|
||||
// FIXME-MULTISELECT: Currently filtered out by ImGuiMultiSelectFlags_NoAutoSelect but maybe should be moved to Selectable(). See https://github.com/ocornut/imgui/pull/5816
|
||||
if (hovered && IsMouseClicked(1) && (flags & ImGuiMultiSelectFlags_NoAutoSelect) == 0)
|
||||
// FIXME-MULTISELECT: Maybe should be moved to Selectable()? Also see #5816, #8200, #9015
|
||||
if (hovered && IsMouseClicked(1) && (flags & (ImGuiMultiSelectFlags_NoAutoSelect | ImGuiMultiSelectFlags_NoSelectOnRightClick)) == 0)
|
||||
{
|
||||
if (g.ActiveId != 0 && g.ActiveId != id)
|
||||
ClearActiveID();
|
||||
|
||||
Reference in New Issue
Block a user