1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-16 00:54:19 +00:00

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 1d18540bf4
commit 23a93afdff
4 changed files with 36 additions and 36 deletions

View file

@ -1547,10 +1547,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)))
@ -4351,7 +4351,7 @@ void ImGuiInputTextCallbackData::InsertChars(int pos, ImStrv new_text)
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 = (int)new_text.length();
int new_text_len = new_text.length();
// We support partial insertion (with a mod in stb_textedit.h)
const int avail = BufSize - 1 - BufTextLen;
@ -5195,7 +5195,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; )
@ -8922,17 +8922,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)
@ -8940,12 +8940,12 @@ void ImGui::Value(ImStrv prefix, float v, ImStrv float_format)
if (float_format)
{
char fmt[64];
ImFormatString(fmt, IM_COUNTOF(fmt), "%%.*s: %.*s", (int)float_format.length(), float_format.Begin);
Text(fmt, (int)prefix.length(), prefix.Begin, v);
ImFormatString(fmt, IM_COUNTOF(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);
}
}