update Dear ImGui to 1.92.3 - comment wrap working
finally I can get rid of that silly text so much drama over a freaking setting... nobody got the reference
This commit is contained in:
parent
c0da289d40
commit
e583a49436
23 changed files with 1082 additions and 568 deletions
118
extern/imgui_patched/imgui_draw.cpp
vendored
118
extern/imgui_patched/imgui_draw.cpp
vendored
|
|
@ -1,4 +1,4 @@
|
|||
// dear imgui, v1.92.2b
|
||||
// dear imgui, v1.92.3
|
||||
// (drawing and font code)
|
||||
|
||||
/*
|
||||
|
|
@ -48,7 +48,7 @@ Index of this file:
|
|||
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
|
||||
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
|
||||
#pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2).
|
||||
#pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). [MSVC Static Analyzer)
|
||||
#pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).
|
||||
#endif
|
||||
|
||||
// Clang/GCC warnings with -Weverything
|
||||
|
|
@ -484,9 +484,10 @@ void ImDrawList::_ClearFreeMemory()
|
|||
_Splitter.ClearFreeMemory();
|
||||
}
|
||||
|
||||
// Note: For multi-threaded rendering, consider using `imgui_threaded_rendering` from https://github.com/ocornut/imgui_club
|
||||
ImDrawList* ImDrawList::CloneOutput() const
|
||||
{
|
||||
ImDrawList* dst = IM_NEW(ImDrawList(_Data));
|
||||
ImDrawList* dst = IM_NEW(ImDrawList(NULL));
|
||||
dst->CmdBuffer = CmdBuffer;
|
||||
dst->IdxBuffer = IdxBuffer;
|
||||
dst->VtxBuffer = VtxBuffer;
|
||||
|
|
@ -523,6 +524,7 @@ void ImDrawList::AddCallback(ImDrawCallback callback, void* userdata, size_t use
|
|||
{
|
||||
IM_ASSERT_PARANOID(CmdBuffer.Size > 0);
|
||||
ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
|
||||
IM_ASSERT(callback != NULL);
|
||||
IM_ASSERT(curr_cmd->UserCallback == NULL);
|
||||
if (curr_cmd->ElemCount != 0)
|
||||
{
|
||||
|
|
@ -1783,7 +1785,7 @@ void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32
|
|||
clip_rect.z = ImMin(clip_rect.z, cpu_fine_clip_rect->z);
|
||||
clip_rect.w = ImMin(clip_rect.w, cpu_fine_clip_rect->w);
|
||||
}
|
||||
font->RenderText(this, font_size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip_rect != NULL);
|
||||
font->RenderText(this, font_size, pos, col, clip_rect, text_begin, text_end, wrap_width, (cpu_fine_clip_rect != NULL) ? ImDrawTextFlags_CpuFineClip : ImDrawTextFlags_None);
|
||||
}
|
||||
|
||||
void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end)
|
||||
|
|
@ -3125,7 +3127,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in)
|
|||
else
|
||||
{
|
||||
IM_ASSERT(Fonts.Size > 0 && "Cannot use MergeMode for the first font"); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font.
|
||||
font = Fonts.back();
|
||||
font = font_cfg_in->DstFont ? font_cfg_in->DstFont : Fonts.back();
|
||||
}
|
||||
|
||||
// Add to list
|
||||
|
|
@ -3196,6 +3198,7 @@ static const char* GetDefaultCompressedFontDataTTF(int* out_size);
|
|||
#endif
|
||||
|
||||
// Load embedded ProggyClean.ttf at size 13, disable oversampling
|
||||
// If you want a similar font which may be better scaled, consider using ProggyVector from the same author!
|
||||
ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
|
||||
{
|
||||
#ifndef IMGUI_DISABLE_DEFAULT_FONT
|
||||
|
|
@ -3214,9 +3217,7 @@ ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
|
|||
|
||||
int ttf_compressed_size = 0;
|
||||
const char* ttf_compressed = GetDefaultCompressedFontDataTTF(&ttf_compressed_size);
|
||||
const ImWchar* glyph_ranges = font_cfg.GlyphRanges != NULL ? font_cfg.GlyphRanges : GetGlyphRangesDefault();
|
||||
ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, font_cfg.SizePixels, &font_cfg, glyph_ranges);
|
||||
return font;
|
||||
return AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, font_cfg.SizePixels, &font_cfg);
|
||||
#else
|
||||
IM_ASSERT(0 && "AddFontDefault() disabled in this build.");
|
||||
IM_UNUSED(font_cfg_template);
|
||||
|
|
@ -4393,6 +4394,8 @@ void ImFontAtlasPackDiscardRect(ImFontAtlas* atlas, ImFontAtlasRectId id)
|
|||
index_entry->IsUsed = false;
|
||||
index_entry->TargetIndex = builder->RectsIndexFreeListStart;
|
||||
index_entry->Generation++;
|
||||
if (index_entry->Generation == 0)
|
||||
index_entry->Generation++; // Keep non-zero on overflow
|
||||
|
||||
const int pack_padding = atlas->TexGlyphPadding;
|
||||
builder->RectsIndexFreeListStart = index_idx;
|
||||
|
|
@ -4616,16 +4619,16 @@ void ImFontAtlasDebugLogTextureRequests(ImFontAtlas* atlas)
|
|||
if (tex->Status == ImTextureStatus_WantCreate)
|
||||
IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: create %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
|
||||
else if (tex->Status == ImTextureStatus_WantDestroy)
|
||||
IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: destroy %dx%d, texid=0x%" IM_PRIX64 ", backend_data=%p\n", tex->UniqueID, tex->Width, tex->Height, tex->TexID, tex->BackendUserData);
|
||||
IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: destroy %dx%d, texid=0x%" IM_PRIX64 ", backend_data=%p\n", tex->UniqueID, tex->Width, tex->Height, IM_TEXTUREID_TO_U64(tex->TexID), tex->BackendUserData);
|
||||
else if (tex->Status == ImTextureStatus_WantUpdates)
|
||||
{
|
||||
IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: update %d regions, texid=0x%" IM_PRIX64 ", backend_data=0x%" IM_PRIX64 "\n", tex->UniqueID, tex->Updates.Size, tex->TexID, (ImU64)(intptr_t)tex->BackendUserData);
|
||||
IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: update %d regions, texid=0x%" IM_PRIX64 ", backend_data=0x%" IM_PRIX64 "\n", tex->UniqueID, tex->Updates.Size, IM_TEXTUREID_TO_U64(tex->TexID), (ImU64)(intptr_t)tex->BackendUserData);
|
||||
for (const ImTextureRect& r : tex->Updates)
|
||||
{
|
||||
IM_UNUSED(r);
|
||||
IM_ASSERT(r.x >= 0 && r.y >= 0);
|
||||
IM_ASSERT(r.x + r.w <= tex->Width && r.y + r.h <= tex->Height); // In theory should subtract PackPadding but it's currently part of atlas and mid-frame change would wreck assert.
|
||||
//IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: update (% 4d..%-4d)->(% 4d..%-4d), texid=0x%" IM_PRIX64 ", backend_data=0x%" IM_PRIX64 "\n", tex->UniqueID, r.x, r.y, r.x + r.w, r.y + r.h, tex->TexID, (ImU64)(intptr_t)tex->BackendUserData);
|
||||
//IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: update (% 4d..%-4d)->(% 4d..%-4d), texid=0x%" IM_PRIX64 ", backend_data=0x%" IM_PRIX64 "\n", tex->UniqueID, r.x, r.y, r.x + r.w, r.y + r.h, IM_TEXTUREID_TO_U64(tex->TexID), (ImU64)(intptr_t)tex->BackendUserData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5438,10 +5441,11 @@ ImFontBaked* ImFontAtlasBakedGetOrAdd(ImFontAtlas* atlas, ImFont* font, float fo
|
|||
}
|
||||
|
||||
// Trim trailing space and find beginning of next line
|
||||
static inline const char* CalcWordWrapNextLineStartA(const char* text, const char* text_end)
|
||||
const char* ImTextCalcWordWrapNextLineStart(const char* text, const char* text_end, ImDrawTextFlags flags)
|
||||
{
|
||||
while (text < text_end && ImCharIsBlankA(*text))
|
||||
text++;
|
||||
if ((flags & ImDrawTextFlags_WrapKeepBlanks) == 0)
|
||||
while (text < text_end && ImCharIsBlankA(*text))
|
||||
text++;
|
||||
if (*text == '\n')
|
||||
text++;
|
||||
return text;
|
||||
|
|
@ -5450,7 +5454,7 @@ static inline const char* CalcWordWrapNextLineStartA(const char* text, const cha
|
|||
// Simple word-wrapping for English, not full-featured. Please submit failing cases!
|
||||
// This will return the next location to wrap from. If no wrapping if necessary, this will fast-forward to e.g. text_end.
|
||||
// FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.)
|
||||
const char* ImFont::CalcWordWrapPosition(float size, const char* text, const char* text_end, float wrap_width)
|
||||
const char* ImFontCalcWordWrapPositionEx(ImFont* font, float size, const char* text, const char* text_end, float wrap_width, ImDrawTextFlags flags)
|
||||
{
|
||||
// For references, possible wrap point marked with ^
|
||||
// "aaa bbb, ccc,ddd. eee fff. ggg!"
|
||||
|
|
@ -5464,7 +5468,7 @@ const char* ImFont::CalcWordWrapPosition(float size, const char* text, const cha
|
|||
// Cut words that cannot possibly fit within one line.
|
||||
// e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"
|
||||
|
||||
ImFontBaked* baked = GetFontBaked(size);
|
||||
ImFontBaked* baked = font->GetFontBaked(size);
|
||||
const float scale = size / baked->Size;
|
||||
|
||||
float line_width = 0.0f;
|
||||
|
|
@ -5490,12 +5494,7 @@ const char* ImFont::CalcWordWrapPosition(float size, const char* text, const cha
|
|||
if (c < 32)
|
||||
{
|
||||
if (c == '\n')
|
||||
{
|
||||
line_width = word_width = blank_width = 0.0f;
|
||||
inside_word = true;
|
||||
s = next_s;
|
||||
continue;
|
||||
}
|
||||
return s; // Direct return, skip "Wrap_width is too small to fit anything" path.
|
||||
if (c == '\r')
|
||||
{
|
||||
s = next_s;
|
||||
|
|
@ -5530,6 +5529,8 @@ const char* ImFont::CalcWordWrapPosition(float size, const char* text, const cha
|
|||
{
|
||||
prev_word_end = word_end;
|
||||
line_width += word_width + blank_width;
|
||||
if ((flags & ImDrawTextFlags_WrapKeepBlanks) && line_width <= wrap_width)
|
||||
prev_word_end = s;
|
||||
word_width = blank_width = 0.0f;
|
||||
}
|
||||
|
||||
|
|
@ -5556,14 +5557,21 @@ const char* ImFont::CalcWordWrapPosition(float size, const char* text, const cha
|
|||
return s;
|
||||
}
|
||||
|
||||
ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining)
|
||||
const char* ImFont::CalcWordWrapPosition(float size, const char* text, const char* text_end, float wrap_width)
|
||||
{
|
||||
return ImFontCalcWordWrapPositionEx(this, size, text, text_end, wrap_width, ImDrawTextFlags_None);
|
||||
}
|
||||
|
||||
ImVec2 ImFontCalcTextSizeEx(ImFont* font, float size, float max_width, float wrap_width, const char* text_begin, const char* text_end_display, const char* text_end, const char** out_remaining, ImVec2* out_offset, ImDrawTextFlags flags)
|
||||
{
|
||||
if (!text_end)
|
||||
text_end = text_begin + ImStrlen(text_begin); // FIXME-OPT: Need to avoid this.
|
||||
if (!text_end_display)
|
||||
text_end_display = text_end;
|
||||
|
||||
ImFontBaked* baked = font->GetFontBaked(size);
|
||||
const float line_height = size;
|
||||
ImFontBaked* baked = GetFontBaked(size);
|
||||
const float scale = size / baked->Size;
|
||||
const float scale = line_height / baked->Size;
|
||||
|
||||
ImVec2 text_size = ImVec2(0, 0);
|
||||
float line_width = 0.0f;
|
||||
|
|
@ -5572,13 +5580,14 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
|
|||
const char* word_wrap_eol = NULL;
|
||||
|
||||
const char* s = text_begin;
|
||||
while (s < text_end)
|
||||
while (s < text_end_display)
|
||||
{
|
||||
// Word-wrapping
|
||||
if (word_wrap_enabled)
|
||||
{
|
||||
// Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
|
||||
if (!word_wrap_eol)
|
||||
word_wrap_eol = CalcWordWrapPosition(size, s, text_end, wrap_width - line_width);
|
||||
word_wrap_eol = ImFontCalcWordWrapPositionEx(font, size, s, text_end, wrap_width - line_width, flags);
|
||||
|
||||
if (s >= word_wrap_eol)
|
||||
{
|
||||
|
|
@ -5586,8 +5595,10 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
|
|||
text_size.x = line_width;
|
||||
text_size.y += line_height;
|
||||
line_width = 0.0f;
|
||||
s = ImTextCalcWordWrapNextLineStart(s, text_end, flags); // Wrapping skips upcoming blanks
|
||||
if (flags & ImDrawTextFlags_StopOnNewLine)
|
||||
break;
|
||||
word_wrap_eol = NULL;
|
||||
s = CalcWordWrapNextLineStartA(s, text_end); // Wrapping skips upcoming blanks
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -5600,18 +5611,17 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
|
|||
else
|
||||
s += ImTextCharFromUtf8(&c, s, text_end);
|
||||
|
||||
if (c < 32)
|
||||
if (c == '\n')
|
||||
{
|
||||
if (c == '\n')
|
||||
{
|
||||
text_size.x = ImMax(text_size.x, line_width);
|
||||
text_size.y += line_height;
|
||||
line_width = 0.0f;
|
||||
continue;
|
||||
}
|
||||
if (c == '\r')
|
||||
continue;
|
||||
text_size.x = ImMax(text_size.x, line_width);
|
||||
text_size.y += line_height;
|
||||
line_width = 0.0f;
|
||||
if (flags & ImDrawTextFlags_StopOnNewLine)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (c == '\r')
|
||||
continue;
|
||||
|
||||
// Optimized inline version of 'float char_width = GetCharAdvance((ImWchar)c);'
|
||||
float char_width = (c < (unsigned int)baked->IndexAdvanceX.Size) ? baked->IndexAdvanceX.Data[c] : -1.0f;
|
||||
|
|
@ -5631,15 +5641,23 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
|
|||
if (text_size.x < line_width)
|
||||
text_size.x = line_width;
|
||||
|
||||
if (line_width > 0 || text_size.y == 0.0f)
|
||||
if (out_offset != NULL)
|
||||
*out_offset = ImVec2(line_width, text_size.y + line_height); // offset allow for the possibility of sitting after a trailing \n
|
||||
|
||||
if (line_width > 0 || text_size.y == 0.0f) // whereas size.y will ignore the trailing \n
|
||||
text_size.y += line_height;
|
||||
|
||||
if (remaining)
|
||||
*remaining = s;
|
||||
if (out_remaining != NULL)
|
||||
*out_remaining = s;
|
||||
|
||||
return text_size;
|
||||
}
|
||||
|
||||
ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** out_remaining)
|
||||
{
|
||||
return ImFontCalcTextSizeEx(this, size, max_width, wrap_width, text_begin, text_end, text_end, out_remaining, NULL, ImDrawTextFlags_None);
|
||||
}
|
||||
|
||||
// Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound.
|
||||
void ImFont::RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, ImWchar c, const ImVec4* cpu_fine_clip)
|
||||
{
|
||||
|
|
@ -5680,7 +5698,8 @@ void ImFont::RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, Im
|
|||
}
|
||||
|
||||
// Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound.
|
||||
void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip)
|
||||
// DO NOT CALL DIRECTLY THIS WILL CHANGE WIDLY IN 2025-2025. Use ImDrawList::AddText().
|
||||
void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, ImDrawTextFlags flags)
|
||||
{
|
||||
// Align to be pixel perfect
|
||||
begin:
|
||||
|
|
@ -5710,8 +5729,8 @@ begin:
|
|||
// FIXME-OPT: This is not optimal as do first do a search for \n before calling CalcWordWrapPosition().
|
||||
// If the specs for CalcWordWrapPosition() were reworked to optionally return on \n we could combine both.
|
||||
// However it is still better than nothing performing the fast-forward!
|
||||
s = CalcWordWrapPosition(size, s, line_end ? line_end : text_end, wrap_width);
|
||||
s = CalcWordWrapNextLineStartA(s, text_end);
|
||||
s = ImFontCalcWordWrapPositionEx(this, size, s, line_end ? line_end : text_end, wrap_width, flags);
|
||||
s = ImTextCalcWordWrapNextLineStart(s, text_end, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -5746,6 +5765,7 @@ begin:
|
|||
ImDrawIdx* idx_write = draw_list->_IdxWritePtr;
|
||||
unsigned int vtx_index = draw_list->_VtxCurrentIdx;
|
||||
const int cmd_count = draw_list->CmdBuffer.Size;
|
||||
const bool cpu_fine_clip = (flags & ImDrawTextFlags_CpuFineClip) != 0;
|
||||
|
||||
const ImU32 col_untinted = col | ~IM_COL32_A_MASK;
|
||||
const char* word_wrap_eol = NULL;
|
||||
|
|
@ -5756,7 +5776,7 @@ begin:
|
|||
{
|
||||
// Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
|
||||
if (!word_wrap_eol)
|
||||
word_wrap_eol = CalcWordWrapPosition(size, s, text_end, wrap_width - (x - origin_x));
|
||||
word_wrap_eol = ImFontCalcWordWrapPositionEx(this, size, s, text_end, wrap_width - (x - origin_x), flags);
|
||||
|
||||
if (s >= word_wrap_eol)
|
||||
{
|
||||
|
|
@ -5765,7 +5785,7 @@ begin:
|
|||
if (y > clip_rect.w)
|
||||
break; // break out of main loop
|
||||
word_wrap_eol = NULL;
|
||||
s = CalcWordWrapNextLineStartA(s, text_end); // Wrapping skips upcoming blanks
|
||||
s = ImTextCalcWordWrapNextLineStart(s, text_end, flags); // Wrapping skips upcoming blanks
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -5934,8 +5954,9 @@ void ImGui::RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir d
|
|||
|
||||
void ImGui::RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col)
|
||||
{
|
||||
// FIXME-OPT: This should be baked in font.
|
||||
draw_list->AddCircleFilled(pos, draw_list->_Data->FontSize * 0.20f, col, 8);
|
||||
// FIXME-OPT: This should be baked in font now that it's easier.
|
||||
float font_size = draw_list->_Data->FontSize;
|
||||
draw_list->AddCircleFilled(pos, font_size * 0.20f, col, (font_size < 22) ? 8 : (font_size < 40) ? 12 : 0); // Hardcode optimal/nice tessellation threshold
|
||||
}
|
||||
|
||||
void ImGui::RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz)
|
||||
|
|
@ -6237,6 +6258,7 @@ static unsigned int stb_decompress(unsigned char *output, const unsigned char *i
|
|||
// Copyright (c) 2004, 2005 Tristan Grimmer
|
||||
// MIT license (see License.txt in http://www.proggyfonts.net/index.php?menu=download)
|
||||
// Download and more information at http://www.proggyfonts.net or http://upperboundsinteractive.com/fonts.php
|
||||
// If you want a similar font which may be better scaled, consider using ProggyVector from the same author!
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef IMGUI_DISABLE_DEFAULT_FONT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue