Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cpp/imgui/imgui_api_columns_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "imgui_utils.h"

#include <nanobind/stl/array.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/string.h>

// clang-format off
void bind_imgui_api_columns_legacy(nb::module_& m) {
Expand All @@ -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<std::string> id, bool borders) {
ImGui::Columns(count, to_char_ptr(id), borders);
},
nb::arg("count") = 1,
nb::arg("id") = nb::none(),
nb::arg("borders") = true);
Expand Down
22 changes: 15 additions & 7 deletions src/cpp/imgui/imgui_api_data_plotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <nanobind/stl/array.h>
#include <nanobind/eigen/dense.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/string.h>

// clang-format off
void bind_imgui_api_data_plotting(nb::module_& m) {
Expand All @@ -16,33 +18,39 @@ 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<const Eigen::VectorXf>& 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<int>(values.size()), values_offset, overlay_text, scale_min, scale_max, to_vec2(graph_size));
[](const char* label, const Eigen::Ref<const Eigen::VectorXf>& values, int values_offset,
std::optional<std::string> overlay_text, float scale_min, float scale_max, const Vec2T& graph_size) {
ImGui::PlotLines(label, values.data(), static_cast<int>(values.size()),
values_offset, to_char_ptr(overlay_text), scale_min, scale_max, to_vec2(graph_size));
},
nb::arg("label"),
nb::arg("values"),
nb::arg("values_offset") = 0,
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

// 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<const Eigen::VectorXf>& 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<int>(values.size()), values_offset, overlay_text, scale_min, scale_max, to_vec2(graph_size));
[](const char* label, const Eigen::Ref<const Eigen::VectorXf>& values, int values_offset,
std::optional<std::string> overlay_text, float scale_min, float scale_max, const Vec2T& graph_size) {
ImGui::PlotHistogram(label, values.data(), static_cast<int>(values.size()),
values_offset, to_char_ptr(overlay_text), scale_min, scale_max, to_vec2(graph_size));
},
nb::arg("label"),
nb::arg("values"),
nb::arg("values_offset") = 0,
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
Expand Down Expand Up @@ -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<std::string> float_format) { ImGui::Value(prefix, v, to_char_ptr(float_format)); },
nb::arg("prefix"),
nb::arg("v"),
nb::arg("float_format") = nb::none());
Expand Down
6 changes: 5 additions & 1 deletion src/cpp/imgui/imgui_api_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "imgui_utils.h"

#include <nanobind/stl/array.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/string.h>

// clang-format off
void bind_imgui_api_logging(nb::module_& m) {
Expand All @@ -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<std::string> filename) {
ImGui::LogToFile(auto_open_depth, to_char_ptr(filename));
},
nb::arg("auto_open_depth") = -1,
nb::arg("filename") = nb::none());

Expand Down
6 changes: 4 additions & 2 deletions src/cpp/imgui/imgui_api_menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "imgui_utils.h"

#include <nanobind/stl/array.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/string.h>

// clang-format off
void bind_imgui_api_menus(nb::module_& m) {
Expand Down Expand Up @@ -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<std::string> shortcut, bool selected, bool enabled) {
return ImGui::MenuItem(label, to_char_ptr(shortcut), selected, enabled);
},
nb::arg("label"),
nb::arg("shortcut") = nb::none(),
Expand Down
16 changes: 9 additions & 7 deletions src/cpp/imgui/imgui_api_popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "imgui_utils.h"

#include <nanobind/stl/array.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/string.h>

// clang-format off
void bind_imgui_api_popups(nb::module_& m) {
Expand Down Expand Up @@ -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<std::string> 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);

Expand All @@ -70,26 +72,26 @@ 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<std::string> 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);

// 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<std::string> 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);

// 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<std::string> 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);
Expand Down
12 changes: 5 additions & 7 deletions src/cpp/imgui/imgui_api_widgets_drag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "imgui_utils.h"

#include <nanobind/stl/array.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/string.h>

// clang-format off
void bind_imgui_api_widgets_drag(nb::module_& m) {
Expand Down Expand Up @@ -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<std::string> 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"),
Expand Down Expand Up @@ -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<std::string> 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"),
Expand Down
12 changes: 6 additions & 6 deletions src/cpp/imgui/imgui_api_widgets_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> overlay) {
ImGui::ProgressBar(fraction, to_vec2(size_arg), to_char_ptr(overlay));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might slightly change the previous behavior, please check whether this is okay for you.
Same goes for TextLinkOpenURL.

},
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(); });
Expand All @@ -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<std::string> 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
9 changes: 8 additions & 1 deletion src/cpp/imgui/imgui_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ inline std::vector<const char*> convert_string_items(const std::vector<std::stri
_items.push_back(item.data());
}
return _items;
}
}

inline const char *to_char_ptr(const std::optional<std::string> &s) {
if (s.has_value()) {
return s->c_str();
}
return nullptr;
}
2 changes: 2 additions & 0 deletions src/cpp/managed_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "utils.h"

#include <nanobind/stl/array.h>

template <typename T>
nb::class_<ps::render::ManagedBuffer<T>> bind_managed_buffer_T(nb::module_& m, ps::ManagedBufferType t) {

Expand Down
1 change: 0 additions & 1 deletion src/polyscope/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")