Skip to content

Commit e8f6f6d

Browse files
committed
[Bundle] specific binding for ColorPicker4
1 parent 9774670 commit e8f6f6d

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>
@@ -689,7 +690,13 @@ namespace ImGui
689690
IMGUI_API bool ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);
690691
IMGUI_API bool ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0);
691692
IMGUI_API bool ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);
693+
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
692694
IMGUI_API bool ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags = 0, const float* ref_col = NULL);
695+
#endif
696+
#ifdef IMGUI_BUNDLE_PYTHON_API
697+
IMGUI_API std::tuple<bool, ImVec4> ColorPicker4(const std::string& label, ImVec4 col, ImGuiColorEditFlags flags = 0, std::optional<ImVec4> ref_col = std::nullopt);
698+
#endif
699+
693700
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.
694701
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.
695702

imgui_widgets.cpp

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

5661+
#ifdef IMGUI_BUNDLE_PYTHON_API
5662+
std::tuple<bool, ImVec4> ImGui::ColorPicker4(const std::string& label, ImVec4 col, ImGuiColorEditFlags flags, std::optional<ImVec4> ref_col)
5663+
{
5664+
float col_values[4] = { col.x, col.y, col.z, col.w };
5665+
if (!ImGui::ColorPicker4(label.c_str(), col_values, flags, ref_col ? &ref_col.value().x : nullptr))
5666+
return {false, col};
5667+
5668+
return {true, ImVec4(col_values[0], col_values[1], col_values[2], col_values[3])};
5669+
}
5670+
#endif
5671+
5672+
56615673
// Note: ColorPicker4() only accesses 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
56625674
// (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.)
56635675
// 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)