Skip to content

Commit e121e6d

Browse files
committed
[Bundle] specific binding for ColorPicker4
1 parent f087bf5 commit e121e6d

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
@@ -40,6 +40,7 @@
4040
// [ADAPT_IMGUI_BUNDLE]
4141
#ifdef IMGUI_BUNDLE_PYTHON_API
4242
#include <vector> // Used *once* to make the FontAtlas api accessible on python
43+
#include <tuple>
4344
#include <optional>
4445
#include <functional>
4546
#include <string>
@@ -692,7 +693,13 @@ namespace ImGui
692693
IMGUI_API bool ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);
693694
IMGUI_API bool ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0);
694695
IMGUI_API bool ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);
696+
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
695697
IMGUI_API bool ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags = 0, const float* ref_col = NULL);
698+
#endif
699+
#ifdef IMGUI_BUNDLE_PYTHON_API
700+
IMGUI_API std::tuple<bool, ImVec4> ColorPicker4(const std::string& label, ImVec4 col, ImGuiColorEditFlags flags = 0, std::optional<ImVec4> ref_col = std::nullopt);
701+
#endif
702+
696703
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.
697704
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.
698705

imgui_widgets.cpp

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

5722+
#ifdef IMGUI_BUNDLE_PYTHON_API
5723+
std::tuple<bool, ImVec4> ImGui::ColorPicker4(const std::string& label, ImVec4 col, ImGuiColorEditFlags flags, std::optional<ImVec4> ref_col)
5724+
{
5725+
float col_values[4] = { col.x, col.y, col.z, col.w };
5726+
if (!ImGui::ColorPicker4(label.c_str(), col_values, flags, ref_col ? &ref_col.value().x : nullptr))
5727+
return {false, col};
5728+
5729+
return {true, ImVec4(col_values[0], col_values[1], col_values[2], col_values[3])};
5730+
}
5731+
#endif
5732+
5733+
57225734
// Note: ColorPicker4() only accesses 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
57235735
// (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.)
57245736
// 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)