Skip to content

Commit

Permalink
ADAPT_IMGUI_BUNDLE: publish Get/SetClipboardTextFn_ and SetPlatformIm…
Browse files Browse the repository at this point in the history
…eDataFn as std::function for python
  • Loading branch information
pthom committed Nov 6, 2023
1 parent 729439f commit 46b5beb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4394,12 +4394,27 @@ void ImGui::DebugAllocHook(ImGuiDebugAllocInfo* info, int frame_count, void* ptr
const char* ImGui::GetClipboardText()
{
ImGuiContext& g = *GImGui;
#ifdef IMGUI_BUNDLE_PYTHON_API
static std::string clipboard_content;
if (g.IO.GetClipboardTextFn_)
{
clipboard_content = g.IO.GetClipboardTextFn_();
return clipboard_content.c_str();
}
#endif
return g.IO.GetClipboardTextFn ? g.IO.GetClipboardTextFn(g.IO.ClipboardUserData) : "";
}

void ImGui::SetClipboardText(const char* text)
{
ImGuiContext& g = *GImGui;
#ifdef IMGUI_BUNDLE_PYTHON_API
if (g.IO.SetClipboardTextFn_)
{
g.IO.SetClipboardTextFn_(std::string(text));
return;
}
#endif
if (g.IO.SetClipboardTextFn)
g.IO.SetClipboardTextFn(g.IO.ClipboardUserData, text);
}
Expand Down
15 changes: 15 additions & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#ifdef IMGUI_BUNDLE_PYTHON_API
#include <vector> // Used *once* to make the FontAtlas api accessible on python
#include <optional>
#include <functional>
#endif
// IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API is always defined (even when building python bindings),
// but is used as a marker to exclude certain functions from the python binding code.
Expand Down Expand Up @@ -2203,15 +2204,29 @@ struct ImGuiIO
void* BackendRendererUserData; // = NULL // User data for renderer backend
void* BackendLanguageUserData; // = NULL // User data for non C++ programming language backend

// [ADAPT_IMGUI_BUNDLE]
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
// Optional: Access OS clipboard
// (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures)
const char* (*GetClipboardTextFn)(void* user_data);
void (*SetClipboardTextFn)(void* user_data, const char* text);
void* ClipboardUserData;
#endif
#ifdef IMGUI_BUNDLE_PYTHON_API
// Optional: Access OS clipboard
// (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures)
std::function<std::string()> GetClipboardTextFn_;
std::function<void(std::string)> SetClipboardTextFn_;
#endif
// [/ADAPT_IMGUI_BUNDLE]

// 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)
#ifdef IMGUI_BUNDLE_PYTHON_API
std::function<void(ImGuiViewport*, ImGuiPlatformImeData*)> SetPlatformImeDataFn;
#else
void (*SetPlatformImeDataFn)(ImGuiViewport* viewport, ImGuiPlatformImeData* data);
#endif

// Optional: Platform locale
ImWchar PlatformLocaleDecimalPoint; // '.' // [Experimental] Configure decimal point e.g. '.' or ',' useful for some languages (e.g. German), generally pulled from *localeconv()->decimal_point
Expand Down

0 comments on commit 46b5beb

Please sign in to comment.