mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Merge branch 'master' into docking
# Conflicts: # examples/imgui_impl_sdl.cpp # imgui.cpp # imgui_internal.h
This commit is contained in:
@ -38,6 +38,7 @@ Index of this file:
|
||||
#include "imgui_internal.h"
|
||||
|
||||
#include <ctype.h> // toupper, isprint
|
||||
#include <wchar.h> // wmemchr
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
|
||||
#include <stddef.h> // intptr_t
|
||||
#else
|
||||
@ -135,8 +136,9 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
{
|
||||
// Long text!
|
||||
// Perform manual coarse clipping to optimize for long multi-line text
|
||||
// From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
|
||||
// We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
|
||||
// - From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
|
||||
// - We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
|
||||
// - We use memchr(), pay attention that well optimized versions of those str/mem functions are much faster than a casually written loop.
|
||||
const char* line = text;
|
||||
const float line_height = GetTextLineHeight();
|
||||
const ImRect clip_rect = window->ClipRect;
|
||||
@ -155,7 +157,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
int lines_skipped = 0;
|
||||
while (line < text_end && lines_skipped < lines_skippable)
|
||||
{
|
||||
const char* line_end = strchr(line, '\n');
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
line = line_end + 1;
|
||||
@ -171,15 +173,15 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
ImRect line_rect(pos, pos + ImVec2(FLT_MAX, line_height));
|
||||
while (line < text_end)
|
||||
{
|
||||
const char* line_end = strchr(line, '\n');
|
||||
if (IsClippedEx(line_rect, 0, false))
|
||||
break;
|
||||
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
const ImVec2 line_size = CalcTextSize(line, line_end, false);
|
||||
text_size.x = ImMax(text_size.x, line_size.x);
|
||||
RenderText(pos, line, line_end, false);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
line = line_end + 1;
|
||||
line_rect.Min.y += line_height;
|
||||
line_rect.Max.y += line_height;
|
||||
@ -190,7 +192,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
int lines_skipped = 0;
|
||||
while (line < text_end)
|
||||
{
|
||||
const char* line_end = strchr(line, '\n');
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
line = line_end + 1;
|
||||
@ -2928,7 +2930,7 @@ static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n)
|
||||
obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n);
|
||||
obj->CurLenW -= n;
|
||||
|
||||
// Offset remaining text
|
||||
// Offset remaining text (FIXME-OPT: Use memmove)
|
||||
const ImWchar* src = obj->TextW.Data + pos + n;
|
||||
while (ImWchar c = *src++)
|
||||
*dst++ = c;
|
||||
@ -3116,7 +3118,7 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
||||
// This is so we can easily call InputText() on static arrays using ARRAYSIZE() and to match
|
||||
// Note that in std::string world, capacity() would omit 1 byte used by the zero-terminator.
|
||||
// - When active, hold on a privately held copy of the text (and apply back to 'buf'). So changing 'buf' while the InputText is active has no effect.
|
||||
// - If you want to use ImGui::InputText() with std::string, see misc/stl/imgui_stl.h
|
||||
// - If you want to use ImGui::InputText() with std::string, see misc/cpp/imgui_stdlib.h
|
||||
// (FIXME: Rather messy function partly because we are doing UTF8 > u16 > UTF8 conversions on the go to more easily handle stb_textedit calls. Ideally we should stay in UTF-8 all the time. See https://github.com/nothings/stb/issues/188)
|
||||
bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* callback_user_data)
|
||||
{
|
||||
@ -3639,13 +3641,12 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
// In multi-line mode, we never exit the loop until all lines are counted, so add one extra to the searches_remaining counter.
|
||||
searches_remaining += is_multiline ? 1 : 0;
|
||||
int line_count = 0;
|
||||
for (const ImWchar* s = text_begin; *s != 0; s++)
|
||||
if (*s == '\n')
|
||||
{
|
||||
line_count++;
|
||||
if (searches_result_line_number[0] == -1 && s >= searches_input_ptr[0]) { searches_result_line_number[0] = line_count; if (--searches_remaining <= 0) break; }
|
||||
if (searches_result_line_number[1] == -1 && s >= searches_input_ptr[1]) { searches_result_line_number[1] = line_count; if (--searches_remaining <= 0) break; }
|
||||
}
|
||||
for (const ImWchar* s = text_begin; (s = (const ImWchar*)wcschr((const wchar_t*)s, (wchar_t)'\n')) != NULL; s++)
|
||||
{
|
||||
line_count++;
|
||||
if (searches_result_line_number[0] == -1 && s >= searches_input_ptr[0]) { searches_result_line_number[0] = line_count; if (--searches_remaining <= 0) break; }
|
||||
if (searches_result_line_number[1] == -1 && s >= searches_input_ptr[1]) { searches_result_line_number[1] = line_count; if (--searches_remaining <= 0) break; }
|
||||
}
|
||||
line_count++;
|
||||
if (searches_result_line_number[0] == -1) searches_result_line_number[0] = line_count;
|
||||
if (searches_result_line_number[1] == -1) searches_result_line_number[1] = line_count;
|
||||
@ -3713,9 +3714,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
break;
|
||||
if (rect_pos.y < clip_rect.y)
|
||||
{
|
||||
while (p < text_selected_end)
|
||||
if (*p++ == '\n')
|
||||
break;
|
||||
p = (const ImWchar*)wmemchr((const wchar_t*)p, '\n', text_selected_end - p) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user