1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-12 02:00:58 +01:00

IO: (BREAKING) moved GetIO().PlatformOpenInShellFn to GetPlatformIO(.Platform_OpenInShellFn. (#7660)

This commit is contained in:
ocornut 2024-08-22 16:42:57 +02:00
parent e6460722ea
commit ba2f4a2cd5
7 changed files with 34 additions and 16 deletions

View File

@ -20,6 +20,8 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2024-08-22: Follow up on function pointers moved from ImGuiIO to ImGuiPlatformIO:
// - io.PlatformOpenInShellFn -> platform_io.Platform_OpenInShellFn
// 2024-07-31: Added ImGui_ImplGlfw_Sleep() helper function for usage by our examples app, since GLFW doesn't provide one.
// 2024-07-08: *BREAKING* Renamed ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback to ImGui_ImplGlfw_InstallEmscriptenCallbacks(), added GLFWWindow* parameter.
// 2024-07-08: Emscripten: Added support for GLFW3 contrib port (GLFW 3.4.0 features + bug fixes): to enable, replace -sUSE_GLFW=3 with --use-port=contrib.glfw3 (requires emscripten 3.1.59+) (https://github.com/pongasoft/emscripten-glfw)
@ -586,10 +588,11 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
bd->Window = window;
bd->Time = 0.0;
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
#ifdef __EMSCRIPTEN__
io.PlatformOpenInShellFn = [](ImGuiContext*, const char* url) { ImGui_ImplGlfw_EmscriptenOpenURL(url); return true; };
platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { ImGui_ImplGlfw_EmscriptenOpenURL(url); return true; };
#endif
// Create mouse cursors

View File

@ -21,6 +21,8 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2024-08-22: Follow up on function pointers moved from ImGuiIO to ImGuiPlatformIO:
// - io.PlatformOpenInShellFn -> platform_io.Platform_OpenInShellFn
// 2024-08-19: Storing SDL's Uint32 WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
// 2024-08-19: ImGui_ImplSDL2_ProcessEvent() now ignores events intended for other SDL windows. (#7853)
// 2024-07-02: Emscripten: Added io.PlatformOpenInShellFn() handler for Emscripten versions.
@ -458,12 +460,13 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void
bd->Renderer = renderer;
bd->MouseCanUseGlobalState = mouse_can_use_global_state;
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
io.ClipboardUserData = nullptr;
io.PlatformSetImeDataFn = ImGui_ImplSDL2_PlatformSetImeData;
#ifdef __EMSCRIPTEN__
io.PlatformOpenInShellFn = [](ImGuiContext*, const char* url) { ImGui_ImplSDL2_EmscriptenOpenURL(url); return true; };
platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { ImGui_ImplSDL2_EmscriptenOpenURL(url); return true; };
#endif
// Gamepad handling

View File

@ -41,6 +41,10 @@ HOW TO UPDATE?
Breaking changes:
- IO: moved some functions from ImGuiIO to ImGuiPlatformIO:
- io.PlatformOpenInShellFn -> platform_io.Platform_OpenInShellFn. (#7660)
- access those via GetPlatformIO() instead of GetIO().
Other changes:
- IO: Added GetPlatformIO() and ImGuiPlatformIO, pulled from 'docking' branch, which
@ -114,6 +118,7 @@ Other changes:
- Added TextLink(), TextLinkOpenURL() hyperlink widgets. (#7660)
- IO: added io.PlatformOpenInShellFn handler to open a link/folder/file in OS shell. (#7660)
(*EDIT* From next version 1.91.1 we moved this to platform_io.Platform_OpenInShellFn *EDIT**)
Added IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS to disable default Windows/Linux/Mac implementations.
- IO: added io.ConfigNavSwapGamepadButtons to swap Activate/Cancel (A<>B) buttons, to match the
typical "Nintendo/Japanese consoles" button layout when using Gamepad navigation. (#787, #5723)

View File

@ -43,7 +43,7 @@
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
//#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS // Don't implement default io.PlatformOpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
//#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)

View File

@ -430,6 +430,10 @@ CODE
When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
- 2024/08/22 (1.91.1) - moved some functions from ImGuiIO to ImGuiPlatformIO structure:
- io.PlatformOpenInShellFn -> platform_io.Platform_OpenInShellFn. (#7660)
- access those via GetPlatformIO() instead of GetIO().
some were introduced very recently and often automatically setup by core library and backends, so for those we are exceptionally not maintaining a legacy redirection symbol.
- 2024/07/25 (1.91.0) - obsoleted GetContentRegionMax(), GetWindowContentRegionMin() and GetWindowContentRegionMax(). (see #7838 on GitHub for more info)
you should never need those functions. you can do everything with GetCursorScreenPos() and GetContentRegionAvail() in a more simple way.
- instead of: GetWindowContentRegionMax().x - GetCursorPos().x
@ -1144,7 +1148,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext*, ImGuiSetti
static const char* GetClipboardTextFn_DefaultImpl(void* user_data_ctx);
static void SetClipboardTextFn_DefaultImpl(void* user_data_ctx, const char* text);
static void PlatformSetImeDataFn_DefaultImpl(ImGuiContext* ctx, ImGuiViewport* viewport, ImGuiPlatformImeData* data);
static bool PlatformOpenInShellFn_DefaultImpl(ImGuiContext* ctx, const char* path);
static bool Platform_OpenInShellFn_DefaultImpl(ImGuiContext* ctx, const char* path);
namespace ImGui
{
@ -1393,7 +1397,6 @@ ImGuiIO::ImGuiIO()
// Note: Initialize() will setup default clipboard/ime handlers.
BackendPlatformName = BackendRendererName = NULL;
BackendPlatformUserData = BackendRendererUserData = BackendLanguageUserData = NULL;
PlatformOpenInShellUserData = NULL;
PlatformLocaleDecimalPoint = '.';
// Input (NB: we already have memset zero the entire structure!)
@ -3805,7 +3808,7 @@ void ImGui::Initialize()
g.IO.GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
g.IO.SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
g.IO.ClipboardUserData = (void*)&g; // Default implementation use the ImGuiContext as user data (ideally those would be arguments to the function)
g.IO.PlatformOpenInShellFn = PlatformOpenInShellFn_DefaultImpl;
g.PlatformIO.Platform_OpenInShellFn = Platform_OpenInShellFn_DefaultImpl;
g.IO.PlatformSetImeDataFn = PlatformSetImeDataFn_DefaultImpl;
// Create default viewport
@ -14477,14 +14480,14 @@ static void SetClipboardTextFn_DefaultImpl(void* user_data_ctx, const char* text
#ifdef _MSC_VER
#pragma comment(lib, "shell32")
#endif
static bool PlatformOpenInShellFn_DefaultImpl(ImGuiContext*, const char* path)
static bool Platform_OpenInShellFn_DefaultImpl(ImGuiContext*, const char* path)
{
return (INT_PTR)::ShellExecuteA(NULL, "open", path, NULL, NULL, SW_SHOWDEFAULT) > 32;
}
#else
#include <sys/wait.h>
#include <unistd.h>
static bool PlatformOpenInShellFn_DefaultImpl(ImGuiContext*, const char* path)
static bool Platform_OpenInShellFn_DefaultImpl(ImGuiContext*, const char* path)
{
#if defined(__APPLE__)
const char* args[] { "open", "--", path, NULL };
@ -14508,7 +14511,7 @@ static bool PlatformOpenInShellFn_DefaultImpl(ImGuiContext*, const char* path)
}
#endif
#else
static bool PlatformOpenInShellFn_DefaultImpl(ImGuiContext*, const char*) { return false; }
static bool Platform_OpenInShellFn_DefaultImpl(ImGuiContext*, const char*) { return false; }
#endif // Default shell handlers
//-----------------------------------------------------------------------------

14
imgui.h
View File

@ -2295,11 +2295,6 @@ struct ImGuiIO
void (*SetClipboardTextFn)(void* user_data, const char* text);
void* ClipboardUserData;
// Optional: Open link/folder/file in OS Shell
// (default to use ShellExecuteA() on Windows, system() on Linux/Mac)
bool (*PlatformOpenInShellFn)(ImGuiContext* ctx, const char* path);
void* PlatformOpenInShellUserData;
// Optional: Notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese IME on Windows)
// (default to use native imm32 api on Windows)
void (*PlatformSetImeDataFn)(ImGuiContext* ctx, ImGuiViewport* viewport, ImGuiPlatformImeData* data);
@ -3491,6 +3486,15 @@ struct ImGuiViewport
struct ImGuiPlatformIO
{
IMGUI_API ImGuiPlatformIO();
//------------------------------------------------------------------
// Inputs - Interface with OS/backends
//------------------------------------------------------------------
// Optional: Open link/folder/file in OS Shell
// (default to use ShellExecuteA() on Windows, system() on Linux/Mac)
bool (*Platform_OpenInShellFn)(ImGuiContext* ctx, const char* path);
void* Platform_OpenInShellUserData;
};
// (Optional) Support for IME (Input Method Editor) via the io.PlatformSetImeDataFn() function.

View File

@ -1462,8 +1462,8 @@ void ImGui::TextLinkOpenURL(const char* label, const char* url)
if (url == NULL)
url = label;
if (TextLink(label))
if (g.IO.PlatformOpenInShellFn != NULL)
g.IO.PlatformOpenInShellFn(&g, url);
if (g.PlatformIO.Platform_OpenInShellFn != NULL)
g.PlatformIO.Platform_OpenInShellFn(&g, url);
SetItemTooltip("%s", url); // It is more reassuring for user to _always_ display URL when we same as label
if (BeginPopupContextItem())
{