aboutsummaryrefslogtreecommitdiff
path: root/vendor/rlImGui-main/examples/asset_browser/imgui_utils.cpp
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2024-09-06 22:29:38 -0500
committerNic Gaffney <gaffney_nic@protonmail.com>2024-09-06 22:29:38 -0500
commit52a2f5b69eaf3430623ef2ebeeca0c50a3b8217c (patch)
tree0fc74f5b192d74452ad74f22ad512b8b663d2139 /vendor/rlImGui-main/examples/asset_browser/imgui_utils.cpp
parentad6d55aeaa7c87a4008e56a5a3922d2608c73239 (diff)
downloadparticle-sim-52a2f5b69eaf3430623ef2ebeeca0c50a3b8217c.tar.gz
Quickfix: rlimgui bindings added to vendor/
Diffstat (limited to 'vendor/rlImGui-main/examples/asset_browser/imgui_utils.cpp')
-rw-r--r--vendor/rlImGui-main/examples/asset_browser/imgui_utils.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/vendor/rlImGui-main/examples/asset_browser/imgui_utils.cpp b/vendor/rlImGui-main/examples/asset_browser/imgui_utils.cpp
new file mode 100644
index 0000000..da87520
--- /dev/null
+++ b/vendor/rlImGui-main/examples/asset_browser/imgui_utils.cpp
@@ -0,0 +1,94 @@
+/*******************************************************************************************
+*
+* raylib-extras [ImGui] example - asset browser
+*
+* This is a more complex ImGui Integration
+* It shows how to build windows on top of 2d and 3d views using a render texture
+*
+* Copyright (c) 2024 Jeffery Myers
+*
+********************************************************************************************/
+
+#include "imgui_utils.h"
+
+#include "imgui.h"
+#include "imgui_internal.h"
+
+namespace ImGuiUtils
+{
+
+ bool IsSpace(char aCharacter)
+ {
+ // all space characters are values 32 or less (space is 32)
+ // so we can convert them to a bitmask and use a single condition
+ const int mask = (1 << (' ' - 1)) | (1 << ('\f' - 1)) | (1 << ('\n' - 1)) | (1 << ('\r' - 1)) | (1 << ('\t' - 1)) | (1 << ('\v' - 1));
+ return (mask & (1 << ((aCharacter && aCharacter <= 32) * (aCharacter - 1)))) != 0;
+ }
+
+ //-------------------------------------------------------------------------------------------------
+ // Todo: Add support for soft-hyphens when using word boundaries?
+ //-------------------------------------------------------------------------------------------------
+ void TextWithEllipsis(const char* string, float aMaxWidth, bool useWordBoundaries, float aSpacing)
+ {
+ char const* partStart = string;
+ char const* partEnd = string;
+
+ ImWchar elipsisChar = ImGui::GetFont()->EllipsisChar;
+ char elipsisText[8];
+ ImTextStrToUtf8(elipsisText, sizeof(elipsisText), &elipsisChar, (&elipsisChar) + 1);
+
+ if (aSpacing < 0.0f) aSpacing = ImGui::GetStyle().ItemSpacing.x;
+
+ float const ellipsisWidth = ImGui::CalcTextSize(elipsisText).x + aSpacing;
+ float width = 0;
+ bool addElipsis = false;
+
+ while (*partStart != 0 )
+ {
+ // Add space to next segment
+ while (IsSpace(*partEnd))
+ partEnd++;
+
+ if (useWordBoundaries)
+ {
+ // get next 'word' by looking for space after non-space
+ while (*partEnd != 0 && !IsSpace(*partEnd))
+ ++partEnd;
+ }
+ else
+ {
+ if (*partEnd != 0)
+ ++partEnd;
+ }
+
+ ImVec2 const wordSize = ImGui::CalcTextSize(partStart, partEnd);
+
+ // Clearly we have space for this word so just add it
+ if (wordSize.x + width + ellipsisWidth < aMaxWidth)
+ {
+ width += wordSize.x;
+ partStart = partEnd;
+ }
+ // If we're just at the end of the word and we just fit then we can commit here
+ else if (*partEnd == 0 && wordSize.x + width < aMaxWidth)
+ {
+ width += wordSize.x;
+ partStart = partEnd;
+ }
+ // we're done so add elipsis where the current segment starts
+ else
+ {
+ addElipsis = true;
+ break;
+ }
+ }
+
+ ImGui::TextUnformatted(string, partStart);
+
+ if (addElipsis)
+ {
+ ImGui::SameLine(0.0f, aSpacing);
+ ImGui::TextUnformatted(elipsisText);
+ }
+ }
+} \ No newline at end of file