Browse Source

Update to work with current ImGui and build on a mac

Jeffery Myers 1 year ago
parent
commit
50779c5e76
3 changed files with 26 additions and 13 deletions
  1. 18 7
      examples/asset_browser/asset_browser.cpp
  2. 1 1
      examples/editor.cpp
  3. 7 5
      rlImGui.cpp

+ 18 - 7
examples/asset_browser/asset_browser.cpp

@@ -18,6 +18,8 @@
 #include "raylib.h"
 #include "extras/IconsFontAwesome6.h"
 
+#include <algorithm>
+
 
 AssetBrowserPanel::AssetBrowserPanel()
 {
@@ -246,23 +248,32 @@ ViewableItem* AssetBrowserPanel::AssetContainer::Next()
 
 const char* AssetBrowserPanel::GetFileIcon(const char* filename)
 {
-    const char* ext = GetFileExtension(filename);
+    const char* e = GetFileExtension(filename);
+
+    if (e == nullptr)
+        return ICON_FA_FILE;
+
+    std::string ext = e;
+
+    std::transform(ext.begin(), ext.end(), ext.begin(),
+        [](unsigned char c) { return std::tolower(c); } // correct
+    );
 
-    if (ext != nullptr)
+    if (!ext.empty())
     {
-        if (stricmp(ext, ".png") == 0)
+        if (ext==".png")
             return ICON_FA_FILE_IMAGE;
 
-        if (stricmp(ext, ".wav") == 0 || stricmp(ext, ".mp3") == 0 || stricmp(ext, ".oog") == 0)
+        if (ext==".wav" || ext==".mp3" || ext==".oog")
             return ICON_FA_FILE_AUDIO;
 
-        if (stricmp(ext, ".ttf") == 0 || stricmp(ext, ".otf") == 0 || stricmp(ext, ".fnt") == 0)
+        if (ext==".ttf" || ext==".otf" || ext==".fnt")
             return ICON_FA_FONT;
 
-        if (stricmp(ext, ".txt") == 0 || stricmp(ext, ".md") == 0)
+        if (ext==".txt" || ext==".md")
             return ICON_FA_FILE_LINES;
 
-        if (stricmp(ext, ".lua") == 0 || stricmp(ext, ".c") == 0 || stricmp(ext, ".h") == 0 || stricmp(ext, ".cpp") == 0)
+        if (ext==".lua" || ext==".c" || ext==".h" || ext==".cpp")
             return ICON_FA_FILE_CODE;
     }
     return ICON_FA_FILE;

+ 1 - 1
examples/editor.cpp

@@ -67,7 +67,7 @@ public:
 		if (ImGui::Begin("Image Viewer", &Open, ImGuiWindowFlags_NoScrollbar))
 		{
 			// save off the screen space content rectangle
-			ContentRect = { ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMin().x, ImGui::GetWindowPos().y + ImGui::GetWindowContentRegionMin().y, ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y };
+			ContentRect = { ImGui::GetWindowPos().x + ImGui::GetCursorScreenPos().x, ImGui::GetWindowPos().y + ImGui::GetCursorScreenPos().y, ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y };
 
 			Focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows);
 

+ 7 - 5
rlImGui.cpp

@@ -87,12 +87,12 @@ void ReloadFonts(void)
     io.Fonts->TexID = fontTexture;
 }
 
-static const char* GetClipTextCallback(void*) 
+static const char* GetClipTextCallback(ImGuiContext*)
 {
     return GetClipboardText();
 }
 
-static void SetClipTextCallback(void*, const char* text)
+static void SetClipTextCallback(ImGuiContext*, const char* text)
 {
     SetClipboardText(text);
 }
@@ -290,10 +290,12 @@ void SetupBackend(void)
 
     io.MousePos = ImVec2(0, 0);
 
-    io.SetClipboardTextFn = SetClipTextCallback;
-    io.GetClipboardTextFn = GetClipTextCallback;
+    ImGuiPlatformIO& platformIO = ImGui::GetPlatformIO();
 
-    io.ClipboardUserData = nullptr;
+    platformIO.Platform_SetClipboardTextFn = SetClipTextCallback;
+    platformIO.Platform_GetClipboardTextFn = GetClipTextCallback;
+
+    platformIO.Platform_ClipboardUserData = nullptr;
 }
 
 void rlImGuiEndInitImGui(void)