From 761a3029d3c0d8d6b75e39e207415df881660db9 Mon Sep 17 00:00:00 2001 From: Merlin Nimier-David Date: Wed, 7 Jan 2026 14:55:45 +0100 Subject: [PATCH 1/2] ImGui: fix optional `const char *` arguments --- src/cpp/imgui/imgui_api_columns_legacy.cpp | 6 +++++- src/cpp/imgui/imgui_api_data_plotting.cpp | 22 +++++++++++++++------- src/cpp/imgui/imgui_api_logging.cpp | 6 +++++- src/cpp/imgui/imgui_api_menus.cpp | 6 ++++-- src/cpp/imgui/imgui_api_popups.cpp | 16 +++++++++------- src/cpp/imgui/imgui_api_widgets_drag.cpp | 12 +++++------- src/cpp/imgui/imgui_api_widgets_main.cpp | 12 ++++++------ src/cpp/imgui/imgui_utils.h | 9 ++++++++- 8 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/cpp/imgui/imgui_api_columns_legacy.cpp b/src/cpp/imgui/imgui_api_columns_legacy.cpp index dff9b50..f2e7596 100644 --- a/src/cpp/imgui/imgui_api_columns_legacy.cpp +++ b/src/cpp/imgui/imgui_api_columns_legacy.cpp @@ -7,6 +7,8 @@ #include "imgui_utils.h" #include +#include +#include // clang-format off void bind_imgui_api_columns_legacy(nb::module_& m) { @@ -15,7 +17,9 @@ void bind_imgui_api_columns_legacy(nb::module_& m) { // IMGUI_API void Columns(int count = 1, const char* id = NULL, bool borders = true); m.def( "Columns", - [](int count, const char* id, bool borders) { ImGui::Columns(count, id, borders); }, + [](int count, std::optional id, bool borders) { + ImGui::Columns(count, to_char_ptr(id), borders); + }, nb::arg("count") = 1, nb::arg("id") = nb::none(), nb::arg("borders") = true); diff --git a/src/cpp/imgui/imgui_api_data_plotting.cpp b/src/cpp/imgui/imgui_api_data_plotting.cpp index 601cb16..49ce99a 100644 --- a/src/cpp/imgui/imgui_api_data_plotting.cpp +++ b/src/cpp/imgui/imgui_api_data_plotting.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include // clang-format off void bind_imgui_api_data_plotting(nb::module_& m) { @@ -16,8 +18,10 @@ void bind_imgui_api_data_plotting(nb::module_& m) { // IMGUI_API void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float)); m.def( "PlotLines", - [](const char* label, const Eigen::Ref& values, int values_offset, const char* overlay_text, float scale_min, float scale_max, const Vec2T& graph_size) { - ImGui::PlotLines(label, values.data(), static_cast(values.size()), values_offset, overlay_text, scale_min, scale_max, to_vec2(graph_size)); + [](const char* label, const Eigen::Ref& values, int values_offset, + std::optional overlay_text, float scale_min, float scale_max, const Vec2T& graph_size) { + ImGui::PlotLines(label, values.data(), static_cast(values.size()), + values_offset, to_char_ptr(overlay_text), scale_min, scale_max, to_vec2(graph_size)); }, nb::arg("label"), nb::arg("values"), @@ -25,7 +29,8 @@ void bind_imgui_api_data_plotting(nb::module_& m) { nb::arg("overlay_text") = nb::none(), nb::arg("scale_min") = FLT_MAX, nb::arg("scale_max") = FLT_MAX, - nb::arg("graph_size") = Vec2T(0.f, 0.f)); + nb::arg("graph_size") = Vec2T(0.f, 0.f) + ); // IMGUI_API void PlotLines(const char* label, float(*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0)); // TODO: Callback version not bound @@ -33,8 +38,10 @@ void bind_imgui_api_data_plotting(nb::module_& m) { // IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float)); m.def( "PlotHistogram", - [](const char* label, const Eigen::Ref& values, int values_offset, const char* overlay_text, float scale_min, float scale_max, const Vec2T& graph_size) { - ImGui::PlotHistogram(label, values.data(), static_cast(values.size()), values_offset, overlay_text, scale_min, scale_max, to_vec2(graph_size)); + [](const char* label, const Eigen::Ref& values, int values_offset, + std::optional overlay_text, float scale_min, float scale_max, const Vec2T& graph_size) { + ImGui::PlotHistogram(label, values.data(), static_cast(values.size()), + values_offset, to_char_ptr(overlay_text), scale_min, scale_max, to_vec2(graph_size)); }, nb::arg("label"), nb::arg("values"), @@ -42,7 +49,8 @@ void bind_imgui_api_data_plotting(nb::module_& m) { nb::arg("overlay_text") = nb::none(), nb::arg("scale_min") = FLT_MAX, nb::arg("scale_max") = FLT_MAX, - nb::arg("graph_size") = Vec2T(0.f, 0.f)); + nb::arg("graph_size") = Vec2T(0.f, 0.f) + ); // IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0)); // TODO: Callback version not bound @@ -71,7 +79,7 @@ void bind_imgui_api_data_plotting(nb::module_& m) { // IMGUI_API void Value(const char* prefix, float v, const char* float_format = NULL); m.def( "Value", - [](const char* prefix, float v, const char* float_format) { ImGui::Value(prefix, v, float_format); }, + [](const char* prefix, float v, std::optional float_format) { ImGui::Value(prefix, v, to_char_ptr(float_format)); }, nb::arg("prefix"), nb::arg("v"), nb::arg("float_format") = nb::none()); diff --git a/src/cpp/imgui/imgui_api_logging.cpp b/src/cpp/imgui/imgui_api_logging.cpp index bd9fd63..7254483 100644 --- a/src/cpp/imgui/imgui_api_logging.cpp +++ b/src/cpp/imgui/imgui_api_logging.cpp @@ -7,6 +7,8 @@ #include "imgui_utils.h" #include +#include +#include // clang-format off void bind_imgui_api_logging(nb::module_& m) { @@ -21,7 +23,9 @@ void bind_imgui_api_logging(nb::module_& m) { // IMGUI_API void LogToFile(int auto_open_depth = -1, const char* filename = NULL); m.def( "LogToFile", - [](int auto_open_depth, const char* filename) { ImGui::LogToFile(auto_open_depth, filename); }, + [](int auto_open_depth, std::optional filename) { + ImGui::LogToFile(auto_open_depth, to_char_ptr(filename)); + }, nb::arg("auto_open_depth") = -1, nb::arg("filename") = nb::none()); diff --git a/src/cpp/imgui/imgui_api_menus.cpp b/src/cpp/imgui/imgui_api_menus.cpp index 0c16e01..36712c0 100644 --- a/src/cpp/imgui/imgui_api_menus.cpp +++ b/src/cpp/imgui/imgui_api_menus.cpp @@ -7,6 +7,8 @@ #include "imgui_utils.h" #include +#include +#include // clang-format off void bind_imgui_api_menus(nb::module_& m) { @@ -37,8 +39,8 @@ void bind_imgui_api_menus(nb::module_& m) { // IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); m.def( "MenuItem", - [](const char* label, const char* shortcut, bool selected, bool enabled) { - return ImGui::MenuItem(label, shortcut, selected, enabled); + [](const char* label, std::optional shortcut, bool selected, bool enabled) { + return ImGui::MenuItem(label, to_char_ptr(shortcut), selected, enabled); }, nb::arg("label"), nb::arg("shortcut") = nb::none(), diff --git a/src/cpp/imgui/imgui_api_popups.cpp b/src/cpp/imgui/imgui_api_popups.cpp index 8081c23..02c0d19 100644 --- a/src/cpp/imgui/imgui_api_popups.cpp +++ b/src/cpp/imgui/imgui_api_popups.cpp @@ -7,6 +7,8 @@ #include "imgui_utils.h" #include +#include +#include // clang-format off void bind_imgui_api_popups(nb::module_& m) { @@ -59,7 +61,7 @@ void bind_imgui_api_popups(nb::module_& m) { // IMGUI_API void OpenPopupOnItemClick(const char* str_id = NULL, ImGuiPopupFlags popup_flags = 1); m.def( "OpenPopupOnItemClick", - [](const char* str_id, ImGuiPopupFlags popup_flags) { ImGui::OpenPopupOnItemClick(str_id, popup_flags); }, + [](std::optional str_id, ImGuiPopupFlags popup_flags) { ImGui::OpenPopupOnItemClick(to_char_ptr(str_id), popup_flags); }, nb::arg("str_id") = nb::none(), nb::arg("popup_flags") = 1); @@ -70,8 +72,8 @@ void bind_imgui_api_popups(nb::module_& m) { // IMGUI_API bool BeginPopupContextItem(const char* str_id = NULL, ImGuiPopupFlags popup_flags = 1); m.def( "BeginPopupContextItem", - [](const char* str_id, ImGuiPopupFlags popup_flags) { - return ImGui::BeginPopupContextItem(str_id, popup_flags); + [](std::optional str_id, ImGuiPopupFlags popup_flags) { + return ImGui::BeginPopupContextItem(to_char_ptr(str_id), popup_flags); }, nb::arg("str_id") = nb::none(), nb::arg("popup_flags") = 1); @@ -79,8 +81,8 @@ void bind_imgui_api_popups(nb::module_& m) { // IMGUI_API bool BeginPopupContextWindow(const char* str_id = NULL, ImGuiPopupFlags popup_flags = 1); m.def( "BeginPopupContextWindow", - [](const char* str_id, ImGuiPopupFlags popup_flags) { - return ImGui::BeginPopupContextWindow(str_id, popup_flags); + [](std::optional str_id, ImGuiPopupFlags popup_flags) { + return ImGui::BeginPopupContextWindow(to_char_ptr(str_id), popup_flags); }, nb::arg("str_id") = nb::none(), nb::arg("popup_flags") = 1); @@ -88,8 +90,8 @@ void bind_imgui_api_popups(nb::module_& m) { // IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, ImGuiPopupFlags popup_flags = 1); m.def( "BeginPopupContextVoid", - [](const char* str_id, ImGuiPopupFlags popup_flags) { - return ImGui::BeginPopupContextVoid(str_id, popup_flags); + [](std::optional str_id, ImGuiPopupFlags popup_flags) { + return ImGui::BeginPopupContextVoid(to_char_ptr(str_id), popup_flags); }, nb::arg("str_id") = nb::none(), nb::arg("popup_flags") = 1); diff --git a/src/cpp/imgui/imgui_api_widgets_drag.cpp b/src/cpp/imgui/imgui_api_widgets_drag.cpp index 3afbb0f..b9f5305 100644 --- a/src/cpp/imgui/imgui_api_widgets_drag.cpp +++ b/src/cpp/imgui/imgui_api_widgets_drag.cpp @@ -7,6 +7,8 @@ #include "imgui_utils.h" #include +#include +#include // clang-format off void bind_imgui_api_widgets_drag(nb::module_& m) { @@ -76,11 +78,7 @@ void bind_imgui_api_widgets_drag(nb::module_& m) { m.def( "DragFloatRange2", [](const char* label, float v_current_min, float v_current_max, float v_speed, float v_min, float v_max, std::string format, std::optional format_max, ImGuiSliderFlags flags) { - const char* format_max_ptr = nullptr; - if(format_max.has_value()) { - format_max_ptr = format_max->c_str(); - } - bool result = ImGui::DragFloatRange2(label, &v_current_min, &v_current_max, v_speed, v_min, v_max, format.c_str(), format_max_ptr, flags); + bool result = ImGui::DragFloatRange2(label, &v_current_min, &v_current_max, v_speed, v_min, v_max, format.c_str(), to_char_ptr(format_max), flags); return std::make_tuple(result, v_current_min, v_current_max); }, nb::arg("label"), @@ -156,8 +154,8 @@ void bind_imgui_api_widgets_drag(nb::module_& m) { // IMGUI_API bool DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%d", const char* format_max = NULL, ImGuiSliderFlags flags = 0); m.def( "DragIntRange2", - [](const char* label, int v_current_min, int v_current_max, float v_speed, int v_min, int v_max, const char* format, const char* format_max, ImGuiSliderFlags flags) { - bool result = ImGui::DragIntRange2(label, &v_current_min, &v_current_max, v_speed, v_min, v_max, format, format_max, flags); + [](const char* label, int v_current_min, int v_current_max, float v_speed, int v_min, int v_max, const char* format, std::optional format_max, ImGuiSliderFlags flags) { + bool result = ImGui::DragIntRange2(label, &v_current_min, &v_current_max, v_speed, v_min, v_max, format, to_char_ptr(format_max), flags); return std::make_tuple(result, v_current_min, v_current_max); }, nb::arg("label"), diff --git a/src/cpp/imgui/imgui_api_widgets_main.cpp b/src/cpp/imgui/imgui_api_widgets_main.cpp index 2f22c5b..05836e0 100644 --- a/src/cpp/imgui/imgui_api_widgets_main.cpp +++ b/src/cpp/imgui/imgui_api_widgets_main.cpp @@ -95,12 +95,12 @@ void bind_imgui_api_widgets_main(nb::module_& m) { // IMGUI_API void ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-FLT_MIN, 0), const char* overlay = NULL); m.def( "ProgressBar", - [](float fraction, const Vec2T& size_arg, std::string overlay) { - ImGui::ProgressBar(fraction, to_vec2(size_arg), overlay.empty() ? nullptr : overlay.c_str()); + [](float fraction, const Vec2T& size_arg, std::optional overlay) { + ImGui::ProgressBar(fraction, to_vec2(size_arg), to_char_ptr(overlay)); }, nb::arg("fraction"), nb::arg("size_arg") = Vec2T(-FLT_MIN, 0.f), - nb::arg("overlay") = ""); + nb::arg("overlay") = nb::none()); // IMGUI_API void Bullet(); m.def("Bullet", []() { ImGui::Bullet(); }); @@ -114,11 +114,11 @@ void bind_imgui_api_widgets_main(nb::module_& m) { // IMGUI_API void TextLinkOpenURL(const char* label, const char* url = NULL); m.def( "TextLinkOpenURL", - [](std::string label, std::string url) { - return ImGui::TextLinkOpenURL(label.c_str(), url.empty() ? nullptr : url.c_str()); + [](std::string label, std::optional url) { + return ImGui::TextLinkOpenURL(label.c_str(), to_char_ptr(url)); }, nb::arg("label"), - nb::arg("url") = ""); + nb::arg("url") = nb::none()); } // clang-format on diff --git a/src/cpp/imgui/imgui_utils.h b/src/cpp/imgui/imgui_utils.h index 68e3df0..995ca84 100644 --- a/src/cpp/imgui/imgui_utils.h +++ b/src/cpp/imgui/imgui_utils.h @@ -48,4 +48,11 @@ inline std::vector convert_string_items(const std::vector &s) { + if (s.has_value()) { + return s->c_str(); + } + return nullptr; +} From 58286f5b647b948752ab907a9a250cd89ecaa0d8 Mon Sep 17 00:00:00 2001 From: Merlin Nimier-David Date: Fri, 9 Jan 2026 14:25:55 +0100 Subject: [PATCH 2/2] ManagedBuffer: import missing type caster For the return value of `get_texture_size()`. --- src/cpp/managed_buffer.cpp | 2 ++ src/polyscope/common.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cpp/managed_buffer.cpp b/src/cpp/managed_buffer.cpp index e356f73..b9c6f14 100644 --- a/src/cpp/managed_buffer.cpp +++ b/src/cpp/managed_buffer.cpp @@ -7,6 +7,8 @@ #include "utils.h" +#include + template nb::class_> bind_managed_buffer_T(nb::module_& m, ps::ManagedBufferType t) { diff --git a/src/polyscope/common.py b/src/polyscope/common.py index 29bd0bc..a74b58a 100644 --- a/src/polyscope/common.py +++ b/src/polyscope/common.py @@ -255,4 +255,3 @@ def process_implicit_render_args(opts, implicit_args): def check_all_args_processed(structure, quantity, args): for arg,val in args.items(): raise ValueError(f"Polyscope: Unrecognized quantity keyword argument {arg}: {val}") -