Skip to content

Commit a7cb079

Browse files
committed
[Bundle] specific binding for ColorPicker4
1 parent 5be1614 commit a7cb079

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

imgui.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
// [ADAPT_IMGUI_BUNDLE]
4242
#ifdef IMGUI_BUNDLE_PYTHON_API
4343
#include <vector> // Used *once* to make the FontAtlas api accessible on python
44+
#include <tuple>
4445
#include <optional>
4546
#include <functional>
4647
#include <string>
@@ -756,7 +757,13 @@ namespace ImGui
756757
IMGUI_API bool ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);
757758
IMGUI_API bool ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0);
758759
IMGUI_API bool ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);
760+
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
759761
IMGUI_API bool ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags = 0, const float* ref_col = NULL);
762+
#endif
763+
#ifdef IMGUI_BUNDLE_PYTHON_API
764+
IMGUI_API std::tuple<bool, ImVec4> ColorPicker4(const std::string& label, ImVec4 col, ImGuiColorEditFlags flags = 0, std::optional<ImVec4> ref_col = std::nullopt);
765+
#endif
766+
760767
IMGUI_API bool ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFlags flags = 0, const ImVec2& size = ImVec2(0, 0)); // display a color square/button, hover for details, return true when pressed.
761768
IMGUI_API void SetColorEditOptions(ImGuiColorEditFlags flags); // initialize current options (generally on application startup) if you want to select a default format, picker type, etc. User will be able to change many settings, unless you pass the _NoOptions flag to your calls.
762769

imgui_widgets.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5855,6 +5855,18 @@ static void RenderArrowsForVerticalBar(ImDrawList* draw_list, ImVec2 pos, ImVec2
58555855
ImGui::RenderArrowPointingAt(draw_list, ImVec2(pos.x + bar_w - half_sz.x, pos.y), half_sz, ImGuiDir_Left, IM_COL32(255,255,255,alpha8));
58565856
}
58575857

5858+
#ifdef IMGUI_BUNDLE_PYTHON_API
5859+
std::tuple<bool, ImVec4> ImGui::ColorPicker4(const std::string& label, ImVec4 col, ImGuiColorEditFlags flags, std::optional<ImVec4> ref_col)
5860+
{
5861+
float col_values[4] = { col.x, col.y, col.z, col.w };
5862+
if (!ImGui::ColorPicker4(label.c_str(), col_values, flags, ref_col ? &ref_col.value().x : nullptr))
5863+
return {false, col};
5864+
5865+
return {true, ImVec4(col_values[0], col_values[1], col_values[2], col_values[3])};
5866+
}
5867+
#endif
5868+
5869+
58585870
// Note: ColorPicker4() only accesses 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
58595871
// (In C++ the 'float col[4]' notation for a function argument is equivalent to 'float* col', we only specify a size to facilitate understanding of the code.)
58605872
// FIXME: we adjust the big color square height based on item width, which may cause a flickering feedback loop (if automatic height makes a vertical scrollbar appears, affecting automatic width..)

0 commit comments

Comments
 (0)