mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-07 05:43:17 +00:00
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_win32.cpp # imgui.cpp
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.89.9
|
||||
// dear imgui, v1.90 WIP
|
||||
// (widgets code)
|
||||
|
||||
/*
|
||||
@@ -18,6 +18,7 @@ Index of this file:
|
||||
// [SECTION] Widgets: ColorEdit, ColorPicker, ColorButton, etc.
|
||||
// [SECTION] Widgets: TreeNode, CollapsingHeader, etc.
|
||||
// [SECTION] Widgets: Selectable
|
||||
// [SECTION] Widgets: Typing-Select support
|
||||
// [SECTION] Widgets: ListBox
|
||||
// [SECTION] Widgets: PlotLines, PlotHistogram
|
||||
// [SECTION] Widgets: Value helpers
|
||||
@@ -3699,7 +3700,7 @@ namespace ImStb
|
||||
{
|
||||
|
||||
static int STB_TEXTEDIT_STRINGLEN(const ImGuiInputTextState* obj) { return obj->CurLenW; }
|
||||
static ImWchar STB_TEXTEDIT_GETCHAR(const ImGuiInputTextState* obj, int idx) { return obj->TextW[idx]; }
|
||||
static ImWchar STB_TEXTEDIT_GETCHAR(const ImGuiInputTextState* obj, int idx) { IM_ASSERT(idx <= obj->CurLenW); return obj->TextW[idx]; }
|
||||
static float STB_TEXTEDIT_GETWIDTH(ImGuiInputTextState* obj, int line_start_idx, int char_idx) { ImWchar c = obj->TextW[line_start_idx + char_idx]; if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; ImGuiContext& g = *obj->Ctx; return g.Font->GetCharAdvance(c) * (g.FontSize / g.Font->FontSize); }
|
||||
static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x200000 ? 0 : key; }
|
||||
static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
|
||||
@@ -6604,6 +6605,103 @@ bool ImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// [SECTION] Widgets: Typing-Select support
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
// [Experimental] Currently not exposed in public API.
|
||||
// Consume character inputs and return search request, if any.
|
||||
// This would typically only be called on the focused window or location you want to grab inputs for, e.g.
|
||||
// if (ImGui::IsWindowFocused(...))
|
||||
// if (const ImGuiTypingSelectRequest* req = ImGui::GetTypingSelectRequest())
|
||||
// if (req->SearchRequest)
|
||||
// // perform search
|
||||
// However the code is written in a way where calling it from multiple locations is safe (e.g. to obtain buffer).
|
||||
const ImGuiTypingSelectRequest* ImGui::GetTypingSelectRequest(ImGuiTypingSelectFlags flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiTypingSelectData* data = &g.TypingSelectData;
|
||||
ImGuiTypingSelectRequest* out_request = &data->Request;
|
||||
|
||||
// Clear buffer
|
||||
if (data->SearchBuffer[0] != 0)
|
||||
{
|
||||
const float TYPING_SELECT_RESET_TIMER = 1.70f; // FIXME: Potentially move to IO config.
|
||||
bool clear_buffer = false;
|
||||
clear_buffer |= (g.NavFocusScopeId != data->FocusScope);
|
||||
clear_buffer |= (data->LastRequestTime + TYPING_SELECT_RESET_TIMER < g.Time);
|
||||
clear_buffer |= g.NavAnyRequest;
|
||||
clear_buffer |= g.ActiveId != 0 && g.NavActivateId == 0; // Allow temporary SPACE activation to not interfere
|
||||
clear_buffer |= IsKeyPressed(ImGuiKey_Escape) || IsKeyPressed(ImGuiKey_Enter);
|
||||
clear_buffer |= IsKeyPressed(ImGuiKey_Backspace) && (flags & ImGuiTypingSelectFlags_AllowBackspace) == 0;
|
||||
//if (clear_buffer) { IMGUI_DEBUG_LOG("GetTypingSelectRequest(): Clear SearchBuffer.\n"); }
|
||||
if (clear_buffer)
|
||||
data->SearchBuffer[0] = 0;
|
||||
}
|
||||
|
||||
// Append to buffer
|
||||
const int buffer_max_len = IM_ARRAYSIZE(data->SearchBuffer) - 1;
|
||||
int buffer_len = (int)strlen(data->SearchBuffer);
|
||||
bool buffer_changed = false;
|
||||
for (ImWchar w : g.IO.InputQueueCharacters)
|
||||
{
|
||||
if (w < 32 || (buffer_len == 0 && ImCharIsBlankW(w))) // Ignore leading blanks
|
||||
continue;
|
||||
int utf8_len = ImTextCountUtf8BytesFromStr(&w, &w + 1);
|
||||
if (buffer_len + utf8_len > buffer_max_len)
|
||||
break;
|
||||
ImTextCharToUtf8(data->SearchBuffer + buffer_len, (unsigned int)w);
|
||||
buffer_len += utf8_len;
|
||||
buffer_changed = true;
|
||||
}
|
||||
g.IO.InputQueueCharacters.resize(0);
|
||||
if ((flags & ImGuiTypingSelectFlags_AllowBackspace) && IsKeyPressed(ImGuiKey_Backspace, 0, ImGuiInputFlags_Repeat))
|
||||
{
|
||||
char* p = (char*)(void*)ImTextFindPreviousUtf8Codepoint(data->SearchBuffer, data->SearchBuffer + buffer_len);
|
||||
*p = 0;
|
||||
buffer_len = (int)(p - data->SearchBuffer);
|
||||
}
|
||||
if (buffer_len == 0)
|
||||
return NULL;
|
||||
|
||||
// Return request if any
|
||||
if (buffer_changed)
|
||||
{
|
||||
data->FocusScope = g.NavFocusScopeId;
|
||||
data->LastRequestFrame = g.FrameCount;
|
||||
data->LastRequestTime = (float)g.Time;
|
||||
}
|
||||
out_request->SearchBuffer = data->SearchBuffer;
|
||||
out_request->SearchBufferLen = buffer_len;
|
||||
out_request->SelectRequest = (data->LastRequestFrame == g.FrameCount);
|
||||
out_request->RepeatCharMode = false;
|
||||
out_request->RepeatCharSize = 0;
|
||||
|
||||
// Calculate if buffer contains the same character repeated.
|
||||
// - This can be used to implement a special search mode on first character.
|
||||
// - Performed on UTF-8 codepoint for correctness.
|
||||
// - RepeatCharMode is always set for first input character, because it usually leads to a "next".
|
||||
const char* buf_begin = out_request->SearchBuffer;
|
||||
const char* buf_end = out_request->SearchBuffer + out_request->SearchBufferLen;
|
||||
const int c0_len = ImTextCountUtf8BytesFromChar(buf_begin, buf_end);
|
||||
const char* p = buf_begin + c0_len;
|
||||
for (; p < buf_end; p += c0_len)
|
||||
if (memcmp(buf_begin, p, (size_t)c0_len) != 0)
|
||||
break;
|
||||
out_request->RepeatCharMode = (p == buf_end);
|
||||
out_request->RepeatCharSize = out_request->RepeatCharMode ? (ImS8)c0_len : 0;
|
||||
|
||||
return out_request;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// [SECTION] Widgets: Multi-Select support
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// [SECTION] Widgets: ListBox
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -6637,6 +6735,7 @@ bool ImGui::BeginListBox(const char* label, const ImVec2& size_arg)
|
||||
{
|
||||
ItemSize(bb.GetSize(), style.FramePadding.y);
|
||||
ItemAdd(bb, 0, &frame_bb);
|
||||
g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7041,12 +7140,18 @@ void ImGui::EndMenuBar()
|
||||
PopClipRect();
|
||||
PopID();
|
||||
window->DC.MenuBarOffset.x = window->DC.CursorPos.x - window->Pos.x; // Save horizontal position so next append can reuse it. This is kinda equivalent to a per-layer CursorPos.
|
||||
g.GroupStack.back().EmitItem = false;
|
||||
EndGroup(); // Restore position on layer 0
|
||||
|
||||
// FIXME: Extremely confusing, cleanup by (a) working on WorkRect stack system (b) not using a Group confusingly here.
|
||||
ImGuiGroupData& group_data = g.GroupStack.back();
|
||||
group_data.EmitItem = false;
|
||||
ImVec2 restore_cursor_max_pos = group_data.BackupCursorMaxPos;
|
||||
window->DC.IdealMaxPos.x = ImMax(window->DC.IdealMaxPos.x, window->DC.CursorMaxPos.x - window->Scroll.x); // Convert ideal extents for scrolling layer equivalent.
|
||||
EndGroup(); // Restore position on layer 0 // FIXME: Misleading to use a group for that backup/restore
|
||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||
window->DC.IsSameLine = false;
|
||||
window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
|
||||
window->DC.MenuBarAppending = false;
|
||||
window->DC.CursorMaxPos = restore_cursor_max_pos;
|
||||
}
|
||||
|
||||
// Important: calling order matters!
|
||||
|
||||
Reference in New Issue
Block a user