ImStrv: made length() returns an int as it simplify the most common case (of passing %.*s to printf)

This commit is contained in:
ocornut
2024-07-02 18:50:28 +02:00
committed by ocornut
parent 8e81880e44
commit dbe36e34a5
4 changed files with 36 additions and 36 deletions

View File

@@ -1535,10 +1535,10 @@ bool ImGui::TextLinkOpenURL(ImStrv label, ImStrv url)
if (pressed && g.PlatformIO.Platform_OpenInShellFn != NULL)
{
ImStrv url_zt;
ImFormatStringToTempBuffer(&url_zt, "%.*s", (int)url.length(), url.Begin);
ImFormatStringToTempBuffer(&url_zt, "%.*s", url.length(), url.Begin);
g.PlatformIO.Platform_OpenInShellFn(&g, url_zt.Begin);
}
SetItemTooltip(LocalizeGetMsg(ImGuiLocKey_OpenLink_s), (int)url.length(), url.Begin); // It is more reassuring for user to _always_ display URL when we same as label
SetItemTooltip(LocalizeGetMsg(ImGuiLocKey_OpenLink_s), url.length(), url.Begin); // It is more reassuring for user to _always_ display URL when we same as label
if (BeginPopupContextItem())
{
if (MenuItem(LocalizeGetMsg(ImGuiLocKey_CopyLink)))
@@ -4318,7 +4318,7 @@ void ImGuiInputTextCallbackData::InsertChars(int pos, ImStrv new_text)
// Grow internal buffer if needed
const bool is_resizable = (Flags & ImGuiInputTextFlags_CallbackResize) != 0;
const int new_text_len = (int)new_text.length();
const int new_text_len = new_text.length();
if (new_text_len + BufTextLen + 1 > obj->TextA.Size && (Flags & ImGuiInputTextFlags_ReadOnly) == 0)
{
if (!is_resizable)
@@ -5153,7 +5153,7 @@ bool ImGui::InputTextEx(ImStrv label, ImStrv hint, char* buf, int buf_size, cons
if (ImStrv clipboard = GetClipboardText())
{
// Filter pasted buffer
const int clipboard_len = (int)clipboard.length();
const int clipboard_len = clipboard.length();
ImVector<char> clipboard_filtered;
clipboard_filtered.reserve(clipboard_len + 1);
for (const char* s = clipboard.Begin; *s != 0; )
@@ -8868,17 +8868,17 @@ void ImGui::PlotHistogram(ImStrv label, float (*values_getter)(void* data, int i
void ImGui::Value(ImStrv prefix, bool b)
{
Text("%.*s: %s", (int)prefix.length(), prefix.Begin, (b ? "true" : "false"));
Text("%.*s: %s", prefix.length(), prefix.Begin, (b ? "true" : "false"));
}
void ImGui::Value(ImStrv prefix, int v)
{
Text("%.*s: %d", (int)prefix.length(), prefix.Begin, v);
Text("%.*s: %d", prefix.length(), prefix.Begin, v);
}
void ImGui::Value(ImStrv prefix, unsigned int v)
{
Text("%.*s: %d", (int)prefix.length(), prefix.Begin, v);
Text("%.*s: %d", prefix.length(), prefix.Begin, v);
}
void ImGui::Value(ImStrv prefix, float v, ImStrv float_format)
@@ -8886,12 +8886,12 @@ void ImGui::Value(ImStrv prefix, float v, ImStrv float_format)
if (float_format)
{
char fmt[64];
ImFormatString(fmt, IM_ARRAYSIZE(fmt), "%%.*s: %.*s", (int)float_format.length(), float_format.Begin);
Text(fmt, (int)prefix.length(), prefix.Begin, v);
ImFormatString(fmt, IM_ARRAYSIZE(fmt), "%%.*s: %.*s", float_format.length(), float_format.Begin);
Text(fmt, prefix.length(), prefix.Begin, v);
}
else
{
Text("%.*s: %.3f", (int)prefix.length(), prefix.Begin, v);
Text("%.*s: %.3f", prefix.length(), prefix.Begin, v);
}
}