From 1a6e3dc3012ed86b0b22bd297f44e15e53ecdddb Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Wed, 24 Dec 2025 10:31:18 -0500 Subject: [PATCH 1/4] update ps to latest --- deps/polyscope | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/polyscope b/deps/polyscope index a534b55..892a332 160000 --- a/deps/polyscope +++ b/deps/polyscope @@ -1 +1 @@ -Subproject commit a534b5591c67a8862c48a06e6661f296cf4c9511 +Subproject commit 892a33257c0ba00621b160118065a52847fe46b0 From 1751b749309df30bad9c8d74f5d1504421846778 Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Wed, 24 Dec 2025 19:43:23 -0500 Subject: [PATCH 2/4] update eigen --- .gitmodules | 6 +++--- deps/eigen | 2 +- deps/nanobind | 1 + deps/pybind11 | 1 - 4 files changed, 5 insertions(+), 5 deletions(-) create mode 160000 deps/nanobind delete mode 160000 deps/pybind11 diff --git a/.gitmodules b/.gitmodules index 2038fea..30d5c40 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ -[submodule "deps/pybind11"] - path = deps/pybind11 - url = https://github.com/pybind/pybind11.git [submodule "deps/polyscope"] path = deps/polyscope url = https://github.com/nmwsharp/polyscope.git [submodule "deps/eigen"] path = deps/eigen url = https://gitlab.com/libeigen/eigen.git +[submodule "deps/nanobind"] + path = deps/nanobind + url = https://github.com/wjakob/nanobind diff --git a/deps/eigen b/deps/eigen index 4fd5d14..d71c30c 160000 --- a/deps/eigen +++ b/deps/eigen @@ -1 +1 @@ -Subproject commit 4fd5d1477b221fc7daf2b7f1c7e4ee4f04ceaced +Subproject commit d71c30c47858effcbd39967097a2d99ee48db464 diff --git a/deps/nanobind b/deps/nanobind new file mode 160000 index 0000000..c5a3a37 --- /dev/null +++ b/deps/nanobind @@ -0,0 +1 @@ +Subproject commit c5a3a378aa61d104c82ca053cb1e367782cd3618 diff --git a/deps/pybind11 b/deps/pybind11 deleted file mode 160000 index a2e59f0..0000000 --- a/deps/pybind11 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a2e59f0e7065404b44dfe92a28aca47ba1378dc4 From df10ed331050c444e13d416ee7458b52f791ca52 Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Thu, 25 Dec 2025 02:14:46 -0500 Subject: [PATCH 3/4] core nanobind switchover completed, tests pass locally --- CMakeLists.txt | 32 +- src/cpp/camera_view.cpp | 14 +- src/cpp/core.cpp | 243 ++-- src/cpp/curve_network.cpp | 77 +- src/cpp/floating_quantities.cpp | 27 +- src/cpp/imgui.cpp | 1925 +++++++++++++++++-------------- src/cpp/imgui_utils.h | 3 +- src/cpp/implicit_helpers.cpp | 70 +- src/cpp/implot.cpp | 241 ++-- src/cpp/managed_buffer.cpp | 20 +- src/cpp/point_cloud.cpp | 44 +- src/cpp/surface_mesh.cpp | 115 +- src/cpp/utils.h | 70 +- src/cpp/volume_grid.cpp | 43 +- src/cpp/volume_mesh.cpp | 58 +- src/polyscope/core.py | 7 +- src/polyscope/managed_buffer.py | 7 +- test/polyscope_test.py | 15 +- 18 files changed, 1560 insertions(+), 1451 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9281fe3..92aa9da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,37 @@ cmake_minimum_required(VERSION 3.15.0) # minimum imposed by scikit-build-core project(polyscope LANGUAGES CXX) +# Default to release build +if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_CXX_STANDARD 20) + ## Gather dependencies -# Eigen +# == Eigen set(EIGEN3_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/deps/eigen/") -# Recurse in to pybind -set(PYBIND11_NEWPYTHON ON) -add_subdirectory(deps/pybind11) +# == Nanobind +if (CMAKE_VERSION VERSION_LESS 3.18) + set(DEV_MODULE Development) +else() + set(DEV_MODULE Development.Module) +endif() -# We need polyscope -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# find python version to target for bindings +find_package(Python 3.9 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED) + +# recurse into nanobind +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/nanobind) + +# == polyscope add_subdirectory(deps/polyscope) -pybind11_add_module(polyscope_bindings +nanobind_add_module(polyscope_bindings src/cpp/core.cpp src/cpp/surface_mesh.cpp src/cpp/point_cloud.cpp @@ -25,6 +42,7 @@ pybind11_add_module(polyscope_bindings src/cpp/floating_quantities.cpp src/cpp/implicit_helpers.cpp src/cpp/managed_buffer.cpp + src/cpp/imgui.cpp src/cpp/implot.cpp diff --git a/src/cpp/camera_view.cpp b/src/cpp/camera_view.cpp index f64fb24..c3feafa 100644 --- a/src/cpp/camera_view.cpp +++ b/src/cpp/camera_view.cpp @@ -1,7 +1,3 @@ -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/camera_view.h" @@ -9,12 +5,8 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - - // clang-format off -void bind_camera_view(py::module& m) { +void bind_camera_view(nb::module_& m) { // == Helper quantity classes @@ -40,9 +32,9 @@ void bind_camera_view(py::module& m) { // Static adders and getters m.def("register_camera_view", &ps::registerCameraView, - py::arg("name"), py::arg("parameters"), "Register a camera view", py::return_value_policy::reference); + nb::arg("name"), nb::arg("parameters"), "Register a camera view", nb::rv_policy::reference); m.def("remove_camera_view", &ps::removeCameraView, "Remove a camera view by name"); - m.def("get_camera_view", &ps::getCameraView, "Get a camera view by name", py::return_value_policy::reference); + m.def("get_camera_view", &ps::getCameraView, "Get a camera view by name", nb::rv_policy::reference); m.def("has_camera_view", &ps::hasCameraView, "Check for a camera view by name"); } diff --git a/src/cpp/core.cpp b/src/cpp/core.cpp index 95d8244..74b76da 100644 --- a/src/cpp/core.cpp +++ b/src/cpp/core.cpp @@ -1,8 +1,7 @@ -#include -#include -#include -#include -#include +#include +#include +#include +#include #include "Eigen/Dense" @@ -21,46 +20,41 @@ #include "utils.h" -namespace py = pybind11; +namespace nb = nanobind; +using namespace nb::literals; namespace ps = polyscope; -// For overloaded functions, with C++11 compiler only -template -using overload_cast_ = pybind11::detail::overload_cast_impl; - - // Forward-declare bindings from other files -void bind_surface_mesh(py::module& m); -void bind_point_cloud(py::module& m); -void bind_curve_network(py::module& m); -void bind_volume_mesh(py::module& m); -void bind_volume_grid(py::module& m); -void bind_camera_view(py::module& m); -void bind_floating_quantities(py::module& m); -void bind_implicit_helpers(py::module& m); -void bind_managed_buffer(py::module& m); -void bind_imgui(py::module& m); -void bind_implot(py::module& m); +void bind_surface_mesh(nb::module_& m); +void bind_point_cloud(nb::module_& m); +void bind_curve_network(nb::module_& m); +void bind_volume_mesh(nb::module_& m); +void bind_volume_grid(nb::module_& m); +void bind_camera_view(nb::module_& m); +void bind_floating_quantities(nb::module_& m); +void bind_implicit_helpers(nb::module_& m); +void bind_managed_buffer(nb::module_& m); +void bind_imgui(nb::module_& m); +void bind_implot(nb::module_& m); // Signal handler (makes ctrl-c work, etc) void checkSignals() { - if (PyErr_CheckSignals() != 0) throw py::error_already_set(); + if (PyErr_CheckSignals() != 0) throw nb::python_error(); } void defaultCallback() { checkSignals(); } // Actual binding code // clang-format off -PYBIND11_MODULE(polyscope_bindings, m) { +NB_MODULE(polyscope_bindings, m) { m.doc() = "Polyscope low-level bindings"; - // Register a cleanup function which will run when the module is exiting. // Suggested at: https://pybind11.readthedocs.io/en/stable/advanced/misc.html#module-destructors // We use it to ensure any Python data held on the C++ side gets properly deleted and cleaned up. This // is particularly difficult to do any other way, because Polyscope extensively uses static variables // to hold this state, so we can't just fall back on some other object's lifetime. - auto atexit = py::module_::import("atexit"); - atexit.attr("register")(py::cpp_function([]() { + auto atexit = nb::module_::import_("atexit"); + atexit.attr("register")(nb::cpp_function([]() { ps::state::userCallback = nullptr; if (ps::render::engine != nullptr) { ps::shutdown(true); @@ -68,7 +62,7 @@ PYBIND11_MODULE(polyscope_bindings, m) { })); // === Basic flow - m.def("init", &ps::init, py::arg("backend")="auto", "Initialize Polyscope"); + m.def("init", &ps::init, nb::arg("backend")="auto", "Initialize Polyscope"); m.def("check_initialized", &ps::checkInitialized); m.def("is_initialized", &ps::isInitialized); m.def("show", [](size_t forFrames) { @@ -86,7 +80,7 @@ PYBIND11_MODULE(polyscope_bindings, m) { ps::show(forFrames); } }, - py::arg("forFrames")=std::numeric_limits::max() + nb::arg("forFrames")=std::numeric_limits::max() ); m.def("unshow", &ps::unshow); m.def("window_requests_close", &ps::windowRequestsClose); @@ -102,17 +96,20 @@ PYBIND11_MODULE(polyscope_bindings, m) { m.def("remove_all_structures", &ps::removeAllStructures, "Remove all structures from polyscope"); // === Screenshots - py::class_(m, "ScreenshotOptions") - .def(py::init<>()) - .def_readwrite("include_UI", &ps::ScreenshotOptions::includeUI) - .def_readwrite("transparent_background", &ps::ScreenshotOptions::transparentBackground) + nb::class_(m, "ScreenshotOptions") + .def(nb::init<>()) + .def_rw("include_UI", &ps::ScreenshotOptions::includeUI) + .def_rw("transparent_background", &ps::ScreenshotOptions::transparentBackground) ; - m.def("screenshot", overload_cast_()(&ps::screenshot), "Take a screenshot"); + m.def("screenshot", nb::overload_cast(&ps::screenshot), "Take a screenshot"); m.def("screenshot_to_buffer", [](const ps::ScreenshotOptions& opts) { std::vector buff = ps::screenshotToBuffer(opts); - return py::array(buff.size(), buff.data()); + // copy to an eigen array + Eigen::Vector vec = + Eigen::Map>(buff.data(), buff.size()); + return vec; }, "Take a screenshot to buffer"); - m.def("named_screenshot", overload_cast_()(&ps::screenshot), "Take a screenshot"); + m.def("named_screenshot", nb::overload_cast(&ps::screenshot), "Take a screenshot"); m.def("set_screenshot_extension", [](std::string x) { ps::options::screenshotExtension = x; }); // === Small options @@ -203,7 +200,7 @@ PYBIND11_MODULE(polyscope_bindings, m) { m.def("build_user_gui_and_invoke_callback", &ps::buildUserGuiAndInvokeCallback); // === Messages - m.def("info", overload_cast_()(&ps::info), "Send an info message"); + m.def("info", nb::overload_cast(&ps::info), "Send an info message"); m.def("warning", &ps::warning, "Send a warning message"); m.def("error", &ps::error, "Send an error message"); m.def("terminating_error", &ps::terminatingError, "Send a terminating error message"); @@ -225,19 +222,19 @@ PYBIND11_MODULE(polyscope_bindings, m) { // === Pick - py::class_(m, "PickResult") - .def(py::init<>()) - .def_readonly("is_hit", &ps::PickResult::isHit) - // .def_readonly("structure", &ps::PickResult::structure) - .def_readonly("structure_handle", &ps::PickResult::structureHandle) - .def_readonly("structure_type", &ps::PickResult::structureType) - .def_readonly("structure_name", &ps::PickResult::structureName) - .def_readonly("quantity_name", &ps::PickResult::quantityName) - .def_readonly("screen_coords", &ps::PickResult::screenCoords) - .def_readonly("buffer_inds", &ps::PickResult::bufferInds) - .def_readonly("position", &ps::PickResult::position) - .def_readonly("depth", &ps::PickResult::depth) - .def_readonly("local_index", &ps::PickResult::localIndex) + nb::class_(m, "PickResult") + .def(nb::init<>()) + .def_ro("is_hit", &ps::PickResult::isHit) + // .def_ro("structure", &ps::PickResult::structure) + .def_ro("structure_handle", &ps::PickResult::structureHandle) + .def_ro("structure_type", &ps::PickResult::structureType) + .def_ro("structure_name", &ps::PickResult::structureName) + .def_ro("quantity_name", &ps::PickResult::quantityName) + .def_ro("screen_coords", &ps::PickResult::screenCoords) + .def_ro("buffer_inds", &ps::PickResult::bufferInds) + .def_ro("position", &ps::PickResult::position) + .def_ro("depth", &ps::PickResult::depth) + .def_ro("local_index", &ps::PickResult::localIndex) ; // stateful selection @@ -264,9 +261,12 @@ PYBIND11_MODULE(polyscope_bindings, m) { // === Materials m.def("load_static_material", ps::loadStaticMaterial, "Load a static material"); - m.def("load_blendable_material_explicit", overload_cast_>()(&ps::loadBlendableMaterial), + m.def("load_blendable_material_explicit", + [](std::string mat_name, std::tuple filenames) { + ps::loadBlendableMaterial(mat_name, {std::get<0>(filenames), std::get<1>(filenames), std::get<2>(filenames), std::get<3>(filenames)}); + }, "Load a blendable material from explicit names"); - m.def("load_blendable_material_baseext", overload_cast_()(&ps::loadBlendableMaterial), + m.def("load_blendable_material_baseext", nb::overload_cast(&ps::loadBlendableMaterial), "Load a blendable material from base and ext names"); // === Colormaps @@ -279,20 +279,20 @@ PYBIND11_MODULE(polyscope_bindings, m) { // === Structure // (this is the generic structure class, subtypes get bound in their respective files) - py::class_(m, "Structure") - .def_readonly("name", &ps::Structure::name) + nb::class_(m, "Structure") + .def_ro("name", &ps::Structure::name) ; // === Groups - py::class_(m, "Group") - .def(py::init()) - .def_readonly("name", &ps::Group::name) + nb::class_(m, "Group") + .def(nb::init()) + .def_ro("name", &ps::Group::name) .def("add_child_group", &ps::Group::addChildGroup) .def("add_child_structure", &ps::Group::addChildStructure) .def("remove_child_group", &ps::Group::removeChildGroup) .def("remove_child_structure", &ps::Group::removeChildStructure) - .def("set_enabled", &ps::Group::setEnabled, py::return_value_policy::reference) + .def("set_enabled", &ps::Group::setEnabled, nb::rv_policy::reference) .def("set_show_child_details", &ps::Group::setShowChildDetails) .def("set_hide_descendants_from_structure_lists", &ps::Group::setHideDescendantsFromStructureLists) .def("get_child_structure_names", [](ps::Group& g) { @@ -316,9 +316,9 @@ PYBIND11_MODULE(polyscope_bindings, m) { ; // create/get/delete - m.def("create_group", &ps::createGroup, py::return_value_policy::reference); - m.def("get_group", &ps::getGroup, py::return_value_policy::reference); - m.def("remove_group", overload_cast_()(&ps::removeGroup)); + m.def("create_group", &ps::createGroup, nb::rv_policy::reference); + m.def("get_group", &ps::getGroup, nb::rv_policy::reference); + m.def("remove_group", nb::overload_cast(&ps::removeGroup)); m.def("remove_all_groups", &ps::removeAllGroups); @@ -327,9 +327,9 @@ PYBIND11_MODULE(polyscope_bindings, m) { m.def("get_final_scene_color_texture_native_handle", []() { ps::render::engine->getFinalSceneColorTexture().getNativeBufferID(); }); // === Slice planes - py::class_(m, "SlicePlane") - .def(py::init()) - .def_readonly("name", &ps::SlicePlane::name) + nb::class_(m, "SlicePlane") + .def(nb::init()) + .def_ro("name", &ps::SlicePlane::name) .def("remove", &ps::SlicePlane::remove, "remove") .def("set_enabled", &ps::SlicePlane::setEnabled, "set enabled") .def("get_enabled", &ps::SlicePlane::getEnabled, "get enabled") @@ -352,22 +352,22 @@ PYBIND11_MODULE(polyscope_bindings, m) { .def("get_volume_mesh_to_inspect", &ps::SlicePlane::getVolumeMeshToInspect, "get name of inspected volume mesh"); - m.def("add_slice_plane", overload_cast_<>()(&ps::addSlicePlane), "add a slice plane", py::return_value_policy::reference); - m.def("add_slice_plane", overload_cast_()(&ps::addSlicePlane), "add a slice plane", py::return_value_policy::reference); - m.def("get_slice_plane", &ps::getSlicePlane, "get a slice plane by name", py::return_value_policy::reference); - m.def("remove_slice_plane", overload_cast_()(&ps::removeSlicePlane), "remove a slice plane by name"); + m.def("add_slice_plane", nb::overload_cast<>(&ps::addSlicePlane), "add a slice plane", nb::rv_policy::reference); + m.def("add_slice_plane", nb::overload_cast(&ps::addSlicePlane), "add a slice plane", nb::rv_policy::reference); + m.def("get_slice_plane", &ps::getSlicePlane, "get a slice plane by name", nb::rv_policy::reference); + m.def("remove_slice_plane", nb::overload_cast(&ps::removeSlicePlane), "remove a slice plane by name"); m.def("remove_all_slice_planes", &ps::removeAllSlicePlanes, "remove all slice planes"); // deprecated, but still supprorted for now - m.def("add_scene_slice_plane", ps::addSceneSlicePlane, "add a slice plane", py::return_value_policy::reference); + m.def("add_scene_slice_plane", ps::addSceneSlicePlane, "add a slice plane", nb::rv_policy::reference); m.def("remove_last_scene_slice_plane", ps::removeLastSceneSlicePlane, "remove last scene plane"); // === Transformation Gizmos - py::class_(m, "TransformationGizmo") - .def(py::init()) - .def_readonly("name", &ps::TransformationGizmo::name) + nb::class_(m, "TransformationGizmo") + .def(nb::init()) + .def_ro("name", &ps::TransformationGizmo::name) .def("remove", &ps::TransformationGizmo::remove, "remove") .def("set_enabled", &ps::TransformationGizmo::setEnabled, "set enabled") .def("get_enabled", &ps::TransformationGizmo::getEnabled, "get enabled") @@ -390,26 +390,26 @@ PYBIND11_MODULE(polyscope_bindings, m) { .def("build_inline_transform_ui", &ps::TransformationGizmo::buildInlineTransformUI, "build inline transform UI") ; - m.def("add_transformation_gizmo", [](std::string name) {return ps::addTransformationGizmo(name); }, "add a transformation gizmo", py::return_value_policy::reference); - m.def("get_transformation_gizmo", &ps::getTransformationGizmo, "get a transformation gizmo", py::return_value_policy::reference); - m.def("remove_transformation_gizmo", overload_cast_()(&ps::removeTransformationGizmo), "remove a transformation gizmo by name"); - m.def("remove_transformation_gizmo", overload_cast_()(&ps::removeTransformationGizmo), "remove a transformation gizmo by ptr"); + m.def("add_transformation_gizmo", [](std::string name) {return ps::addTransformationGizmo(name); }, "add a transformation gizmo", nb::rv_policy::reference); + m.def("get_transformation_gizmo", &ps::getTransformationGizmo, "get a transformation gizmo", nb::rv_policy::reference); + m.def("remove_transformation_gizmo", nb::overload_cast(&ps::removeTransformationGizmo), "remove a transformation gizmo by name"); + m.def("remove_transformation_gizmo", nb::overload_cast(&ps::removeTransformationGizmo), "remove a transformation gizmo by ptr"); m.def("remove_all_transformation_gizmos", &ps::removeAllTransformationGizmos, "remove all transformation gizmos"); // === Camera Parameters - py::class_(m, "CameraIntrinsics") - .def(py::init<>()) + nb::class_(m, "CameraIntrinsics") + .def(nb::init<>()) .def_static("from_FoV_deg_vertical_and_aspect", &ps::CameraIntrinsics::fromFoVDegVerticalAndAspect) .def_static("from_FoV_deg_horizontal_and_aspect", &ps::CameraIntrinsics::fromFoVDegHorizontalAndAspect) .def_static("from_FoV_deg_horizontal_and_vertical", &ps::CameraIntrinsics::fromFoVDegHorizontalAndVertical) ; - py::class_(m, "CameraExtrinsics") - .def(py::init<>()) + nb::class_(m, "CameraExtrinsics") + .def(nb::init<>()) .def_static("from_vectors", &ps::CameraExtrinsics::fromVectors) .def_static("from_matrix", [](Eigen::Matrix4f mat) { return ps::CameraExtrinsics::fromMatrix(eigen2glm(mat)); }) ; - py::class_(m, "CameraParameters") - .def(py::init()) + nb::class_(m, "CameraParameters") + .def(nb::init()) .def("get_intrinsics", [](ps::CameraParameters& c) { return c.intrinsics; }) .def("get_extrinsics", [](ps::CameraParameters& c) { return c.extrinsics; }) .def("get_T", [](ps::CameraParameters& c) { return glm2eigen(c.getT()); }) @@ -449,15 +449,14 @@ PYBIND11_MODULE(polyscope_bindings, m) { // === Weak Handles // (used for lifetime tracking tricks) - py::class_(m, "GenericWeakHandle") - .def(py::init<>()) + nb::class_(m, "GenericWeakHandle") + .def(nb::init<>()) .def("is_valid", &ps::GenericWeakHandle::isValid) .def("get_unique_ID", &ps::GenericWeakHandle::getUniqueID) ; // === Enums - - py::enum_(m, "NavigateStyle") + nb::enum_(m, "NavigateStyle") .value("turntable", ps::view::NavigateStyle::Turntable) .value("free", ps::view::NavigateStyle::Free) .value("planar", ps::view::NavigateStyle::Planar) @@ -466,12 +465,12 @@ PYBIND11_MODULE(polyscope_bindings, m) { .value("first_person", ps::view::NavigateStyle::FirstPerson) ; - py::enum_(m, "ProjectionMode") + nb::enum_(m, "ProjectionMode") .value("perspective", ps::ProjectionMode::Perspective) .value("orthographic", ps::ProjectionMode::Orthographic) ; - py::enum_(m, "UpDir") + nb::enum_(m, "UpDir") .value("x_up", ps::UpDir::XUp) .value("y_up", ps::UpDir::YUp) .value("z_up", ps::UpDir::ZUp) @@ -480,7 +479,7 @@ PYBIND11_MODULE(polyscope_bindings, m) { .value("neg_z_up", ps::UpDir::NegZUp) ; - py::enum_(m, "FrontDir") + nb::enum_(m, "FrontDir") .value("x_front", ps::FrontDir::XFront) .value("y_front", ps::FrontDir::YFront) .value("z_front", ps::FrontDir::ZFront) @@ -489,24 +488,24 @@ PYBIND11_MODULE(polyscope_bindings, m) { .value("neg_z_front", ps::FrontDir::NegZFront) ; - py::enum_(m, "DataType") + nb::enum_(m, "DataType") .value("standard", ps::DataType::STANDARD) .value("symmetric", ps::DataType::SYMMETRIC) .value("magnitude", ps::DataType::MAGNITUDE) .value("categorical", ps::DataType::CATEGORICAL) ; - py::enum_(m, "VectorType") + nb::enum_(m, "VectorType") .value("standard", ps::VectorType::STANDARD) .value("ambient", ps::VectorType::AMBIENT) ; - py::enum_(m, "ParamCoordsType") + nb::enum_(m, "ParamCoordsType") .value("unit", ps::ParamCoordsType::UNIT) .value("world", ps::ParamCoordsType::WORLD) ; - py::enum_(m, "ParamVizStyle") + nb::enum_(m, "ParamVizStyle") .value("checker", ps::ParamVizStyle::CHECKER) .value("checker_islands", ps::ParamVizStyle::CHECKER_ISLANDS) .value("grid", ps::ParamVizStyle::GRID) @@ -514,43 +513,43 @@ PYBIND11_MODULE(polyscope_bindings, m) { .value("local_rad", ps::ParamVizStyle::LOCAL_RAD) ; - py::enum_(m, "BackFacePolicy") + nb::enum_(m, "BackFacePolicy") .value("identical", ps::BackFacePolicy::Identical) .value("different", ps::BackFacePolicy::Different) .value("custom", ps::BackFacePolicy::Custom) .value("cull", ps::BackFacePolicy::Cull) ; - py::enum_(m, "LimitFPSMode") + nb::enum_(m, "LimitFPSMode") .value("ignore_limits", ps::LimitFPSMode::IgnoreLimits) .value("block_to_hit_target", ps::LimitFPSMode::BlockToHitTarget) .value("skip_frames_to_hit_target", ps::LimitFPSMode::SkipFramesToHitTarget) ; - py::enum_(m, "GroundPlaneMode") + nb::enum_(m, "GroundPlaneMode") .value("none", ps::GroundPlaneMode::None) .value("tile", ps::GroundPlaneMode::Tile) .value("tile_reflection", ps::GroundPlaneMode::TileReflection) .value("shadow_only", ps::GroundPlaneMode::ShadowOnly) ; - py::enum_(m, "GroundPlaneHeightMode") + nb::enum_(m, "GroundPlaneHeightMode") .value("automatic", ps::GroundPlaneHeightMode::Automatic) .value("manual", ps::GroundPlaneHeightMode::Manual) ; - py::enum_(m, "TransparencyMode") + nb::enum_(m, "TransparencyMode") .value("none", ps::TransparencyMode::None) .value("simple", ps::TransparencyMode::Simple) .value("pretty", ps::TransparencyMode::Pretty) ; - py::enum_(m, "CurveNetworkElement") + nb::enum_(m, "CurveNetworkElement") .value("node", ps::CurveNetworkElement::NODE) .value("edge", ps::CurveNetworkElement::EDGE) ; - py::enum_(m, "MeshElement") + nb::enum_(m, "MeshElement") .value("vertex", ps::MeshElement::VERTEX) .value("face", ps::MeshElement::FACE) .value("edge", ps::MeshElement::EDGE) @@ -558,56 +557,56 @@ PYBIND11_MODULE(polyscope_bindings, m) { .value("corner", ps::MeshElement::CORNER) ; - py::enum_(m, "MeshSelectionMode") + nb::enum_(m, "MeshSelectionMode") .value("auto", ps::MeshSelectionMode::Auto) .value("vertices_only", ps::MeshSelectionMode::VerticesOnly) .value("faces_only", ps::MeshSelectionMode::FacesOnly) ; - py::enum_(m, "VolumeMeshElement") + nb::enum_(m, "VolumeMeshElement") .value("vertex", ps::VolumeMeshElement::VERTEX) .value("edge", ps::VolumeMeshElement::EDGE) .value("face", ps::VolumeMeshElement::FACE) .value("cell", ps::VolumeMeshElement::CELL) ; - py::enum_(m, "VolumeGridElement") + nb::enum_(m, "VolumeGridElement") .value("node", ps::VolumeGridElement::NODE) .value("cell", ps::VolumeGridElement::CELL) ; - py::enum_(m, "PointRenderMode") + nb::enum_(m, "PointRenderMode") .value("sphere", ps::PointRenderMode::Sphere) .value("quad", ps::PointRenderMode::Quad) ; - py::enum_(m, "FilterMode") + nb::enum_(m, "FilterMode") .value("linear", ps::FilterMode::Linear) .value("nearest", ps::FilterMode::Nearest) ; - py::enum_(m, "ImageOrigin") + nb::enum_(m, "ImageOrigin") .value("lower_left", ps::ImageOrigin::LowerLeft) .value("upper_left", ps::ImageOrigin::UpperLeft) ; - py::enum_(m, "MeshShadeStyle") + nb::enum_(m, "MeshShadeStyle") .value("smooth", ps::MeshShadeStyle::Smooth) .value("flat", ps::MeshShadeStyle::Flat) .value("tri_flat", ps::MeshShadeStyle::TriFlat) ; - py::enum_(m, "IsolineStyle") + nb::enum_(m, "IsolineStyle") .value("stripe", ps::IsolineStyle::Stripe) .value("contour", ps::IsolineStyle::Contour) ; - py::enum_(m, "ImplicitRenderMode") + nb::enum_(m, "ImplicitRenderMode") .value("sphere_march", ps::ImplicitRenderMode::SphereMarch) .value("fixed_step", ps::ImplicitRenderMode::FixedStep) ; - py::enum_(m, "ManagedBufferType") + nb::enum_(m, "ManagedBufferType") .value(ps::typeName(ps::ManagedBufferType::Float ).c_str(), ps::ManagedBufferType::Float ) .value(ps::typeName(ps::ManagedBufferType::Double ).c_str(), ps::ManagedBufferType::Double ) .value(ps::typeName(ps::ManagedBufferType::Vec2 ).c_str(), ps::ManagedBufferType::Vec2 ) @@ -623,44 +622,45 @@ PYBIND11_MODULE(polyscope_bindings, m) { .value(ps::typeName(ps::ManagedBufferType::UVec4 ).c_str(), ps::ManagedBufferType::UVec4 ) ; - py::enum_(m, "DeviceBufferType") + nb::enum_(m, "DeviceBufferType") .value("attribute", ps::DeviceBufferType::Attribute) .value("texture1d", ps::DeviceBufferType::Texture1d) .value("texture2d", ps::DeviceBufferType::Texture2d) .value("texture3d", ps::DeviceBufferType::Texture3d) ; + // === Mini bindings for a little bit of glm - py::class_(m, "glm_vec2"). - def(py::init()) + nb::class_(m, "glm_vec2"). + def(nb::init()) .def("as_tuple", [](const glm::vec2& x) { return std::tuple(x[0], x[1]); }); - py::class_(m, "glm_vec3"). - def(py::init()) + nb::class_(m, "glm_vec3"). + def(nb::init()) .def("as_tuple", [](const glm::vec3& x) { return std::tuple(x[0], x[1], x[2]); }); - py::class_(m, "glm_vec4"). - def(py::init()) + nb::class_(m, "glm_vec4"). + def(nb::init()) .def("as_tuple", [](const glm::vec4& x) { return std::tuple(x[0], x[1], x[2], x[3]); }); - py::class_(m, "glm_ivec2"). - def(py::init()) + nb::class_(m, "glm_ivec2"). + def(nb::init()) .def("as_tuple", [](const glm::ivec2& x) { return std::tuple(x[0], x[1]); }); - py::class_(m, "glm_uvec3"). - def(py::init()) + nb::class_(m, "glm_uvec3"). + def(nb::init()) .def("as_tuple", [](const glm::uvec3& x) { return std::tuple(x[0], x[1], x[2]); @@ -679,7 +679,6 @@ PYBIND11_MODULE(polyscope_bindings, m) { bind_managed_buffer(m); bind_imgui(m); bind_implot(m); - } // clang-format on diff --git a/src/cpp/curve_network.cpp b/src/cpp/curve_network.cpp index 62430bf..12bfe3d 100644 --- a/src/cpp/curve_network.cpp +++ b/src/cpp/curve_network.cpp @@ -1,7 +1,3 @@ -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/curve_network.h" @@ -9,19 +5,16 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - // clang-format off -void bind_curve_network(py::module& m) { +void bind_curve_network(nb::module_& m) { // == Helper classes - py::class_(m, "CurveNetworkPickResult") - .def(py::init<>()) - .def_readonly("element_type", &ps::CurveNetworkPickResult::elementType) - .def_readonly("index", &ps::CurveNetworkPickResult::index) - .def_readonly("t_edge", &ps::CurveNetworkPickResult::tEdge) + nb::class_(m, "CurveNetworkPickResult") + .def(nb::init<>()) + .def_ro("element_type", &ps::CurveNetworkPickResult::elementType) + .def_ro("index", &ps::CurveNetworkPickResult::index) + .def_ro("t_edge", &ps::CurveNetworkPickResult::tEdge) ; // Scalar quantities @@ -58,62 +51,62 @@ void bind_curve_network(py::module& m) { .def("interpret_pick_result", &ps::CurveNetwork::interpretPickResult) // variable radius - .def("set_node_radius_quantity", overload_cast_()(&ps::CurveNetwork::setNodeRadiusQuantity), - py::arg("quantity_name"), py::arg("autoscale")) - .def("set_edge_radius_quantity", overload_cast_()(&ps::CurveNetwork::setEdgeRadiusQuantity), - py::arg("quantity_name"), py::arg("autoscale")) + .def("set_node_radius_quantity", nb::overload_cast(&ps::CurveNetwork::setNodeRadiusQuantity), + nb::arg("quantity_name"), nb::arg("autoscale")) + .def("set_edge_radius_quantity", nb::overload_cast(&ps::CurveNetwork::setEdgeRadiusQuantity), + nb::arg("quantity_name"), nb::arg("autoscale")) .def("clear_node_radius_quantity", &ps::CurveNetwork::clearNodeRadiusQuantity) .def("clear_edge_radius_quantity", &ps::CurveNetwork::clearEdgeRadiusQuantity) // quantities .def("add_node_color_quantity", &ps::CurveNetwork::addNodeColorQuantity, "Add a color function at nodes", - py::arg("name"), py::arg("values"), py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::rv_policy::reference) .def("add_edge_color_quantity", &ps::CurveNetwork::addEdgeColorQuantity, "Add a color function at edges", - py::arg("name"), py::arg("values"), py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::rv_policy::reference) .def("add_node_scalar_quantity", &ps::CurveNetwork::addNodeScalarQuantity, "Add a scalar function at nodes", - py::arg("name"), py::arg("values"), py::arg("data_type")=ps::DataType::STANDARD, py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("data_type")=ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_edge_scalar_quantity", &ps::CurveNetwork::addEdgeScalarQuantity, "Add a scalar function at edge", - py::arg("name"), py::arg("values"), py::arg("data_type")=ps::DataType::STANDARD, py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("data_type")=ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_node_vector_quantity", &ps::CurveNetwork::addNodeVectorQuantity, "Add a vector function at nodes", - py::arg("name"), py::arg("values"), py::arg("vector_type")=ps::VectorType::STANDARD, py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("vector_type")=ps::VectorType::STANDARD, nb::rv_policy::reference) .def("add_node_vector_quantity2D", &ps::CurveNetwork::addNodeVectorQuantity2D, "Add a vector function at nodes", - py::arg("name"), py::arg("values"), py::arg("vector_type")=ps::VectorType::STANDARD, py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("vector_type")=ps::VectorType::STANDARD, nb::rv_policy::reference) .def("add_edge_vector_quantity", &ps::CurveNetwork::addEdgeVectorQuantity, "Add a vector function at edges", - py::arg("name"), py::arg("values"), py::arg("vector_type")=ps::VectorType::STANDARD, py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("vector_type")=ps::VectorType::STANDARD, nb::rv_policy::reference) .def("add_edge_vector_quantity2D", &ps::CurveNetwork::addEdgeVectorQuantity2D, "Add a vector function at edges", - py::arg("name"), py::arg("values"), py::arg("vector_type")=ps::VectorType::STANDARD, py::return_value_policy::reference); + nb::arg("name"), nb::arg("values"), nb::arg("vector_type")=ps::VectorType::STANDARD, nb::rv_policy::reference); // Static adders and getters m.def("register_curve_network", &ps::registerCurveNetwork, - py::arg("name"), py::arg("nodes"), py::arg("edges"), - "Register a curve network", py::return_value_policy::reference); + nb::arg("name"), nb::arg("nodes"), nb::arg("edges"), + "Register a curve network", nb::rv_policy::reference); m.def("register_curve_network2D", &ps::registerCurveNetwork2D, - py::arg("name"), py::arg("nodes"), py::arg("edges"), - "Register a curve network", py::return_value_policy::reference); + nb::arg("name"), nb::arg("nodes"), nb::arg("edges"), + "Register a curve network", nb::rv_policy::reference); m.def("register_curve_network_line", &ps::registerCurveNetworkLine, - py::arg("name"), py::arg("nodes"), - "Register a curve network", py::return_value_policy::reference); + nb::arg("name"), nb::arg("nodes"), + "Register a curve network", nb::rv_policy::reference); m.def("register_curve_network_line2D", &ps::registerCurveNetworkLine2D, - py::arg("name"), py::arg("nodes"), - "Register a curve network", py::return_value_policy::reference); + nb::arg("name"), nb::arg("nodes"), + "Register a curve network", nb::rv_policy::reference); m.def("register_curve_network_loop", &ps::registerCurveNetworkLoop, - py::arg("name"), py::arg("nodes"), - "Register a curve network", py::return_value_policy::reference); + nb::arg("name"), nb::arg("nodes"), + "Register a curve network", nb::rv_policy::reference); m.def("register_curve_network_loop2D", &ps::registerCurveNetworkLoop2D, - py::arg("name"), py::arg("nodes"), - "Register a curve network", py::return_value_policy::reference); + nb::arg("name"), nb::arg("nodes"), + "Register a curve network", nb::rv_policy::reference); m.def("register_curve_network_segments", &ps::registerCurveNetworkSegments, - py::arg("name"), py::arg("nodes"), - "Register a curve network", py::return_value_policy::reference); + nb::arg("name"), nb::arg("nodes"), + "Register a curve network", nb::rv_policy::reference); m.def("register_curve_network_segments2D", &ps::registerCurveNetworkSegments2D, - py::arg("name"), py::arg("nodes"), - "Register a curve network", py::return_value_policy::reference); + nb::arg("name"), nb::arg("nodes"), + "Register a curve network", nb::rv_policy::reference); m.def("remove_curve_network", &polyscope::removeCurveNetwork, "Remove a curve network by name"); - m.def("get_curve_network", &polyscope::getCurveNetwork, "Get a curve network by name", py::return_value_policy::reference); + m.def("get_curve_network", &polyscope::getCurveNetwork, "Get a curve network by name", nb::rv_policy::reference); m.def("has_curve_network", &polyscope::hasCurveNetwork, "Check for a curve network by name"); } diff --git a/src/cpp/floating_quantities.cpp b/src/cpp/floating_quantities.cpp index 33d1c41..72d90d4 100644 --- a/src/cpp/floating_quantities.cpp +++ b/src/cpp/floating_quantities.cpp @@ -1,7 +1,3 @@ -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/polyscope.h" @@ -11,17 +7,14 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - // clang-format off -void bind_floating_quantities(py::module& m) { +void bind_floating_quantities(nb::module_& m) { // == Global floating quantity management // global floating quantity structure bindStructure(m, "FloatingQuantityStructure"); - m.def("get_global_floating_quantity_structure", &ps::getGlobalFloatingQuantityStructure, py::return_value_policy::reference); + m.def("get_global_floating_quantity_structure", &ps::getGlobalFloatingQuantityStructure, nb::rv_policy::reference); m.def("remove_floating_quantity", &ps::removeFloatingQuantity); m.def("remove_all_floating_quantities", &ps::removeAllFloatingQuantities); @@ -37,11 +30,11 @@ void bind_floating_quantities(py::module& m) { // global / free-floating adders m.def("add_scalar_image_quantity", &ps::addScalarImageQuantity, - py::return_value_policy::reference); + nb::rv_policy::reference); m.def("add_color_image_quantity", &ps::addColorImageQuantity, - py::return_value_policy::reference); + nb::rv_policy::reference); m.def("add_color_alpha_image_quantity", &ps::addColorAlphaImageQuantity, - py::return_value_policy::reference); + nb::rv_policy::reference); // == Render image floating quantities @@ -72,15 +65,15 @@ void bind_floating_quantities(py::module& m) { // global / free-floating adders m.def("add_depth_render_image_quantity", &ps::addDepthRenderImageQuantity, - py::return_value_policy::reference); + nb::rv_policy::reference); m.def("add_color_render_image_quantity", &ps::addColorRenderImageQuantity, - py::return_value_policy::reference); + nb::rv_policy::reference); m.def("add_scalar_render_image_quantity", &ps::addScalarRenderImageQuantity, - py::return_value_policy::reference); + nb::rv_policy::reference); m.def("add_raw_color_render_image_quantity", &ps::addRawColorRenderImageQuantity, - py::return_value_policy::reference); + nb::rv_policy::reference); m.def("add_raw_color_alpha_render_image_quantity", &ps::addRawColorAlphaRenderImageQuantity, - py::return_value_policy::reference); + nb::rv_policy::reference); } diff --git a/src/cpp/imgui.cpp b/src/cpp/imgui.cpp index 662feef..cc95f80 100644 --- a/src/cpp/imgui.cpp +++ b/src/cpp/imgui.cpp @@ -1,22 +1,18 @@ #include "imgui.h" #include "implot.h" -#include -#include -#include -#include - #include "Eigen/Dense" #include "utils.h" #include "imgui_utils.h" +#include -void bind_imgui_structs(py::module& m); -void bind_imgui_methods(py::module& m); -void bind_imgui_enums(py::module& m); +void bind_imgui_structs(nb::module_& m); +void bind_imgui_methods(nb::module_& m); +void bind_imgui_enums(nb::module_& m); -void bind_imgui(py::module& m) { +void bind_imgui(nb::module_& m) { auto imgui_module = m.def_submodule("imgui", "ImGui bindings"); bind_imgui_structs(imgui_module); bind_imgui_methods(imgui_module); @@ -51,85 +47,86 @@ static int input_text_callback(ImGuiInputTextCallbackData* data) { // clang-format off -void bind_imgui_structs(py::module& m) { +void bind_imgui_structs(nb::module_& m) { // ImGuiIO - py::class_(m, "ImGuiIO") - .def_readwrite("DisplaySize" ,&ImGuiIO::DisplaySize ) - .def_readwrite("DeltaTime" ,&ImGuiIO::DeltaTime ) - .def_readwrite("IniSavingRate" ,&ImGuiIO::IniSavingRate ) - .def_readwrite("IniFilename" ,&ImGuiIO::IniFilename ) - .def_readwrite("MouseDoubleClickTime" ,&ImGuiIO::MouseDoubleClickTime ) - .def_readwrite("MouseDoubleClickMaxDist" ,&ImGuiIO::MouseDoubleClickMaxDist ) - .def_readwrite("MouseDragThreshold" ,&ImGuiIO::MouseDragThreshold ) - .def_readwrite("KeyRepeatDelay" ,&ImGuiIO::KeyRepeatDelay ) - .def_readwrite("KeyRepeatRate" ,&ImGuiIO::KeyRepeatRate ) - .def_readwrite("Fonts" ,&ImGuiIO::Fonts ) - .def_readwrite("FontGlobalScale" ,&ImGuiIO::FontGlobalScale ) - .def_readwrite("FontAllowUserScaling" ,&ImGuiIO::FontAllowUserScaling ) - .def_readwrite("FontDefault" ,&ImGuiIO::FontDefault ) - .def_readwrite("DisplayFramebufferScale" ,&ImGuiIO::DisplayFramebufferScale ) - .def_readwrite("MouseDrawCursor" ,&ImGuiIO::MouseDrawCursor ) - .def_readwrite("ConfigMacOSXBehaviors" ,&ImGuiIO::ConfigMacOSXBehaviors ) - .def_readwrite("ConfigInputTextCursorBlink" ,&ImGuiIO::ConfigInputTextCursorBlink ) - .def_readwrite("ConfigDragClickToInputText" ,&ImGuiIO::ConfigDragClickToInputText ) - .def_readwrite("ConfigWindowsResizeFromEdges" ,&ImGuiIO::ConfigWindowsResizeFromEdges ) - .def_readwrite("ConfigWindowsMoveFromTitleBarOnly" ,&ImGuiIO::ConfigWindowsMoveFromTitleBarOnly ) - .def_readwrite("ConfigMemoryCompactTimer" ,&ImGuiIO::ConfigMemoryCompactTimer ) - .def_property_readonly("MousePos" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return from_vec2(o.MousePos);}) - .def_property_readonly("MouseDown" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseDown , ob};}) - .def_readwrite("MouseWheel" ,&ImGuiIO::MouseWheel ) - .def_readwrite("MouseWheelH" ,&ImGuiIO::MouseWheelH ) - .def_readwrite("KeyCtrl" ,&ImGuiIO::KeyCtrl ) - .def_readwrite("KeyShift" ,&ImGuiIO::KeyShift ) - .def_readwrite("KeyAlt" ,&ImGuiIO::KeyAlt ) - .def_readwrite("KeySuper" ,&ImGuiIO::KeySuper ) - .def_readwrite("WantCaptureMouse" ,&ImGuiIO::WantCaptureMouse ) - .def_readwrite("WantCaptureKeyboard" ,&ImGuiIO::WantCaptureKeyboard ) - .def_readwrite("WantTextInput" ,&ImGuiIO::WantTextInput ) - .def_readwrite("WantSetMousePos" ,&ImGuiIO::WantSetMousePos ) - .def_readwrite("WantSaveIniSettings" ,&ImGuiIO::WantSaveIniSettings ) - .def_readwrite("NavActive" ,&ImGuiIO::NavActive ) - .def_readwrite("NavVisible" ,&ImGuiIO::NavVisible ) - .def_readwrite("Framerate" ,&ImGuiIO::Framerate ) - .def_readwrite("MetricsRenderVertices" ,&ImGuiIO::MetricsRenderVertices ) - .def_readwrite("MetricsRenderIndices" ,&ImGuiIO::MetricsRenderIndices ) - .def_readwrite("MetricsRenderWindows" ,&ImGuiIO::MetricsRenderWindows ) - .def_readwrite("MetricsActiveWindows" ,&ImGuiIO::MetricsActiveWindows ) - .def_property_readonly("MouseDelta" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return from_vec2(o.MouseDelta);}) - .def_readwrite("WantCaptureMouseUnlessPopupClose" ,&ImGuiIO::WantCaptureMouseUnlessPopupClose ) - .def_readwrite("KeyMods" ,&ImGuiIO::KeyMods ) - .def_readwrite("MousePosPrev" ,&ImGuiIO::MousePosPrev ) - .def_property_readonly("MouseClickedPos" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseClickedPos, ob};}) - .def_property_readonly("MouseClickedTime" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseClickedTime, ob};}) - .def_property_readonly("MouseClicked" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseClicked, ob};}) - .def_property_readonly("MouseDoubleClicked" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseDoubleClicked, ob};}) - .def_property_readonly("MouseClickedCount" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseClickedCount, ob};}) - .def_property_readonly("MouseClickedLastCount" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseClickedLastCount, ob};}) - .def_property_readonly("MouseReleased" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseReleased, ob};}) - .def_property_readonly("MouseDownOwned" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseDownOwned, ob};}) - .def_property_readonly("MouseDownOwnedUnlessPopupClose" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseDownOwnedUnlessPopupClose, ob};}) - .def_property_readonly("MouseDownDuration" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseDownDuration, ob};}) - .def_property_readonly("MouseDownDurationPrev" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseDownDurationPrev, ob};}) - .def_property_readonly("MouseDragMaxDistanceSqr" , [](py::object& ob) { ImGuiIO& o = ob.cast(); return py::array{5, o.MouseDragMaxDistanceSqr, ob};}) - .def_readwrite("PenPressure" ,&ImGuiIO::PenPressure ) - .def_readwrite("AppFocusLost" ,&ImGuiIO::AppFocusLost ) - .def_readwrite("InputQueueSurrogate" ,&ImGuiIO::InputQueueSurrogate ) - .def_readwrite("InputQueueCharacters" ,&ImGuiIO::InputQueueCharacters ) + nb::class_(m, "ImGuiIO") + .def_rw("DisplaySize" ,&ImGuiIO::DisplaySize ) + .def_rw("DeltaTime" ,&ImGuiIO::DeltaTime ) + .def_rw("IniSavingRate" ,&ImGuiIO::IniSavingRate ) + .def_rw("IniFilename" ,&ImGuiIO::IniFilename ) + .def_rw("MouseDoubleClickTime" ,&ImGuiIO::MouseDoubleClickTime ) + .def_rw("MouseDoubleClickMaxDist" ,&ImGuiIO::MouseDoubleClickMaxDist ) + .def_rw("MouseDragThreshold" ,&ImGuiIO::MouseDragThreshold ) + .def_rw("KeyRepeatDelay" ,&ImGuiIO::KeyRepeatDelay ) + .def_rw("KeyRepeatRate" ,&ImGuiIO::KeyRepeatRate ) + .def_rw("Fonts" ,&ImGuiIO::Fonts ) + .def_rw("FontGlobalScale" ,&ImGuiIO::FontGlobalScale ) + .def_rw("FontAllowUserScaling" ,&ImGuiIO::FontAllowUserScaling ) + .def_rw("FontDefault" ,&ImGuiIO::FontDefault ) + .def_rw("DisplayFramebufferScale" ,&ImGuiIO::DisplayFramebufferScale ) + .def_rw("MouseDrawCursor" ,&ImGuiIO::MouseDrawCursor ) + .def_rw("ConfigMacOSXBehaviors" ,&ImGuiIO::ConfigMacOSXBehaviors ) + .def_rw("ConfigInputTextCursorBlink" ,&ImGuiIO::ConfigInputTextCursorBlink ) + .def_rw("ConfigDragClickToInputText" ,&ImGuiIO::ConfigDragClickToInputText ) + .def_rw("ConfigWindowsResizeFromEdges" ,&ImGuiIO::ConfigWindowsResizeFromEdges ) + .def_rw("ConfigWindowsMoveFromTitleBarOnly" ,&ImGuiIO::ConfigWindowsMoveFromTitleBarOnly ) + .def_rw("ConfigMemoryCompactTimer" ,&ImGuiIO::ConfigMemoryCompactTimer ) + .def_prop_ro("MousePos" , [](ImGuiIO& o) { return from_vec2(o.MousePos);} ) + .def_prop_ro("MouseDown" , [](ImGuiIO& o) { return std::to_array(o.MouseDown);} ) + .def_rw("MouseWheel" ,&ImGuiIO::MouseWheel ) + .def_rw("MouseWheelH" ,&ImGuiIO::MouseWheelH ) + .def_rw("KeyCtrl" ,&ImGuiIO::KeyCtrl ) + .def_rw("KeyShift" ,&ImGuiIO::KeyShift ) + .def_rw("KeyAlt" ,&ImGuiIO::KeyAlt ) + .def_rw("KeySuper" ,&ImGuiIO::KeySuper ) + .def_rw("WantCaptureMouse" ,&ImGuiIO::WantCaptureMouse ) + .def_rw("WantCaptureKeyboard" ,&ImGuiIO::WantCaptureKeyboard ) + .def_rw("WantTextInput" ,&ImGuiIO::WantTextInput ) + .def_rw("WantSetMousePos" ,&ImGuiIO::WantSetMousePos ) + .def_rw("WantSaveIniSettings" ,&ImGuiIO::WantSaveIniSettings ) + .def_rw("NavActive" ,&ImGuiIO::NavActive ) + .def_rw("NavVisible" ,&ImGuiIO::NavVisible ) + .def_rw("Framerate" ,&ImGuiIO::Framerate ) + .def_rw("MetricsRenderVertices" ,&ImGuiIO::MetricsRenderVertices ) + .def_rw("MetricsRenderIndices" ,&ImGuiIO::MetricsRenderIndices ) + .def_rw("MetricsRenderWindows" ,&ImGuiIO::MetricsRenderWindows ) + .def_rw("MetricsActiveWindows" ,&ImGuiIO::MetricsActiveWindows ) + .def_prop_ro("MouseDelta" , [](ImGuiIO& o) { return from_vec2(o.MouseDelta);}) + .def_rw("WantCaptureMouseUnlessPopupClose" ,&ImGuiIO::WantCaptureMouseUnlessPopupClose ) + .def_rw("KeyMods" ,&ImGuiIO::KeyMods ) + .def_rw("MousePosPrev" ,&ImGuiIO::MousePosPrev ) + .def_prop_ro("MouseClickedPos" , [](ImGuiIO& o) { return std::to_array(o.MouseClickedPos); }) + .def_prop_ro("MouseClickedTime" , [](ImGuiIO& o) { return std::to_array(o.MouseClickedTime); }) + .def_prop_ro("MouseClicked" , [](ImGuiIO& o) { return std::to_array(o.MouseClicked); }) + .def_prop_ro("MouseDoubleClicked" , [](ImGuiIO& o) { return std::to_array(o.MouseDoubleClicked); }) + .def_prop_ro("MouseClickedCount" , [](ImGuiIO& o) { return std::to_array(o.MouseClickedCount); }) + .def_prop_ro("MouseClickedLastCount" , [](ImGuiIO& o) { return std::to_array(o.MouseClickedLastCount); }) + .def_prop_ro("MouseReleased" , [](ImGuiIO& o) { return std::to_array(o.MouseReleased); }) + .def_prop_ro("MouseDownOwned" , [](ImGuiIO& o) { return std::to_array(o.MouseDownOwned); }) + .def_prop_ro("MouseDownOwnedUnlessPopupClose" , [](ImGuiIO& o) { return std::to_array(o.MouseDownOwnedUnlessPopupClose); }) + .def_prop_ro("MouseDownDuration" , [](ImGuiIO& o) { return std::to_array(o.MouseDownDuration); }) + .def_prop_ro("MouseDownDurationPrev" , [](ImGuiIO& o) { return std::to_array(o.MouseDownDurationPrev); }) + .def_prop_ro("MouseDragMaxDistanceSqr" , [](ImGuiIO& o) { return std::to_array(o.MouseDragMaxDistanceSqr); }) + .def_rw("PenPressure" ,&ImGuiIO::PenPressure ) + .def_rw("AppFocusLost" ,&ImGuiIO::AppFocusLost ) + .def_rw("InputQueueSurrogate" ,&ImGuiIO::InputQueueSurrogate ) + .def_rw("InputQueueCharacters" ,&ImGuiIO::InputQueueCharacters ) ; - py::class_(m, "ImFontAtlas") + nb::class_(m, "ImFontAtlas") .def("AddFontFromFileTTF", - [](py::object& ob, std::string filename, float size_pixels) { ImFontAtlas& o = ob.cast(); return o.AddFontFromFileTTF(filename.c_str(), size_pixels);}, - py::return_value_policy::reference) + [](ImFontAtlas& o, std::string filename, float size_pixels) { + return o.AddFontFromFileTTF(filename.c_str(), size_pixels);}, + nb::rv_policy::reference) // TODO add bindings to the rest of the font functions ; - py::class_(m, "ImFont") + nb::class_(m, "ImFont") // TODO add bindings to the rest of the font functions @@ -137,28 +134,27 @@ void bind_imgui_structs(py::module& m) { // Table sorting - py::class_(m, "ImGuiTableSortSpecs") - .def("Specs", [](py::object& ob) { - ImGuiTableSortSpecs& o = ob.cast(); + nb::class_(m, "ImGuiTableSortSpecs") + .def("Specs", [](ImGuiTableSortSpecs& o) { std::vector specs; for (int i = 0; i < o.SpecsCount; i++) { specs.push_back(o.Specs[i]); } return specs;} ) - .def_readonly("SpecsCount", &ImGuiTableSortSpecs::SpecsCount) - .def_readwrite("SpecsDirty", &ImGuiTableSortSpecs::SpecsDirty) + .def_ro("SpecsCount", &ImGuiTableSortSpecs::SpecsCount) + .def_rw("SpecsDirty", &ImGuiTableSortSpecs::SpecsDirty) ; - py::class_(m, "ImGuiTableColumnSortSpecs") - .def_readonly("ColumnUserID", &ImGuiTableColumnSortSpecs::ColumnUserID) - .def_readonly("ColumnIndex", &ImGuiTableColumnSortSpecs::ColumnIndex) - .def_readonly("SortOrder", &ImGuiTableColumnSortSpecs::SortOrder) - .def_readonly("SortDirection", &ImGuiTableColumnSortSpecs::SortDirection) + nb::class_(m, "ImGuiTableColumnSortSpecs") + .def_ro("ColumnUserID", &ImGuiTableColumnSortSpecs::ColumnUserID) + .def_ro("ColumnIndex", &ImGuiTableColumnSortSpecs::ColumnIndex) + .def_ro("SortOrder", &ImGuiTableColumnSortSpecs::SortOrder) + .def_ro("SortDirection", &ImGuiTableColumnSortSpecs::SortDirection) ; #define VEC2_PROPERTY(name) \ - def_property(#name, [](const ImGuiStyle& style) { \ + def_prop_rw(#name, [](const ImGuiStyle& style) { \ return from_vec2(style.name); \ }, [](ImGuiStyle& style, const Vec2T& value) { \ style.name = to_vec2(value); \ @@ -166,100 +162,106 @@ void bind_imgui_structs(py::module& m) { // Style - py::class_(m, "ImGuiStyle") - .def_readwrite("Alpha", &ImGuiStyle::Alpha) // float - .def_readwrite("DisabledAlpha", &ImGuiStyle::DisabledAlpha) // float - .VEC2_PROPERTY(WindowPadding) // ImVec2 - .def_readwrite("WindowRounding", &ImGuiStyle::WindowRounding) // float - .def_readwrite("WindowBorderSize", &ImGuiStyle::WindowBorderSize) // float - .def_readwrite("WindowBorderHoverPadding", &ImGuiStyle::WindowBorderHoverPadding) // float - .VEC2_PROPERTY(WindowMinSize) // ImVec2 - .VEC2_PROPERTY(WindowTitleAlign) // ImVec2 - .def_readwrite("WindowMenuButtonPosition", &ImGuiStyle::WindowMenuButtonPosition) // ImGuiDir - .def_readwrite("ChildRounding", &ImGuiStyle::ChildRounding) // float - .def_readwrite("ChildBorderSize", &ImGuiStyle::ChildBorderSize) // float - .def_readwrite("PopupRounding", &ImGuiStyle::PopupRounding) // float - .def_readwrite("PopupBorderSize", &ImGuiStyle::PopupBorderSize) // float - .VEC2_PROPERTY(FramePadding) // ImVec2 - .def_readwrite("FrameRounding", &ImGuiStyle::FrameRounding) // float - .def_readwrite("FrameBorderSize", &ImGuiStyle::FrameBorderSize) // float - .VEC2_PROPERTY(ItemSpacing) // ImVec2 - .VEC2_PROPERTY(ItemInnerSpacing) // ImVec2 - .VEC2_PROPERTY(CellPadding) // ImVec2 - .VEC2_PROPERTY(TouchExtraPadding) // ImVec2 - .def_readwrite("IndentSpacing", &ImGuiStyle::IndentSpacing) // float - .def_readwrite("ColumnsMinSpacing", &ImGuiStyle::ColumnsMinSpacing) // float - .def_readwrite("ScrollbarSize", &ImGuiStyle::ScrollbarSize) // float - .def_readwrite("ScrollbarRounding", &ImGuiStyle::ScrollbarRounding) // float - .def_readwrite("GrabMinSize", &ImGuiStyle::GrabMinSize) // float - .def_readwrite("GrabRounding", &ImGuiStyle::GrabRounding) // float - .def_readwrite("LogSliderDeadzone", &ImGuiStyle::LogSliderDeadzone) // float - .def_readwrite("ImageBorderSize", &ImGuiStyle::ImageBorderSize) // float - .def_readwrite("TabRounding", &ImGuiStyle::TabRounding) // float - .def_readwrite("TabBorderSize", &ImGuiStyle::TabBorderSize) // float - .def_readwrite("TabCloseButtonMinWidthSelected", &ImGuiStyle::TabCloseButtonMinWidthSelected) // float - .def_readwrite("TabCloseButtonMinWidthUnselected", &ImGuiStyle::TabCloseButtonMinWidthUnselected) // float - .def_readwrite("TabBarBorderSize", &ImGuiStyle::TabBarBorderSize) // float - .def_readwrite("TabBarOverlineSize", &ImGuiStyle::TabBarOverlineSize) // float - .def_readwrite("TableAngledHeadersAngle", &ImGuiStyle::TableAngledHeadersAngle) // float - .VEC2_PROPERTY(TableAngledHeadersTextAlign) // ImVec2 - .def_readwrite("ColorButtonPosition", &ImGuiStyle::ColorButtonPosition) // ImGuiDir - .VEC2_PROPERTY(ButtonTextAlign) // ImVec2 - .VEC2_PROPERTY(SelectableTextAlign) // ImVec2 - .def_readwrite("SeparatorTextBorderSize", &ImGuiStyle::SeparatorTextBorderSize) // float - .VEC2_PROPERTY(SeparatorTextAlign) // ImVec2 - .VEC2_PROPERTY(SeparatorTextPadding) // ImVec2 - .VEC2_PROPERTY(DisplayWindowPadding) // ImVec2 - .VEC2_PROPERTY(DisplaySafeAreaPadding) // ImVec2 - .def_readwrite("MouseCursorScale", &ImGuiStyle::MouseCursorScale) // float - .def_readwrite("AntiAliasedLines", &ImGuiStyle::AntiAliasedLines) // bool - .def_readwrite("AntiAliasedLinesUseTex", &ImGuiStyle::AntiAliasedLinesUseTex) // bool - .def_readwrite("AntiAliasedFill", &ImGuiStyle::AntiAliasedFill) // bool - .def_readwrite("CurveTessellationTol", &ImGuiStyle::CurveTessellationTol) // float - .def_readwrite("CircleTessellationMaxError", &ImGuiStyle::CircleTessellationMaxError) // float + nb::class_(m, "ImGuiStyle") + .def_rw("Alpha", &ImGuiStyle::Alpha) // float + .def_rw("DisabledAlpha", &ImGuiStyle::DisabledAlpha) // float + .VEC2_PROPERTY(WindowPadding) // ImVec2 + .def_rw("WindowRounding", &ImGuiStyle::WindowRounding) // float + .def_rw("WindowBorderSize", &ImGuiStyle::WindowBorderSize) // float + .def_rw("WindowBorderHoverPadding", &ImGuiStyle::WindowBorderHoverPadding) // float + .VEC2_PROPERTY(WindowMinSize) // ImVec2 + .VEC2_PROPERTY(WindowTitleAlign) // ImVec2 + .def_rw("WindowMenuButtonPosition", &ImGuiStyle::WindowMenuButtonPosition) // ImGuiDir + .def_rw("ChildRounding", &ImGuiStyle::ChildRounding) // float + .def_rw("ChildBorderSize", &ImGuiStyle::ChildBorderSize) // float + .def_rw("PopupRounding", &ImGuiStyle::PopupRounding) // float + .def_rw("PopupBorderSize", &ImGuiStyle::PopupBorderSize) // float + .VEC2_PROPERTY(FramePadding) // ImVec2 + .def_rw("FrameRounding", &ImGuiStyle::FrameRounding) // float + .def_rw("FrameBorderSize", &ImGuiStyle::FrameBorderSize) // float + .VEC2_PROPERTY(ItemSpacing) // ImVec2 + .VEC2_PROPERTY(ItemInnerSpacing) // ImVec2 + .VEC2_PROPERTY(CellPadding) // ImVec2 + .VEC2_PROPERTY(TouchExtraPadding) // ImVec2 + .def_rw("IndentSpacing", &ImGuiStyle::IndentSpacing) // float + .def_rw("ColumnsMinSpacing", &ImGuiStyle::ColumnsMinSpacing) // float + .def_rw("ScrollbarSize", &ImGuiStyle::ScrollbarSize) // float + .def_rw("ScrollbarRounding", &ImGuiStyle::ScrollbarRounding) // float + .def_rw("GrabMinSize", &ImGuiStyle::GrabMinSize) // float + .def_rw("GrabRounding", &ImGuiStyle::GrabRounding) // float + .def_rw("LogSliderDeadzone", &ImGuiStyle::LogSliderDeadzone) // float + .def_rw("ImageBorderSize", &ImGuiStyle::ImageBorderSize) // float + .def_rw("TabRounding", &ImGuiStyle::TabRounding) // float + .def_rw("TabBorderSize", &ImGuiStyle::TabBorderSize) // float + .def_rw("TabCloseButtonMinWidthSelected", &ImGuiStyle::TabCloseButtonMinWidthSelected) // float + .def_rw("TabCloseButtonMinWidthUnselected", &ImGuiStyle::TabCloseButtonMinWidthUnselected) // float + .def_rw("TabBarBorderSize", &ImGuiStyle::TabBarBorderSize) // float + .def_rw("TabBarOverlineSize", &ImGuiStyle::TabBarOverlineSize) // float + .def_rw("TableAngledHeadersAngle", &ImGuiStyle::TableAngledHeadersAngle) // float + .VEC2_PROPERTY(TableAngledHeadersTextAlign) // ImVec2 + .def_rw("ColorButtonPosition", &ImGuiStyle::ColorButtonPosition) // ImGuiDir + .VEC2_PROPERTY(ButtonTextAlign) // ImVec2 + .VEC2_PROPERTY(SelectableTextAlign) // ImVec2 + .def_rw("SeparatorTextBorderSize", &ImGuiStyle::SeparatorTextBorderSize) // float + .VEC2_PROPERTY(SeparatorTextAlign) // ImVec2 + .VEC2_PROPERTY(SeparatorTextPadding) // ImVec2 + .VEC2_PROPERTY(DisplayWindowPadding) // ImVec2 + .VEC2_PROPERTY(DisplaySafeAreaPadding) // ImVec2 + .def_rw("MouseCursorScale", &ImGuiStyle::MouseCursorScale) // float + .def_rw("AntiAliasedLines", &ImGuiStyle::AntiAliasedLines) // bool + .def_rw("AntiAliasedLinesUseTex", &ImGuiStyle::AntiAliasedLinesUseTex) // bool + .def_rw("AntiAliasedFill", &ImGuiStyle::AntiAliasedFill) // bool + .def_rw("CurveTessellationTol", &ImGuiStyle::CurveTessellationTol) // float + .def_rw("CircleTessellationMaxError", &ImGuiStyle::CircleTessellationMaxError) // float + + // FIXME + // .def_rw("Colors", &ImGuiStyle::Colors) // Colors (ImVec4[ImGuiCol_COUNT]) // Note: having explicit getter and setter functions for colors will avoid accidental no-ops such as: // style.Colors[2] = ... + // FIXME + /* .def("GetColors", [](const ImGuiStyle &o) { - py::list colors; + nb::list colors; for (int i = 0; i < ImGuiCol_COUNT; i++) { colors.append(from_vec4(o.Colors[i])); } return colors; }) - .def("SetColors", [](ImGuiStyle &o, const py::list& colors) { + .def("SetColors", [](ImGuiStyle &o, const nb::list& colors) { if (colors.size() != ImGuiCol_COUNT) { throw std::runtime_error("Expected " + std::to_string(ImGuiCol_COUNT) + " colors, got " + std::to_string(colors.size())); } for (int i = 0; i < ImGuiCol_COUNT; i++) { - if (py::len(colors[i]) != 4) { + if (nb::len(colors[i]) != 4) { throw std::runtime_error("Expected 4 elements for color " + std::to_string(i) - + ", got " + std::to_string(py::len(colors[i]))); + + ", got " + std::to_string(nb::len(colors[i]))); } - o.Colors[i] = to_vec4(py::cast(colors[i])); + o.Colors[i] = to_vec4(nb::cast(colors[i])); } - }, py::arg("colors")) + }, nb::arg("colors")) + */ // Behaviors // (It is possible to modify those fields mid-frame if specific behavior need it, unlike e.g. configuration fields in ImGuiIO) - .def_readwrite("HoverStationaryDelay", &ImGuiStyle::HoverStationaryDelay) // float - .def_readwrite("HoverDelayShort", &ImGuiStyle::HoverDelayShort) // float - .def_readwrite("HoverDelayNormal", &ImGuiStyle::HoverDelayNormal) // float - .def_readwrite("HoverFlagsForTooltipMouse", &ImGuiStyle::HoverFlagsForTooltipMouse) // ImGuiHoveredFlags - .def_readwrite("HoverFlagsForTooltipNav", &ImGuiStyle::HoverFlagsForTooltipNav) // ImGuiHoveredFlags + .def_rw("HoverStationaryDelay", &ImGuiStyle::HoverStationaryDelay) // float + .def_rw("HoverDelayShort", &ImGuiStyle::HoverDelayShort) // float + .def_rw("HoverDelayNormal", &ImGuiStyle::HoverDelayNormal) // float + .def_rw("HoverFlagsForTooltipMouse", &ImGuiStyle::HoverFlagsForTooltipMouse) // ImGuiHoveredFlags + .def_rw("HoverFlagsForTooltipNav", &ImGuiStyle::HoverFlagsForTooltipNav) // ImGuiHoveredFlags .def("ScaleAllSizes", &ImGuiStyle::ScaleAllSizes); #undef VEC2_PROPERTY } -void bind_imgui_methods(py::module& m) { +void bind_imgui_methods(nb::module_& m) { // Main - m.def("GetIO", &ImGui::GetIO, py::return_value_policy::reference); - m.def("GetStyle", &ImGui::GetStyle, py::return_value_policy::reference); + m.def("GetIO", &ImGui::GetIO, nb::rv_policy::reference); + m.def("GetStyle", &ImGui::GetStyle, nb::rv_policy::reference); // Windows m.def( @@ -268,30 +270,30 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::Begin(name, &open, flags); return std::make_tuple(clicked, open); }, - py::arg("name"), - py::arg("open"), - py::arg("flags") = 0); + nb::arg("name"), + nb::arg("open"), + nb::arg("flags") = 0); m.def("End", []() { ImGui::End(); }); // Child Windows m.def( "BeginChild", - [](const char* str_id, const Vec2T& size, bool border, ImGuiWindowFlags flags) { + [](const char* str_id, Vec2T size, bool border, ImGuiWindowFlags flags) { return ImGui::BeginChild(str_id, to_vec2(size), border, flags); }, - py::arg("str_id"), - py::arg("size") = std::make_tuple(0.f, 0.f), - py::arg("border") = false, - py::arg("flags") = 0); + nb::arg("str_id"), + nb::arg("size") = Vec2T(0.f, 0.f), + nb::arg("border") = false, + nb::arg("flags") = 0); m.def( "BeginChild", [](ImGuiID id, const Vec2T& size, bool border, ImGuiWindowFlags flags) { return ImGui::BeginChild(id, to_vec2(size), border, flags); }, - py::arg("id"), - py::arg("size") = std::make_tuple(0.f, 0.f), - py::arg("border") = false, - py::arg("flags") = 0); + nb::arg("id"), + nb::arg("size") = Vec2T(0.f, 0.f), + nb::arg("border") = false, + nb::arg("flags") = 0); m.def("EndChild", []() { ImGui::EndChild(); }); // Windows Utilities @@ -300,12 +302,12 @@ void bind_imgui_methods(py::module& m) { m.def( "IsWindowFocused", [](ImGuiFocusedFlags flags) { return ImGui::IsWindowFocused(flags); }, - py::arg("flags") = 0); + nb::arg("flags") = 0); m.def( "IsWindowHovered", [](ImGuiFocusedFlags flags) { return ImGui::IsWindowHovered(flags); }, - py::arg("flags") = 0); - m.def("GetWindowDrawList", []() { return ImGui::GetWindowDrawList(); }, py::return_value_policy::reference); + nb::arg("flags") = 0); + m.def("GetWindowDrawList", []() { return ImGui::GetWindowDrawList(); }, nb::rv_policy::reference); m.def("GetWindowPos", []() { return from_vec2(ImGui::GetWindowPos()); }); m.def("GetWindowSize", []() { return from_vec2(ImGui::GetWindowSize()); }); m.def("GetWindowWidth", []() { return ImGui::GetWindowWidth(); }); @@ -315,78 +317,78 @@ void bind_imgui_methods(py::module& m) { [](const Vec2T& pos, ImGuiCond cond, const Vec2T& pivot) { ImGui::SetNextWindowPos(to_vec2(pos), cond, to_vec2(pivot)); }, - py::arg("pos"), - py::arg("cond") = 0, - py::arg("pivot") = std::make_tuple(0., 0.)); + nb::arg("pos"), + nb::arg("cond") = 0, + nb::arg("pivot") = Vec2T(0., 0.)); m.def( "SetNextWindowSize", [](const Vec2T& size, ImGuiCond cond) { ImGui::SetNextWindowSize(to_vec2(size), cond); }, - py::arg("size"), - py::arg("cond") = 0); + nb::arg("size"), + nb::arg("cond") = 0); m.def( "SetNextWindowSizeConstraints", [](const Vec2T& size_min, const Vec2T& size_max) { ImGui::SetNextWindowSizeConstraints(to_vec2(size_min), to_vec2(size_max)); }, - py::arg("size_min"), - py::arg("size_max")); + nb::arg("size_min"), + nb::arg("size_max")); m.def( "SetNextWindowContextSize", [](const Vec2T& size) { ImGui::SetNextWindowContentSize(to_vec2(size)); }, - py::arg("size")); + nb::arg("size")); m.def( "SetNextWindowCollapsed", [](bool collapsed, ImGuiCond cond) { ImGui::SetNextWindowCollapsed(collapsed, cond); }, - py::arg("collapsed"), - py::arg("cond") = 0); + nb::arg("collapsed"), + nb::arg("cond") = 0); m.def("SetNextWindowFocus", []() { ImGui::SetNextWindowFocus(); }); m.def("SetNextWindowBgAlpha", [](float alpha) { ImGui::SetNextWindowBgAlpha(alpha); }); m.def( "SetWindowPos", [](const Vec2T& pos, ImGuiCond cond) { ImGui::SetWindowPos(to_vec2(pos), cond); }, - py::arg("pos"), - py::arg("cond") = 0); + nb::arg("pos"), + nb::arg("cond") = 0); m.def( "SetWindowSize", [](const Vec2T& size, ImGuiCond cond) { ImGui::SetWindowSize(to_vec2(size), cond); }, - py::arg("size"), - py::arg("cond") = 0); + nb::arg("size"), + nb::arg("cond") = 0); m.def( "SetWindowCollapsed", [](bool collapsed, ImGuiCond cond) { ImGui::SetWindowCollapsed(collapsed, cond); }, - py::arg("collapsed"), - py::arg("cond") = 0); + nb::arg("collapsed"), + nb::arg("cond") = 0); m.def("set_window_focus", []() { ImGui::SetWindowFocus(); }); m.def( "SetWindowFontScale", [](float scale) { ImGui::SetWindowFontScale(scale); }, - py::arg("scale")); + nb::arg("scale")); m.def( "SetWindowPos", [](const char* name, const Vec2T& pos, ImGuiCond cond) { ImGui::SetWindowPos(name, to_vec2(pos), cond); }, - py::arg("name"), - py::arg("pos"), - py::arg("cond") = 0); + nb::arg("name"), + nb::arg("pos"), + nb::arg("cond") = 0); m.def( "SetWindowSize", [](const char* name, const Vec2T& size, ImGuiCond cond) { ImGui::SetWindowSize(name, to_vec2(size), cond); }, - py::arg("name"), - py::arg("size"), - py::arg("cond") = 0); + nb::arg("name"), + nb::arg("size"), + nb::arg("cond") = 0); m.def( "SetWindowCollapsed", [](const char* name, bool collapsed, ImGuiCond cond) { ImGui::SetWindowCollapsed(name, collapsed, cond); }, - py::arg("name"), - py::arg("collapsed"), - py::arg("cond") = 0); + nb::arg("name"), + nb::arg("collapsed"), + nb::arg("cond") = 0); m.def( - "SetWindowFocus", [](const char* name) { ImGui::SetWindowFocus(name); }, py::arg("name")); + "SetWindowFocus", [](const char* name) { ImGui::SetWindowFocus(name); }, nb::arg("name")); // Content region m.def("GetContentRegionMax", []() { @@ -406,29 +408,29 @@ void bind_imgui_methods(py::module& m) { m.def( "SetScrollX", [](float scroll_x) { ImGui::SetScrollX(scroll_x); }, - py::arg("scroll_x")); + nb::arg("scroll_x")); m.def( "SetScrollY", [](float scroll_y) { ImGui::SetScrollY(scroll_y); }, - py::arg("scroll_y")); + nb::arg("scroll_y")); m.def( "SetScrollHereX", [](float center_x_ratio) { ImGui::SetScrollHereX(center_x_ratio); }, - py::arg("center_x_ratio") = 0.5f); + nb::arg("center_x_ratio") = 0.5f); m.def( "SetScrollHereY", [](float center_y_ratio) { ImGui::SetScrollHereY(center_y_ratio); }, - py::arg("center_y_ratio") = 0.5f); + nb::arg("center_y_ratio") = 0.5f); m.def( "SetScrollFromPosX", [](float local_x, float center_x_ratio) { ImGui::SetScrollFromPosX(local_x, center_x_ratio); }, - py::arg("local_x"), - py::arg("center_x_ratio") = 0.5f); + nb::arg("local_x"), + nb::arg("center_x_ratio") = 0.5f); m.def( "SetScrollFromPosY", [](float local_y, float center_y_ratio) { ImGui::SetScrollFromPosY(local_y, center_y_ratio); }, - py::arg("local_y"), - py::arg("center_y_ratio") = 0.5f); + nb::arg("local_y"), + nb::arg("center_y_ratio") = 0.5f); // Parameters stacks (shared) IMGUI_API void PushFont(ImFont* font); // use NULL as a shortcut to push default font @@ -436,7 +438,7 @@ void bind_imgui_methods(py::module& m) { m.def( "PushFont", [](ImFont* font) { ImGui::PushFont(font); }, - py::arg("font")); + nb::arg("font")); m.def( "PopFont", []() { ImGui::PopFont(); } @@ -444,69 +446,69 @@ void bind_imgui_methods(py::module& m) { m.def( "PushStyleColor", [](ImGuiCol idx, ImU32 col) { ImGui::PushStyleColor(idx, col); }, - py::arg("idx"), - py::arg("col")); + nb::arg("idx"), + nb::arg("col")); m.def( "PushStyleColor", [](ImGuiCol idx, const Vec4T& col) { ImGui::PushStyleColor(idx, to_vec4(col)); }, - py::arg("idx"), - py::arg("col")); + nb::arg("idx"), + nb::arg("col")); m.def( - "PopStyleColor", [](int count) { ImGui::PopStyleColor(count); }, py::arg("count") = 1); + "PopStyleColor", [](int count) { ImGui::PopStyleColor(count); }, nb::arg("count") = 1); m.def( "PushStyleVar", [](ImGuiCol idx, float val) { ImGui::PushStyleVar(idx, val); }, - py::arg("idx"), - py::arg("val")); + nb::arg("idx"), + nb::arg("val")); m.def( "PushStyleVar", [](ImGuiCol idx, const Vec2T& val) { ImGui::PushStyleVar(idx, to_vec2(val)); }, - py::arg("idx"), - py::arg("val")); + nb::arg("idx"), + nb::arg("val")); m.def( - "PopStyleVar", [](int count) { ImGui::PopStyleVar(count); }, py::arg("count") = 1); + "PopStyleVar", [](int count) { ImGui::PopStyleVar(count); }, nb::arg("count") = 1); m.def( "GetStyleColorVec4", [](ImGuiCol idx) { return from_vec4(ImGui::GetStyleColorVec4(idx)); }, - py::arg("idx")); + nb::arg("idx")); m.def("GetFontSize", []() { return ImGui::GetFontSize(); }); m.def("GetFontTexUvWhitePixel", []() { return from_vec2(ImGui::GetFontTexUvWhitePixel()); }); m.def( "GetColorU32", [](ImGuiCol idx, float alpha_mul) { return ImGui::GetColorU32(idx, alpha_mul); }, - py::arg("idx"), - py::arg("alpha_mul") = 1.0f); + nb::arg("idx"), + nb::arg("alpha_mul") = 1.0f); m.def( - "GetColorU32", [](const Vec4T& col) { return ImGui::GetColorU32(to_vec4(col)); }, py::arg("col")); + "GetColorU32", [](const Vec4T& col) { return ImGui::GetColorU32(to_vec4(col)); }, nb::arg("col")); m.def( - "GetColorU32", [](ImU32 col) { return ImGui::GetColorU32(col); }, py::arg("col")); + "GetColorU32", [](ImU32 col) { return ImGui::GetColorU32(col); }, nb::arg("col")); // Parameters stacks (current window) m.def( "PushItemWidth", [](float item_width) { return ImGui::PushItemWidth(item_width); }, - py::arg("item_width")); + nb::arg("item_width")); m.def("PopItemWidth", []() { ImGui::PopItemWidth(); }); m.def( "SetNextItemWidth", [](float item_width) { return ImGui::SetNextItemWidth(item_width); }, - py::arg("item_width")); + nb::arg("item_width")); m.def("CalcItemWidth", []() { return ImGui::CalcItemWidth(); }); m.def( "PushTextWrapPos", [](float wrap_local_pos_x) { ImGui::PushTextWrapPos(wrap_local_pos_x); }, - py::arg("wrap_local_pos_x") = 0.0f); + nb::arg("wrap_local_pos_x") = 0.0f); m.def("PopTextWrapPos", []() { ImGui::PopTextWrapPos(); }); m.def( "PushAllowKeyboardFocus", [](bool allow_keyboard_focus) { ImGui::PushAllowKeyboardFocus(allow_keyboard_focus); }, - py::arg("allow_keyboard_focus")); + nb::arg("allow_keyboard_focus")); m.def("PopAllowKeyboardFocus", []() { ImGui::PopAllowKeyboardFocus(); }); m.def( "PushButtonRepeat", [](bool repeat) { ImGui::PushButtonRepeat(repeat); }, - py::arg("allow_keyboard_focus")); + nb::arg("allow_keyboard_focus")); m.def("PopButtonRepeat", []() { ImGui::PopButtonRepeat(); }); // Cursor / Layout @@ -514,15 +516,15 @@ void bind_imgui_methods(py::module& m) { m.def( "SameLine", [](float offset_from_start_x, float spacing) { ImGui::SameLine(); }, - py::arg("offset_from_start_x") = 0.0f, - py::arg("offset") = -1.0f); + nb::arg("offset_from_start_x") = 0.0f, + nb::arg("offset") = -1.0f); m.def("NewLine", []() { ImGui::NewLine(); }); m.def("Spacing", []() { ImGui::Spacing(); }); m.def("Dummy", [](const Vec2T& size) { ImGui::Dummy(to_vec2(size)); }); m.def( - "Indent", [](float indent_w) { ImGui::Indent(indent_w); }, py::arg("indent_w") = 0.f); + "Indent", [](float indent_w) { ImGui::Indent(indent_w); }, nb::arg("indent_w") = 0.f); m.def( - "Unindent", [](float indent_w) { ImGui::Unindent(indent_w); }, py::arg("indent_w") = 0.f); + "Unindent", [](float indent_w) { ImGui::Unindent(indent_w); }, nb::arg("indent_w") = 0.f); m.def("BeginGroup", []() { ImGui::BeginGroup(); }); m.def("EndGroup", []() { ImGui::EndGroup(); }); m.def("GetCursorPos", []() { return from_vec2(ImGui::GetCursorPos()); }); @@ -531,21 +533,21 @@ void bind_imgui_methods(py::module& m) { m.def( "SetCursorPos", [](const Vec2T& local_pos) { ImGui::SetCursorPos(to_vec2(local_pos)); }, - py::arg("local_pos")); + nb::arg("local_pos")); m.def( "SetCursorPosX", [](float local_x) { ImGui::SetCursorPosX(local_x); }, - py::arg("local_x")); + nb::arg("local_x")); m.def( "SetCursorPosY", [](float local_y) { ImGui::SetCursorPosY(local_y); }, - py::arg("local_y")); + nb::arg("local_y")); m.def("GetCursorStartPos", []() { return from_vec2(ImGui::GetCursorStartPos()); }); m.def("GetCursorScreenPos", []() { return from_vec2(ImGui::GetCursorScreenPos()); }); m.def( "SetCursorScreenPos", [](const Vec2T& pos) { ImGui::SetCursorScreenPos(to_vec2(pos)); }, - py::arg("pos")); + nb::arg("pos")); m.def("AlignTextToFramePadding", []() { ImGui::AlignTextToFramePadding(); }); m.def("GetTextLineHeight", []() { return ImGui::GetTextLineHeight(); }); m.def("GetTextLineHeightWithSpacing", []() { return ImGui::GetTextLineHeightWithSpacing(); }); @@ -554,109 +556,109 @@ void bind_imgui_methods(py::module& m) { // ID stack/scopes m.def( - "PushID", [](const char* str_id) { ImGui::PushID(str_id); }, py::arg("str_id")); + "PushID", [](const char* str_id) { ImGui::PushID(str_id); }, nb::arg("str_id")); m.def( - "PushID", [](int int_id) { ImGui::PushID(int_id); }, py::arg("int_id")); + "PushID", [](int int_id) { ImGui::PushID(int_id); }, nb::arg("int_id")); m.def("PopID", []() { ImGui::PopID(); }); m.def( - "GetID", [](const char* str_id) { return ImGui::GetID(str_id); }, py::arg("str_id")); + "GetID", [](const char* str_id) { return ImGui::GetID(str_id); }, nb::arg("str_id")); // these are typos (bad capitalization). kept around to avoid needless breaking changes m.def( - "PushId", [](const char* str_id) { ImGui::PushID(str_id); }, py::arg("str_id")); + "PushId", [](const char* str_id) { ImGui::PushID(str_id); }, nb::arg("str_id")); m.def( - "PushId", [](int int_id) { ImGui::PushID(int_id); }, py::arg("int_id")); + "PushId", [](int int_id) { ImGui::PushID(int_id); }, nb::arg("int_id")); m.def( - "GetId", [](const char* str_id) { return ImGui::GetID(str_id); }, py::arg("str_id")); + "GetId", [](const char* str_id) { return ImGui::GetID(str_id); }, nb::arg("str_id")); // Widgets: Text m.def( - "TextUnformatted", [](const char* text) { ImGui::TextUnformatted(text); }, py::arg("text")); + "TextUnformatted", [](const char* text) { ImGui::TextUnformatted(text); }, nb::arg("text")); m.def( - "Text", [](const char* text) { ImGui::Text("%s", text); }, py::arg("text")); + "Text", [](const char* text) { ImGui::Text("%s", text); }, nb::arg("text")); m.def( "TextColored", [](const Vec4T& color, const char* text) { ImGui::TextColored(to_vec4(color), "%s", text); }, - py::arg("color"), - py::arg("text")); + nb::arg("color"), + nb::arg("text")); m.def( - "TextDisabled", [](const char* text) { ImGui::TextDisabled("%s", text); }, py::arg("text")); + "TextDisabled", [](const char* text) { ImGui::TextDisabled("%s", text); }, nb::arg("text")); m.def( - "TextWrapped", [](const char* text) { ImGui::TextWrapped("%s", text); }, py::arg("text")); + "TextWrapped", [](const char* text) { ImGui::TextWrapped("%s", text); }, nb::arg("text")); m.def( "LabelText", [](const char* label, const char* text) { ImGui::LabelText(label, "%s", text); }, - py::arg("label"), - py::arg("text")); + nb::arg("label"), + nb::arg("text")); m.def( "BulletText", [](const char* fmt) { ImGui::BulletText("%s", fmt); }, - py::arg("text")); + nb::arg("text")); m.def( "SeparatorText", [](const char* label) { ImGui::SeparatorText(label); }, - py::arg("label")); + nb::arg("label")); // Widgets: Main m.def( "Button", [](const char* label, const Vec2T& size) { return ImGui::Button(label, to_vec2(size)); }, - py::arg("label"), - py::arg("size") = std::make_tuple(0.f, 0.f)); + nb::arg("label"), + nb::arg("size") = Vec2T(0.f, 0.f)); m.def( "SmallButton", [](const char* label) { return ImGui::SmallButton(label); }, - py::arg("label")); + nb::arg("label")); m.def( "InvisibleButton", [](const char* str_id, const Vec2T& size) { return ImGui::InvisibleButton(str_id, to_vec2(size)); }, - py::arg("str_id"), - py::arg("size")); + nb::arg("str_id"), + nb::arg("size")); m.def( "ArrowButton", [](const char* str_id, ImGuiDir dir) { return ImGui::ArrowButton(str_id, dir); }, - py::arg("str_id"), - py::arg("dir")); + nb::arg("str_id"), + nb::arg("dir")); m.def( "Checkbox", [](const char* label, bool v) { const auto clicked = ImGui::Checkbox(label, &v); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v")); + nb::arg("label"), + nb::arg("v")); m.def( "CheckboxFlags", [](const char* label, unsigned int flags, unsigned int flags_value) { const auto clicked = ImGui::CheckboxFlags(label, &flags, flags_value); return std::make_tuple(clicked, flags); }, - py::arg("label"), - py::arg("flags"), - py::arg("flags_value")); + nb::arg("label"), + nb::arg("flags"), + nb::arg("flags_value")); m.def( "RadioButton", [](const char* label, bool active) { return ImGui::RadioButton(label, active); }, - py::arg("label"), - py::arg("active")); + nb::arg("label"), + nb::arg("active")); m.def( "RadioButton", [](const char* label, int v, int v_button) { const auto clicked = ImGui::RadioButton(label, &v, v_button); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_button")); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_button")); m.def( "ProgressBar", [](float fraction, const Vec2T& size_arg) { ImGui::ProgressBar(fraction, to_vec2(size_arg)); }, - py::arg("fraction"), - py::arg("size_arg") = std::make_tuple(-1.f, 0.f)); + nb::arg("fraction"), + nb::arg("size_arg") = Vec2T(-1.f, 0.f)); m.def("Bullet", []() { ImGui::Bullet(); }); // Widgets: Image @@ -665,34 +667,34 @@ void bind_imgui_methods(py::module& m) { [](ImTextureID user_texture_id, const Vec2T& image_size, const Vec2T& uv0, const Vec2T& uv1) { ImGui::Image(user_texture_id, to_vec2(image_size), to_vec2(uv0), to_vec2(uv1)); }, - py::arg("user_texture_id"), - py::arg("image_size"), - py::arg("uv0") = Vec2T(0.0f, 0.0f), - py::arg("uv1") = Vec2T(1.0f, 1.0f)); + nb::arg("user_texture_id"), + nb::arg("image_size"), + nb::arg("uv0") = Vec2T(0.0f, 0.0f), + nb::arg("uv1") = Vec2T(1.0f, 1.0f)); m.def( "ImageWithBg", [](ImTextureID user_texture_id, const Vec2T& image_size, const Vec2T& uv0, const Vec2T& uv1, const Vec4T& bg_col, const Vec4T& tint_col) { ImGui::ImageWithBg(user_texture_id, to_vec2(image_size), to_vec2(uv0), to_vec2(uv1), to_vec4(bg_col), to_vec4(tint_col)); }, - py::arg("user_texture_id"), - py::arg("image_size"), - py::arg("uv0") = Vec2T(0.0f, 0.0f), - py::arg("uv1") = Vec2T(1.0f, 1.0f), - py::arg("bg_col") = Vec4T(0.0f, 0.0f, 0.0f, 0.0f), - py::arg("tint_col") = Vec4T(1.0f, 1.0f, 1.0f, 1.0f)); + nb::arg("user_texture_id"), + nb::arg("image_size"), + nb::arg("uv0") = Vec2T(0.0f, 0.0f), + nb::arg("uv1") = Vec2T(1.0f, 1.0f), + nb::arg("bg_col") = Vec4T(0.0f, 0.0f, 0.0f, 0.0f), + nb::arg("tint_col") = Vec4T(1.0f, 1.0f, 1.0f, 1.0f)); m.def( "ImageButton", [](const char* str_id, ImTextureID user_texture_id, const Vec2T& image_size, const Vec2T& uv0, const Vec2T& uv1, const Vec4T& bg_col, const Vec4T& tint_col) { return ImGui::ImageButton(str_id, user_texture_id, to_vec2(image_size), to_vec2(uv0), to_vec2(uv1), to_vec4(bg_col), to_vec4(tint_col)); }, - py::arg("str_id"), - py::arg("user_texture_id"), - py::arg("image_size"), - py::arg("uv0") = Vec2T(0.0f, 0.0f), - py::arg("uv1") = Vec2T(1.0f, 1.0f), - py::arg("bg_col") = Vec4T(0.0f, 0.0f, 0.0f, 0.0f), - py::arg("tint_col") = Vec4T(1.0f, 1.0f, 1.0f, 1.0f)); + nb::arg("str_id"), + nb::arg("user_texture_id"), + nb::arg("image_size"), + nb::arg("uv0") = Vec2T(0.0f, 0.0f), + nb::arg("uv1") = Vec2T(1.0f, 1.0f), + nb::arg("bg_col") = Vec4T(0.0f, 0.0f, 0.0f, 0.0f), + nb::arg("tint_col") = Vec4T(1.0f, 1.0f, 1.0f, 1.0f)); // Widgets: Combo Box @@ -701,9 +703,9 @@ void bind_imgui_methods(py::module& m) { [](const char* label, const char* preview_value, ImGuiComboFlags flags) { return ImGui::BeginCombo(label, preview_value, flags); }, - py::arg("label"), - py::arg("preview_value"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("preview_value"), + nb::arg("flags") = 0); m.def("EndCombo", []() { ImGui::EndCombo(); }); m.def( "Combo", @@ -716,10 +718,10 @@ void bind_imgui_methods(py::module& m) { label, ¤t_item, _items.data(), _items.size(), popup_max_height_in_items); return std::make_tuple(clicked, current_item); }, - py::arg("label"), - py::arg("current_item"), - py::arg("items"), - py::arg("popup_max_height_in_items") = -1); + nb::arg("label"), + nb::arg("current_item"), + nb::arg("items"), + nb::arg("popup_max_height_in_items") = -1); m.def( "Combo", [](const char* label, @@ -730,10 +732,10 @@ void bind_imgui_methods(py::module& m) { label, ¤t_item, items_separated_by_zeros, popup_max_height_in_items); return std::make_tuple(clicked, current_item); }, - py::arg("label"), - py::arg("current_item"), - py::arg("items_separated_by_zeros"), - py::arg("popup_max_height_in_items") = -1); + nb::arg("label"), + nb::arg("current_item"), + nb::arg("items_separated_by_zeros"), + nb::arg("popup_max_height_in_items") = -1); // Widgets: Drags m.def( @@ -748,13 +750,13 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::DragFloat(label, &v, v_speed, v_min, v_max, format, power); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_speed") = 1.0f, - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("power") = 1.0f); m.def( "DragFloat2", [](const char* label, @@ -768,13 +770,13 @@ void bind_imgui_methods(py::module& m) { ImGui::DragFloat2(label, v.data(), v_speed, v_min, v_max, format, power); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_speed") = 1.0f, - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("power") = 1.0f); m.def( "DragFloat3", [](const char* label, @@ -788,13 +790,13 @@ void bind_imgui_methods(py::module& m) { ImGui::DragFloat3(label, v.data(), v_speed, v_min, v_max, format, power); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_speed") = 1.0f, - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("power") = 1.0f); m.def( "DragFloat4", [](const char* label, @@ -808,13 +810,13 @@ void bind_imgui_methods(py::module& m) { ImGui::DragFloat4(label, v.data(), v_speed, v_min, v_max, format, power); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_speed") = 1.0f, - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("power") = 1.0f); m.def( "DragFloatRange2", [](const char* label, @@ -837,15 +839,15 @@ void bind_imgui_methods(py::module& m) { power); return std::make_tuple(clicked, v_current_min, v_current_max); }, - py::arg("label"), - py::arg("v_current_min"), - py::arg("v_current_max"), - py::arg("v_speed") = 1.0f, - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("format_max") = nullptr, - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v_current_min"), + nb::arg("v_current_max"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("format_max") = nullptr, + nb::arg("power") = 1.0f); m.def( "DragInt", @@ -853,12 +855,12 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::DragInt(label, &v, v_speed, v_min, v_max, format); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_speed") = 1.0f, - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d"); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d"); m.def( "DragInt2", [](const char* label, @@ -870,12 +872,12 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::DragInt2(label, v.data(), v_speed, v_min, v_max, format); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_speed") = 1.0f, - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d"); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d"); m.def( "DragInt3", [](const char* label, @@ -887,12 +889,12 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::DragInt3(label, v.data(), v_speed, v_min, v_max, format); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_speed") = 1.0f, - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d"); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d"); m.def( "DragInt4", [](const char* label, @@ -904,12 +906,12 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::DragInt4(label, v.data(), v_speed, v_min, v_max, format); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_speed") = 1.0f, - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d"); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d"); m.def( "DragIntRange2", [](const char* label, @@ -930,14 +932,14 @@ void bind_imgui_methods(py::module& m) { format_max); return std::make_tuple(clicked, v_current_min, v_current_max); }, - py::arg("label"), - py::arg("v_current_min"), - py::arg("v_current_max"), - py::arg("v_speed") = 1.0f, - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d", - py::arg("format_max") = nullptr); + nb::arg("label"), + nb::arg("v_current_min"), + nb::arg("v_current_max"), + nb::arg("v_speed") = 1.0f, + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d", + nb::arg("format_max") = nullptr); // Widgets: Sliders m.def( @@ -946,12 +948,12 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderFloat(label, &v, v_min, v_max, format, power); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("power") = 1.0f); m.def( "SliderFloat2", [](const char* label, @@ -963,12 +965,12 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderFloat2(label, v.data(), v_min, v_max, format, power); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("power") = 1.0f); m.def( "SliderFloat3", [](const char* label, @@ -980,12 +982,12 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderFloat3(label, v.data(), v_min, v_max, format, power); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("power") = 1.0f); m.def( "SliderFloat4", [](const char* label, @@ -997,12 +999,12 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderFloat4(label, v.data(), v_min, v_max, format, power); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("v_min"), - py::arg("v_max"), - py::arg("format") = "%.3f", - py::arg("power") = 1.0f); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("format") = "%.3f", + nb::arg("power") = 1.0f); m.def( "SliderAngle", @@ -1014,11 +1016,11 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderAngle(label, &v_rad, v_degrees_min, v_degrees_max, format); return std::make_tuple(clicked, v_rad); }, - py::arg("label"), - py::arg("v_rad"), - py::arg("v_degrees_min") = -360.0f, - py::arg("v_degrees_max") = +360.0f, - py::arg("format") = "%.0f deg"); + nb::arg("label"), + nb::arg("v_rad"), + nb::arg("v_degrees_min") = -360.0f, + nb::arg("v_degrees_max") = +360.0f, + nb::arg("format") = "%.0f deg"); m.def( "SliderInt", @@ -1027,11 +1029,11 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderInt(label, &v_, v_min, v_max, format); return std::make_tuple(clicked, v_); }, - py::arg("label"), - py::arg("v"), - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d"); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d"); m.def( "SliderInt2", [](const char* label, @@ -1043,11 +1045,11 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderInt2(label, v_.data(), v_min, v_max, format); return std::make_tuple(clicked, v_); }, - py::arg("label"), - py::arg("v"), - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d"); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d"); m.def( "SliderInt3", [](const char* label, @@ -1059,11 +1061,11 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderInt3(label, v_.data(), v_min, v_max, format); return std::make_tuple(clicked, v_); }, - py::arg("label"), - py::arg("v"), - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d"); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d"); m.def( "SliderInt4", [](const char* label, @@ -1075,11 +1077,11 @@ void bind_imgui_methods(py::module& m) { auto clicked = ImGui::SliderInt4(label, v_.data(), v_min, v_max, format); return std::make_tuple(clicked, v_); }, - py::arg("label"), - py::arg("v"), - py::arg("v_min") = 0, - py::arg("v_max") = 0, - py::arg("format") = "%d"); + nb::arg("label"), + nb::arg("v"), + nb::arg("v_min") = 0, + nb::arg("v_max") = 0, + nb::arg("format") = "%d"); // Widgets: Input with Keyboard m.def( @@ -1101,9 +1103,9 @@ void bind_imgui_methods(py::module& m) { &cb_user_data); return std::make_tuple(clicked, buf_); }, - py::arg("label"), - py::arg("buf"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("buf"), + nb::arg("flags") = 0); m.def( "InputTextMultiline", [](const char* label, @@ -1127,10 +1129,10 @@ void bind_imgui_methods(py::module& m) { &cb_user_data); return std::make_tuple(clicked, buf_); }, - py::arg("label"), - py::arg("buf"), - py::arg("size") = std::make_tuple(0.f, 0.f), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("buf"), + nb::arg("size") = std::make_tuple(0.f, 0.f), + nb::arg("flags") = 0); m.def( "InputTextWithHint", [](const char* label, const char* hint, const std::string& buf, ImGuiInputTextFlags flags) { @@ -1151,10 +1153,10 @@ void bind_imgui_methods(py::module& m) { &cb_user_data); return std::make_tuple(clicked, buf_); }, - py::arg("label"), - py::arg("hint"), - py::arg("buf"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("hint"), + nb::arg("buf"), + nb::arg("flags") = 0); m.def( "InputFloat", [](const char* label, @@ -1166,12 +1168,12 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::InputFloat(label, &v, step, step_fast, format, flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("step") = 0.f, - py::arg("step_fast") = 0.f, - py::arg("format") = "%.3f", - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("step") = 0.f, + nb::arg("step_fast") = 0.f, + nb::arg("format") = "%.3f", + nb::arg("flags") = 0); m.def( "InputFloat2", [](const char* label, @@ -1181,10 +1183,10 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::InputFloat2(label, v.data(), format, flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("format") = "%.3f", - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("format") = "%.3f", + nb::arg("flags") = 0); m.def( "InputFloat3", [](const char* label, @@ -1194,10 +1196,10 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::InputFloat3(label, v.data(), format, flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("format") = "%.3f", - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("format") = "%.3f", + nb::arg("flags") = 0); m.def( "InputFloat4", [](const char* label, @@ -1207,30 +1209,30 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::InputFloat4(label, v.data(), format, flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("format") = "%.3f", - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("format") = "%.3f", + nb::arg("flags") = 0); m.def( "InputInt", [](const char* label, int v, float step, float step_fast, ImGuiInputTextFlags flags) { const auto clicked = ImGui::InputInt(label, &v, step, step_fast, flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("step") = 0.f, - py::arg("step_fast") = 0.f, - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("step") = 0.f, + nb::arg("step_fast") = 0.f, + nb::arg("flags") = 0); m.def( "InputInt2", [](const char* label, std::array v, ImGuiInputTextFlags flags) { const auto clicked = ImGui::InputInt2(label, v.data(), flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("flags") = 0); m.def( "InputInt3", [](const char* label, std::array v, ImGuiInputTextFlags flags) { @@ -1238,18 +1240,18 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::InputInt3(label, v.data(), flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("flags") = 0); m.def( "InputInt4", [](const char* label, std::array v, ImGuiInputTextFlags flags) { const auto clicked = ImGui::InputInt4(label, v.data(), flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("flags") = 0); m.def( "InputDouble", [](const char* label, @@ -1261,12 +1263,12 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::InputDouble(label, &v, step, step_fast, format, flags); return std::make_tuple(clicked, v); }, - py::arg("label"), - py::arg("v"), - py::arg("step") = 0.f, - py::arg("step_fast") = 0.f, - py::arg("format") = "%.6f", - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("v"), + nb::arg("step") = 0.f, + nb::arg("step_fast") = 0.f, + nb::arg("format") = "%.6f", + nb::arg("flags") = 0); // Widgets: Color Editor/Picker m.def( @@ -1276,9 +1278,9 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::ColorEdit3(label, col_.data(), flags); return std::make_tuple(clicked, col_); }, - py::arg("label"), - py::arg("def"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("def"), + nb::arg("flags") = 0); m.def( "ColorEdit4", [](const char* label, const std::array& col, ImGuiColorEditFlags flags) { @@ -1286,9 +1288,9 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::ColorEdit4(label, col_.data(), flags); return std::make_tuple(clicked, col_); }, - py::arg("label"), - py::arg("def"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("def"), + nb::arg("flags") = 0); m.def( "ColorPicker3", [](const char* label, const std::array& col, ImGuiColorEditFlags flags) { @@ -1296,9 +1298,9 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::ColorPicker3(label, col_.data(), flags); return std::make_tuple(clicked, col_); }, - py::arg("label"), - py::arg("def"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("def"), + nb::arg("flags") = 0); m.def( "ColorPicker4", [](const char* label, const std::array& col, ImGuiColorEditFlags flags) { @@ -1306,9 +1308,9 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::ColorPicker4(label, col_.data(), flags); return std::make_tuple(clicked, col_); }, - py::arg("label"), - py::arg("def"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("def"), + nb::arg("flags") = 0); m.def( "ColorButton", [](const char* label, const Vec4T& col, ImGuiColorEditFlags flags, const Vec2T& size) { @@ -1316,25 +1318,25 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::ColorButton(label, to_vec4(col), flags, to_vec2(size)); return std::make_tuple(clicked, col_); }, - py::arg("label"), - py::arg("def"), - py::arg("flags") = 0, - py::arg("size") = std::make_tuple(0.f, 0.f)); + nb::arg("label"), + nb::arg("def"), + nb::arg("flags") = 0, + nb::arg("size") = std::make_tuple(0.f, 0.f)); m.def( "SetColorEditOptions", [](ImGuiColorEditFlags flags) { ImGui::SetColorEditOptions(flags); }, - py::arg("flags")); + nb::arg("flags")); // Widgets: Trees m.def( - "TreeNode", [](const char* label) { return ImGui::TreeNode(label); }, py::arg("label")); + "TreeNode", [](const char* label) { return ImGui::TreeNode(label); }, nb::arg("label")); m.def( "TreeNodeEx", [](const char* label, ImGuiTreeNodeFlags flags) { return ImGui::TreeNodeEx(label, flags); }, - py::arg("label"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("flags") = 0); m.def( - "TreePush", [](const char* str_id) { ImGui::TreePush(str_id); }, py::arg("str_id")); + "TreePush", [](const char* str_id) { ImGui::TreePush(str_id); }, nb::arg("str_id")); m.def("TreePop", []() { ImGui::TreePop(); }); m.def("GetTreeNodeToLabelSpacing", []() { return ImGui::GetTreeNodeToLabelSpacing(); }); m.def( @@ -1342,22 +1344,22 @@ void bind_imgui_methods(py::module& m) { [](const char* label, ImGuiTreeNodeFlags flags) { return ImGui::CollapsingHeader(label, flags); }, - py::arg("label"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("flags") = 0); m.def( "CollapsingHeader", [](const char* label, bool open, ImGuiTreeNodeFlags flags) { const auto clicked = ImGui::CollapsingHeader(label, &open, flags); return std::make_tuple(clicked, open); }, - py::arg("label"), - py::arg("open"), - py::arg("flags") = 0); + nb::arg("label"), + nb::arg("open"), + nb::arg("flags") = 0); m.def( "SetNextItemOpen", [](bool is_open, ImGuiCond cond) { ImGui::SetNextItemOpen(is_open, cond); }, - py::arg("is_open"), - py::arg("cond") = 0); + nb::arg("is_open"), + nb::arg("cond") = 0); // Widgets: Selectables m.def( @@ -1366,10 +1368,10 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::Selectable(label, &selected, flags, to_vec2(size)); return std::make_tuple(clicked, selected); }, - py::arg("label"), - py::arg("selected") = false, - py::arg("flags") = 0, - py::arg("size") = std::make_tuple(0.f, 0.f)); + nb::arg("label"), + nb::arg("selected") = false, + nb::arg("flags") = 0, + nb::arg("size") = std::make_tuple(0.f, 0.f)); // Widgets: List Boxes m.def( @@ -1379,8 +1381,8 @@ void bind_imgui_methods(py::module& m) { ) { return ImGui::BeginListBox(label, to_vec2(size)); }, - py::arg("label"), - py::arg("size") = Vec2T(0,0)); + nb::arg("label"), + nb::arg("size") = Vec2T(0,0)); m.def( "EndListBox", []() { @@ -1397,10 +1399,10 @@ void bind_imgui_methods(py::module& m) { ImGui::ListBox(label, ¤t_item, _items.data(), _items.size(), height_in_items); return std::make_tuple(clicked, current_item); }, - py::arg("label"), - py::arg("current_item"), - py::arg("items"), - py::arg("height_in_items") = -1); + nb::arg("label"), + nb::arg("current_item"), + nb::arg("items"), + nb::arg("height_in_items") = -1); // Widgets: Data Plotting m.def( @@ -1416,13 +1418,13 @@ void bind_imgui_methods(py::module& m) { ) { ImGui::PlotLines(label, values.data(), values.size(), values_offset, overlay_text, scale_min, scale_max, to_vec2(graph_size)); }, - py::arg("label"), - py::arg("values"), - py::arg("values_offset") = 0, - py::arg("overlay_text") = nullptr, - py::arg("scale_min") = FLT_MAX, - py::arg("scale_max") = FLT_MAX, - py::arg("graph_size") = std::make_tuple(0.f, 0.f) + nb::arg("label"), + nb::arg("values"), + nb::arg("values_offset") = 0, + nb::arg("overlay_text") = nullptr, + nb::arg("scale_min") = FLT_MAX, + nb::arg("scale_max") = FLT_MAX, + nb::arg("graph_size") = std::make_tuple(0.f, 0.f) ); m.def( "PlotHistogram", @@ -1437,26 +1439,26 @@ void bind_imgui_methods(py::module& m) { ) { ImGui::PlotHistogram(label, values.data(), values.size(), values_offset, overlay_text, scale_min, scale_max, to_vec2(graph_size)); }, - py::arg("label"), - py::arg("values"), - py::arg("values_offset") = 0, - py::arg("overlay_text") = nullptr, - py::arg("scale_min") = FLT_MAX, - py::arg("scale_max") = FLT_MAX, - py::arg("graph_size") = std::make_tuple(0.f, 0.f) + nb::arg("label"), + nb::arg("values"), + nb::arg("values_offset") = 0, + nb::arg("overlay_text") = nullptr, + nb::arg("scale_min") = FLT_MAX, + nb::arg("scale_max") = FLT_MAX, + nb::arg("graph_size") = std::make_tuple(0.f, 0.f) ); // Widgets: Value() Helpers. - m.def("Value", [](const char *prefix, bool b){ ImGui::Value(prefix, b); }, py::arg("prefix"), py::arg("b")); - m.def("Value", [](const char *prefix, int v){ ImGui::Value(prefix, v); }, py::arg("prefix"), py::arg("v")); + m.def("Value", [](const char *prefix, bool b){ ImGui::Value(prefix, b); }, nb::arg("prefix"), nb::arg("b")); + m.def("Value", [](const char *prefix, int v){ ImGui::Value(prefix, v); }, nb::arg("prefix"), nb::arg("v")); m.def( "Value", [](const char *prefix, float v, const char * float_format) { ImGui::Value(prefix, v, float_format); }, - py::arg("prefix"), - py::arg("b"), - py::arg("float_format") = nullptr + nb::arg("prefix"), + nb::arg("b"), + nb::arg("float_format") = nullptr ); // Widgets: Menus @@ -1467,18 +1469,18 @@ void bind_imgui_methods(py::module& m) { m.def( "BeginMenu", [](const char* label, bool enabled) { return ImGui::BeginMenu(label, enabled); }, - py::arg("label"), - py::arg("enabled") = true); + nb::arg("label"), + nb::arg("enabled") = true); m.def("EndMenu", []() { ImGui::EndMenu(); }); m.def( "MenuItem", [](const char* label, const char* shortcut, bool selected, bool enabled) { return ImGui::MenuItem(label, shortcut, selected, enabled); }, - py::arg("label"), - py::arg("shortcut") = nullptr, - py::arg("selected") = false, - py::arg("enabled") = true); + nb::arg("label"), + nb::arg("shortcut") = nullptr, + nb::arg("selected") = false, + nb::arg("enabled") = true); // Tooltips m.def("BeginTooltip", []() { ImGui::BeginTooltip(); }); @@ -1487,55 +1489,55 @@ void bind_imgui_methods(py::module& m) { // Popups, Modals m.def( - "OpenPopup", [](const char* str_id) { ImGui::OpenPopup(str_id); }, py::arg("str_id")); + "OpenPopup", [](const char* str_id) { ImGui::OpenPopup(str_id); }, nb::arg("str_id")); m.def( "BeginPopup", [](const char* str_id, ImGuiWindowFlags flags) { return ImGui::BeginPopup(str_id, flags); }, - py::arg("str_id"), - py::arg("flags") = 0); + nb::arg("str_id"), + nb::arg("flags") = 0); m.def( "BeginPopupContextItem", [](const char* str_id, ImGuiPopupFlags popup_flags) { return ImGui::BeginPopupContextItem(str_id, popup_flags); }, - py::arg("str_id"), - py::arg("popup_flags") = 1); + nb::arg("str_id"), + nb::arg("popup_flags") = 1); m.def( "BeginPopupContextWindow", [](const char* str_id, ImGuiPopupFlags popup_flags) { return ImGui::BeginPopupContextWindow(str_id, popup_flags); }, - py::arg("str_id"), - py::arg("popup_flags") = 1); + nb::arg("str_id"), + nb::arg("popup_flags") = 1); m.def( "BeginPopupContextVoid", [](const char* str_id, ImGuiPopupFlags popup_flags) { return ImGui::BeginPopupContextVoid(str_id, popup_flags); }, - py::arg("str_id"), - py::arg("popup_flags") = 1); + nb::arg("str_id"), + nb::arg("popup_flags") = 1); m.def( "BeginPopupModal", [](const char* str_id, bool open, ImGuiWindowFlags flags) { auto open_ = open; return ImGui::BeginPopupModal(str_id, &open_, flags); }, - py::arg("str_id"), - py::arg("open"), - py::arg("flags") = 0); + nb::arg("str_id"), + nb::arg("open"), + nb::arg("flags") = 0); m.def("EndPopup", []() { ImGui::EndPopup(); }); m.def( "OpenPopupOnItemClick", [](const char* str_id, ImGuiWindowFlags popup_flags) { return ImGui::OpenPopupOnItemClick(str_id, popup_flags); }, - py::arg("str_id"), - py::arg("popup_flags") = 1); + nb::arg("str_id"), + nb::arg("popup_flags") = 1); m.def( "IsPopupOpen", [](const char* str_id, ImGuiPopupFlags popup_flags) { return ImGui::IsPopupOpen(str_id, popup_flags); }, - py::arg("str_id"), - py::arg("flags") = 0); + nb::arg("str_id"), + nb::arg("flags") = 0); m.def("CloseCurrentPopup", []() { ImGui::CloseCurrentPopup(); }); // Tables @@ -1544,11 +1546,11 @@ void bind_imgui_methods(py::module& m) { [](const char*str_id, int columns, ImGuiTableFlags flags, Vec2T size, float innerwidth) -> bool { return ImGui::BeginTable(str_id, columns, flags, to_vec2(size), innerwidth); }, - py::arg("str"), - py::arg("columns"), - py::arg("flags") = 0, - py::arg("size") = std::make_tuple(0.f, 0.f), - py::arg("inner_width") = 0.f + nb::arg("str"), + nb::arg("columns"), + nb::arg("flags") = 0, + nb::arg("size") = std::make_tuple(0.f, 0.f), + nb::arg("inner_width") = 0.f ); m.def( "EndTable", []() { ImGui::EndTable(); } ); m.def( @@ -1556,8 +1558,8 @@ void bind_imgui_methods(py::module& m) { [](ImGuiTableRowFlags flags, float min_row_height) { ImGui::TableNextRow(flags, min_row_height); }, - py::arg("flags") = 0, - py::arg("min_row_height") = 0.f + nb::arg("flags") = 0, + nb::arg("min_row_height") = 0.f ); m.def( "TableNextColumn", @@ -1570,7 +1572,7 @@ void bind_imgui_methods(py::module& m) { [](int column_n) -> bool { return ImGui::TableSetColumnIndex(column_n); }, - py::arg("column_n") + nb::arg("column_n") ); // Table headers and columns @@ -1579,25 +1581,25 @@ void bind_imgui_methods(py::module& m) { [](const char* label, ImGuiTableColumnFlags flags, float init_width_or_height, ImGuiID user_id) { ImGui::TableSetupColumn(label, flags, init_width_or_height, user_id); }, - py::arg("label"), - py::arg("flags") = 0, - py::arg("init_width_or_height") = 0.f, - py::arg("user_id") = 0u + nb::arg("label"), + nb::arg("flags") = 0, + nb::arg("init_width_or_height") = 0.f, + nb::arg("user_id") = 0u ); m.def( "TableSetupScrollFreeze", [](int cols, int rows) { ImGui::TableSetupScrollFreeze(cols, rows); }, - py::arg("cols"), - py::arg("rows") + nb::arg("cols"), + nb::arg("rows") ); m.def( "TableHeader", [](const char* label) { ImGui::TableHeader(label); }, - py::arg("label") + nb::arg("label") ); m.def("TableHeadersRow", []() { ImGui::TableHeadersRow(); }); m.def("TableAngledHeadersRow", []() { ImGui::TableAngledHeadersRow(); }); @@ -1606,21 +1608,21 @@ void bind_imgui_methods(py::module& m) { // warning! this function returns a pointer which is only valid for a short time, within the same frame and before next call to BeginTable() (see imgui docs) // you will get undefined behavior if you try to use it later - m.def("TableGetSortSpecs", []() -> ImGuiTableSortSpecs* { return ImGui::TableGetSortSpecs(); }, py::return_value_policy::reference); + m.def("TableGetSortSpecs", []() -> ImGuiTableSortSpecs* { return ImGui::TableGetSortSpecs(); }, nb::rv_policy::reference); m.def("TableGetColumnCount", []() -> int { return ImGui::TableGetColumnCount(); }); m.def("TableGetColumnIndex", []() -> int { return ImGui::TableGetColumnIndex(); }); m.def("TableGetRowIndex", []() -> int { return ImGui::TableGetRowIndex(); }); m.def( "TableGetColumnName", - [](int column_n) { return py::str(ImGui::TableGetColumnName(column_n)); }, - py::arg("column_n") = -1 + [](int column_n) { return nb::str(ImGui::TableGetColumnName(column_n)); }, + nb::arg("column_n") = -1 ); /* TableGetColumnFlags not included for the same reasons. */ m.def( "TableSetColumnEnabled", [](int column_n, bool enable) { return ImGui::TableSetColumnEnabled(column_n, enable); }, - py::arg("column_n"), - py::arg("v") + nb::arg("column_n"), + nb::arg("v") ); m.def("TableGetHoveredColumn", []() -> int { return ImGui::TableGetHoveredColumn(); }); m.def( @@ -1628,9 +1630,9 @@ void bind_imgui_methods(py::module& m) { [](ImGuiTableBgTarget target, ImU32 color, int column_n) { return ImGui::TableSetBgColor(target, color, column_n); }, - py::arg("target"), - py::arg("color"), - py::arg("column_n") = -1 + nb::arg("target"), + nb::arg("color"), + nb::arg("column_n") = -1 ); // Columns @@ -1639,9 +1641,9 @@ void bind_imgui_methods(py::module& m) { [](int count, const char *id, bool border) { ImGui::Columns(count, id, border); }, - py::arg("count") = 1, - py::arg("id") = nullptr, - py::arg("border") = true + nb::arg("count") = 1, + nb::arg("id") = nullptr, + nb::arg("border") = true ); m.def("NextColumn", []() { ImGui::NextColumn(); }); m.def("GetColumnIndex", []() { return ImGui::GetColumnIndex(); }); @@ -1650,30 +1652,30 @@ void bind_imgui_methods(py::module& m) { [](int column_index) { return ImGui::GetColumnWidth(column_index); }, - py::arg("column_index") = -1 + nb::arg("column_index") = -1 ); m.def( "SetColumnWidth", [](int column_index, float width) { ImGui::SetColumnWidth(column_index, width); }, - py::arg("column_index"), - py::arg("width") + nb::arg("column_index"), + nb::arg("width") ); m.def( "GetColumnOffset", [](int column_index) { return ImGui::GetColumnOffset(column_index); }, - py::arg("column_index") = -1 + nb::arg("column_index") = -1 ); m.def( "SetColumnOffset", [](int column_index, float width) { ImGui::SetColumnOffset(column_index, width); }, - py::arg("column_index"), - py::arg("offset_x") + nb::arg("column_index"), + nb::arg("offset_x") ); m.def("GetColumnsCount", []() { return ImGui::GetColumnsCount(); }); @@ -1683,8 +1685,8 @@ void bind_imgui_methods(py::module& m) { [](const char *str_id, ImGuiTabBarFlags flags) { return ImGui::BeginTabBar(str_id, flags); }, - py::arg("str_id"), - py::arg("flags") = 0 + nb::arg("str_id"), + nb::arg("flags") = 0 ); m.def("EndTabBar", []() { ImGui::EndTabBar(); }); m.def( @@ -1693,9 +1695,9 @@ void bind_imgui_methods(py::module& m) { const auto clicked = ImGui::BeginTabItem(str, &open, flags); return std::make_tuple(clicked, open); }, - py::arg("str"), - py::arg("open"), - py::arg("flags") = 0 + nb::arg("str"), + nb::arg("open"), + nb::arg("flags") = 0 ); m.def("EndTabItem", []() { ImGui::EndTabItem(); }); m.def( @@ -1703,7 +1705,7 @@ void bind_imgui_methods(py::module& m) { [](const char *tab_or_docked_window_label) { ImGui::SetTabItemClosed(tab_or_docked_window_label); }, - py::arg("tab_or_docked_window_label") + nb::arg("tab_or_docked_window_label") ); // Logging/Capture @@ -1712,22 +1714,22 @@ void bind_imgui_methods(py::module& m) { [](int auto_open_depth) { ImGui::LogToTTY(auto_open_depth); }, - py::arg("auto_open_depth") = -1 + nb::arg("auto_open_depth") = -1 ); m.def( "LogToFile", [](int auto_open_depth, const char *filename) { ImGui::LogToFile(auto_open_depth, filename); }, - py::arg("auto_open_depth") = -1, - py::arg("filename") = nullptr + nb::arg("auto_open_depth") = -1, + nb::arg("filename") = nullptr ); m.def( "LogToClipboard", [](int auto_open_depth) { ImGui::LogToClipboard(auto_open_depth); }, - py::arg("auto_open_depth") = -1 + nb::arg("auto_open_depth") = -1 ); m.def("LogFinish", []() { ImGui::LogFinish(); }); m.def("LogButtons", []() { ImGui::LogButtons(); }); @@ -1736,7 +1738,7 @@ void bind_imgui_methods(py::module& m) { m.def("BeginDisabled", [](bool disable) { return ImGui::BeginDisabled(disable); - }, py::arg("disable")); + }, nb::arg("disable")); m.def("EndDisabled", []() { ImGui::EndDisabled(); }); // Clipping @@ -1749,9 +1751,9 @@ void bind_imgui_methods(py::module& m) { ) { ImGui::PushClipRect(to_vec2(clip_rect_min), to_vec2(clip_rect_max), intersect_with_current_clip_rect); }, - py::arg("clip_rect_min"), - py::arg("clip_rect_max"), - py::arg("intersect_with_current_clip_rect") + nb::arg("clip_rect_min"), + nb::arg("clip_rect_max"), + nb::arg("intersect_with_current_clip_rect") ); m.def("PopClipRect", []() { ImGui::PopClipRect(); }); @@ -1760,20 +1762,20 @@ void bind_imgui_methods(py::module& m) { m.def( "SetKeyboardFocusHere", [](int offset) { ImGui::SetKeyboardFocusHere(offset); }, - py::arg("offset") + nb::arg("offset") ); // Item/Widgets Utilities m.def( "IsItemHovered", [](ImGuiHoveredFlags flags) { return ImGui::IsItemHovered(flags); }, - py::arg("flags") = 0); + nb::arg("flags") = 0); m.def("IsItemActive", []() { return ImGui::IsItemActive(); }); m.def("IsItemFocused", []() { return ImGui::IsItemFocused(); }); m.def( "IsItemClicked", [](ImGuiMouseButton mouse_button) { return ImGui::IsItemClicked(mouse_button); }, - py::arg("mouse_button") = 0); + nb::arg("mouse_button") = 0); m.def("IsItemVisible", []() { return ImGui::IsItemVisible(); }); m.def("IsItemEdited", []() { return ImGui::IsItemEdited(); }); m.def("IsItemActivated", []() { return ImGui::IsItemActivated(); }); @@ -1789,8 +1791,8 @@ void bind_imgui_methods(py::module& m) { m.def("SetItemAllowOverlap", []() { ImGui::SetItemAllowOverlap(); }); // Background/Foreground Draw Lists - m.def("GetBackgroundDrawList", &ImGui::GetBackgroundDrawList, py::return_value_policy::reference); - m.def("GetForegroundDrawList", &ImGui::GetForegroundDrawList, py::return_value_policy::reference); + m.def("GetBackgroundDrawList", &ImGui::GetBackgroundDrawList, nb::rv_policy::reference); + m.def("GetForegroundDrawList", &ImGui::GetForegroundDrawList, nb::rv_policy::reference); // Miscellaneous Utilities m.def( @@ -1798,15 +1800,15 @@ void bind_imgui_methods(py::module& m) { [](const Vec2T& size) { return ImGui::IsRectVisible(to_vec2(size)); }, - py::arg("size") + nb::arg("size") ); m.def( "IsRectVisible", [](const Vec2T& rect_min, const Vec2T& rect_max) { return ImGui::IsRectVisible(to_vec2(rect_min), to_vec2(rect_max)); }, - py::arg("rect_min"), - py::arg("rect_max") + nb::arg("rect_min"), + nb::arg("rect_max") ); m.def("GetTime", []() { return ImGui::GetTime(); }); m.def("GetFrameCount", []() { return ImGui::GetFrameCount(); }); @@ -1816,9 +1818,9 @@ void bind_imgui_methods(py::module& m) { [](ImGuiID id, const Vec2T& size, ImGuiWindowFlags flags) { return ImGui::BeginChildFrame(id, to_vec2(size), flags); }, - py::arg("id"), - py::arg("size"), - py::arg("flags") = 0 + nb::arg("id"), + nb::arg("size"), + nb::arg("flags") = 0 ); m.def("EndChildFrame", []() { ImGui::EndChildFrame(); }); @@ -1828,30 +1830,30 @@ void bind_imgui_methods(py::module& m) { [](const char *text, const char *text_end, bool hide_text_after_double_hash, float wrap_width) { return from_vec2(ImGui::CalcTextSize(text, text_end, hide_text_after_double_hash, wrap_width)); }, - py::arg("text"), - py::arg("text_end") = nullptr, - py::arg("hide_text_after_double_hash") = false, - py::arg("wrap_width") = -1.f + nb::arg("text"), + nb::arg("text_end") = nullptr, + nb::arg("hide_text_after_double_hash") = false, + nb::arg("wrap_width") = -1.f ); // Utilities: Mouse - m.def("IsMouseDown", [](ImGuiMouseButton button) { return ImGui::IsMouseDown(button); }, py::arg("button")); + m.def("IsMouseDown", [](ImGuiMouseButton button) { return ImGui::IsMouseDown(button); }, nb::arg("button")); m.def( "IsMouseClicked", [](ImGuiMouseButton button, bool repeat) { return ImGui::IsMouseClicked(button, repeat); }, - py::arg("button"), - py::arg("repeat") = false + nb::arg("button"), + nb::arg("repeat") = false ); - m.def("IsMouseReleased", [](ImGuiMouseButton button) { return ImGui::IsMouseReleased(button); }, py::arg("button")); - m.def("IsMouseDoubleClicked", [](ImGuiMouseButton button) { return ImGui::IsMouseDoubleClicked(button); }, py::arg("button")); + m.def("IsMouseReleased", [](ImGuiMouseButton button) { return ImGui::IsMouseReleased(button); }, nb::arg("button")); + m.def("IsMouseDoubleClicked", [](ImGuiMouseButton button) { return ImGui::IsMouseDoubleClicked(button); }, nb::arg("button")); m.def( "IsMouseHoveringRect", [](const Vec2T& r_min, const Vec2T& r_max, bool clip) { return ImGui::IsMouseHoveringRect(to_vec2(r_min), to_vec2(r_max), clip); }, - py::arg("r_min"), - py::arg("r_max"), - py::arg("clip") = true + nb::arg("r_min"), + nb::arg("r_max"), + nb::arg("clip") = true ); m.def("IsAnyMouseDown", []() { return ImGui::IsAnyMouseDown(); }); m.def("GetMousePos", []() { return from_vec2(ImGui::GetMousePos()); }); @@ -1859,47 +1861,47 @@ void bind_imgui_methods(py::module& m) { m.def( "IsMouseDragging", [](ImGuiMouseButton button, float lock_threshold) { return ImGui::IsMouseDragging(button, lock_threshold); }, - py::arg("button"), - py::arg("lock_threshold") = -1.f + nb::arg("button"), + nb::arg("lock_threshold") = -1.f ); - m.def("ResetMouseDragDelta", [](ImGuiMouseButton button) { ImGui::ResetMouseDragDelta(button); }, py::arg("button")); + m.def("ResetMouseDragDelta", [](ImGuiMouseButton button) { ImGui::ResetMouseDragDelta(button); }, nb::arg("button")); m.def("GetMouseCursor", []() { return ImGui::GetMouseCursor(); }); - m.def("SetMouseCursor", [](ImGuiMouseCursor cursor_type) { ImGui::SetMouseCursor(cursor_type); }, py::arg("cursor_type")); - m.def("SetNextFrameWantCaptureMouse", [](bool want_capture_mouse) { ImGui::SetNextFrameWantCaptureMouse(want_capture_mouse); }, py::arg("want_capture_mouse")); + m.def("SetMouseCursor", [](ImGuiMouseCursor cursor_type) { ImGui::SetMouseCursor(cursor_type); }, nb::arg("cursor_type")); + m.def("SetNextFrameWantCaptureMouse", [](bool want_capture_mouse) { ImGui::SetNextFrameWantCaptureMouse(want_capture_mouse); }, nb::arg("want_capture_mouse")); // Inputs Utilities: Keyboard - m.def("IsKeyDown", [](ImGuiKey user_key_index) { return ImGui::IsKeyDown(user_key_index); }, py::arg("user_key_index")); - m.def("IsKeyPressed", [](ImGuiKey user_key_index, bool repeat) { return ImGui::IsKeyPressed(user_key_index, repeat); }, py::arg("user_key_index"), py::arg("repeat")=true); - m.def("IsKeyReleased", [](ImGuiKey user_key_index) { return ImGui::IsKeyReleased(user_key_index); }, py::arg("user_key_index")); + m.def("IsKeyDown", [](ImGuiKey user_key_index) { return ImGui::IsKeyDown(user_key_index); }, nb::arg("user_key_index")); + m.def("IsKeyPressed", [](ImGuiKey user_key_index, bool repeat) { return ImGui::IsKeyPressed(user_key_index, repeat); }, nb::arg("user_key_index"), nb::arg("repeat")=true); + m.def("IsKeyReleased", [](ImGuiKey user_key_index) { return ImGui::IsKeyReleased(user_key_index); }, nb::arg("user_key_index")); m.def( "GetKeyPressedAmount", [](ImGuiKey key_index, float repeat_delay, float rate) { return ImGui::GetKeyPressedAmount(key_index, repeat_delay, rate); }, - py::arg("key_index"), - py::arg("repeat_delay"), - py::arg("rate") + nb::arg("key_index"), + nb::arg("repeat_delay"), + nb::arg("rate") ); m.def( "SetNextFrameWantCaptureKeyboard", [](bool want_capture_keyboard) { ImGui::SetNextFrameWantCaptureKeyboard(want_capture_keyboard); }, - py::arg("want_capture_keyboard") = true + nb::arg("want_capture_keyboard") = true ); // Clipboard Utilities m.def("GetClipboardText", []() { return ImGui::GetClipboardText(); }); - m.def("SetClipboardText", [](const char *text) { ImGui::SetClipboardText(text); }, py::arg("text")); + m.def("SetClipboardText", [](const char *text) { ImGui::SetClipboardText(text); }, nb::arg("text")); // Settings/.Ini Utilities - m.def("LoadIniSettingsFromDisk", [](const char *ini_filename) { ImGui::LoadIniSettingsFromDisk(ini_filename); }, py::arg("ini_filename")); - m.def("LoadIniSettingsFromMemory", [](const char *ini_data) { ImGui::LoadIniSettingsFromMemory(ini_data); }, py::arg("ini_data")); - m.def("SaveIniSettingsToDisk", [](const char *ini_filename) { ImGui::SaveIniSettingsToDisk(ini_filename); }, py::arg("ini_filename")); + m.def("LoadIniSettingsFromDisk", [](const char *ini_filename) { ImGui::LoadIniSettingsFromDisk(ini_filename); }, nb::arg("ini_filename")); + m.def("LoadIniSettingsFromMemory", [](const char *ini_data) { ImGui::LoadIniSettingsFromMemory(ini_data); }, nb::arg("ini_data")); + m.def("SaveIniSettingsToDisk", [](const char *ini_filename) { ImGui::SaveIniSettingsToDisk(ini_filename); }, nb::arg("ini_filename")); m.def("SaveIniSettingsToMemory", []() { return ImGui::SaveIniSettingsToMemory(); }); // Draw Commands - py::class_(m, "ImDrawList") + nb::class_(m, "ImDrawList") // Clip Rect @@ -1908,9 +1910,9 @@ void bind_imgui_methods(py::module& m) { [](ImDrawList& self, const Vec2T& clip_rect_min, const Vec2T& clip_rect_max, bool intersect_with_current_clip_rect) { self.PushClipRect(to_vec2(clip_rect_min), to_vec2(clip_rect_max), intersect_with_current_clip_rect); }, - py::arg("clip_rect_min"), - py::arg("clip_rect_max"), - py::arg("intersect_with_current_clip_rect") = false + nb::arg("clip_rect_min"), + nb::arg("clip_rect_max"), + nb::arg("intersect_with_current_clip_rect") = false ) .def("PushClipRectFullScreen", &ImDrawList::PushClipRectFullScreen) .def("PopClipRect", &ImDrawList::PopClipRect) @@ -1921,158 +1923,157 @@ void bind_imgui_methods(py::module& m) { .def( "AddLine", - [](py::object& draw_list_obj, const Vec2T& p1, const Vec2T& p2, ImU32 col, float thickness) { - ImDrawList& draw_list = draw_list_obj.cast(); + [](ImDrawList& draw_list, const Vec2T& p1, const Vec2T& p2, ImU32 col, float thickness) { draw_list.AddLine(to_vec2(p1), to_vec2(p2), col, thickness); }, - py::arg("p1"), - py::arg("p2"), - py::arg("col"), - py::arg("thickness") = 1.0f + nb::arg("p1"), + nb::arg("p2"), + nb::arg("col"), + nb::arg("thickness") = 1.0f ) .def( "AddRect", [](ImDrawList& self, const Vec2T& p_min, const Vec2T& p_max, ImU32 col, float rounding, ImDrawFlags flags, float thickness) { self.AddRect(to_vec2(p_min), to_vec2(p_max), col, rounding, flags, thickness); }, - py::arg("p_min"), - py::arg("p_max"), - py::arg("col"), - py::arg("rounding") = 0.0f, - py::arg("flags") = 0, - py::arg("thickness") = 1.0f + nb::arg("p_min"), + nb::arg("p_max"), + nb::arg("col"), + nb::arg("rounding") = 0.0f, + nb::arg("flags") = 0, + nb::arg("thickness") = 1.0f ) .def( "AddRectFilled", [](ImDrawList& self, const Vec2T& p_min, const Vec2T& p_max, ImU32 col, float rounding, ImDrawFlags flags) { self.AddRectFilled(to_vec2(p_min), to_vec2(p_max), col, rounding, flags); }, - py::arg("p_min"), - py::arg("p_max"), - py::arg("col"), - py::arg("rounding") = 0.0f, - py::arg("flags") = 0 + nb::arg("p_min"), + nb::arg("p_max"), + nb::arg("col"), + nb::arg("rounding") = 0.0f, + nb::arg("flags") = 0 ) .def( "AddRectFilledMultiColor", [](ImDrawList& self, const Vec2T& p_min, const Vec2T& p_max, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left) { self.AddRectFilledMultiColor(to_vec2(p_min), to_vec2(p_max), col_upr_left, col_upr_right, col_bot_right, col_bot_left); }, - py::arg("p_min"), - py::arg("p_max"), - py::arg("col_upr_left"), - py::arg("col_upr_right"), - py::arg("col_bot_right"), - py::arg("col_bot_left") + nb::arg("p_min"), + nb::arg("p_max"), + nb::arg("col_upr_left"), + nb::arg("col_upr_right"), + nb::arg("col_bot_right"), + nb::arg("col_bot_left") ) .def( "AddQuad", [](ImDrawList& self, const Vec2T& p1, const Vec2T& p2, const Vec2T& p3, const Vec2T& p4, ImU32 col, float thickness) { self.AddQuad(to_vec2(p1), to_vec2(p2), to_vec2(p3), to_vec2(p4), col, thickness); }, - py::arg("p1"), - py::arg("p2"), - py::arg("p3"), - py::arg("p4"), - py::arg("col"), - py::arg("thickness") = 1.0f + nb::arg("p1"), + nb::arg("p2"), + nb::arg("p3"), + nb::arg("p4"), + nb::arg("col"), + nb::arg("thickness") = 1.0f ) .def( "AddQuadFilled", [](ImDrawList& self, const Vec2T& p1, const Vec2T& p2, const Vec2T& p3, const Vec2T& p4, ImU32 col) { self.AddQuadFilled(to_vec2(p1), to_vec2(p2), to_vec2(p3), to_vec2(p4), col); }, - py::arg("p1"), - py::arg("p2"), - py::arg("p3"), - py::arg("p4"), - py::arg("col") + nb::arg("p1"), + nb::arg("p2"), + nb::arg("p3"), + nb::arg("p4"), + nb::arg("col") ) .def( "AddTriangle", [](ImDrawList& self, const Vec2T& p1, const Vec2T& p2, const Vec2T& p3, ImU32 col, float thickness) { self.AddTriangle(to_vec2(p1), to_vec2(p2), to_vec2(p3), col, thickness); }, - py::arg("p1"), - py::arg("p2"), - py::arg("p3"), - py::arg("col"), - py::arg("thickness") = 1.0f + nb::arg("p1"), + nb::arg("p2"), + nb::arg("p3"), + nb::arg("col"), + nb::arg("thickness") = 1.0f ) .def( "AddTriangleFilled", [](ImDrawList& self, const Vec2T& p1, const Vec2T& p2, const Vec2T& p3, ImU32 col) { self.AddTriangleFilled(to_vec2(p1), to_vec2(p2), to_vec2(p3), col); }, - py::arg("p1"), - py::arg("p2"), - py::arg("p3"), - py::arg("col") + nb::arg("p1"), + nb::arg("p2"), + nb::arg("p3"), + nb::arg("col") ) .def( "AddCircle", [](ImDrawList& self, const Vec2T& center, const float radius, ImU32 col, int num_segments, float thickness) { self.AddCircle(to_vec2(center), radius, col, num_segments, thickness); }, - py::arg("center"), - py::arg("radius"), - py::arg("col"), - py::arg("num_segments") = 0, - py::arg("thickness") = 1.0f + nb::arg("center"), + nb::arg("radius"), + nb::arg("col"), + nb::arg("num_segments") = 0, + nb::arg("thickness") = 1.0f ) .def( "AddCircleFilled", [](ImDrawList& self, const Vec2T& center, const float radius, ImU32 col, int num_segments) { self.AddCircleFilled(to_vec2(center), radius, col, num_segments); }, - py::arg("center"), - py::arg("radius"), - py::arg("col"), - py::arg("num_segments") = 0 + nb::arg("center"), + nb::arg("radius"), + nb::arg("col"), + nb::arg("num_segments") = 0 ) .def( "AddNgon", [](ImDrawList& self, const Vec2T& center, const float radius, ImU32 col, int num_segments, float thickness) { self.AddNgon(to_vec2(center), radius, col, num_segments, thickness); }, - py::arg("center"), - py::arg("radius"), - py::arg("col"), - py::arg("num_segments") = 0, - py::arg("thickness") = 1.0f + nb::arg("center"), + nb::arg("radius"), + nb::arg("col"), + nb::arg("num_segments") = 0, + nb::arg("thickness") = 1.0f ) .def( "AddNgonFilled", [](ImDrawList& self, const Vec2T& center, const float radius, ImU32 col, int num_segments) { self.AddNgonFilled(to_vec2(center), radius, col, num_segments); }, - py::arg("center"), - py::arg("radius"), - py::arg("col"), - py::arg("num_segments") = 0 + nb::arg("center"), + nb::arg("radius"), + nb::arg("col"), + nb::arg("num_segments") = 0 ) .def( "AddText", [](ImDrawList& self, const Vec2T& pos, ImU32 col, const char* text_begin, const char* text_end) { self.AddText(to_vec2(pos), col, text_begin, text_end); }, - py::arg("pos"), - py::arg("col"), - py::arg("text_begin"), - py::arg("text_end") = nullptr + nb::arg("pos"), + nb::arg("col"), + nb::arg("text_begin"), + nb::arg("text_end") = nullptr ) .def( "AddText", [](ImDrawList& self, ImFont* font, float font_size, const Vec2T& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width) { self.AddText(font, font_size, to_vec2(pos), col, text_begin, text_end, wrap_width); }, - py::arg("font"), - py::arg("font_size"), - py::arg("pos"), - py::arg("col"), - py::arg("text_begin"), - py::arg("text_end") = nullptr, - py::arg("wrap_width") = 0.0f + nb::arg("font"), + nb::arg("font_size"), + nb::arg("pos"), + nb::arg("col"), + nb::arg("text_begin"), + nb::arg("text_end") = nullptr, + nb::arg("wrap_width") = 0.0f ) .def( "AddPolyline", @@ -2083,11 +2084,11 @@ void bind_imgui_methods(py::module& m) { } self.AddPolyline(points_vec2.data(), num_points, col, flags, thickness); }, - py::arg("points"), - py::arg("num_points"), - py::arg("col"), - py::arg("flags"), - py::arg("thickness") + nb::arg("points"), + nb::arg("num_points"), + nb::arg("col"), + nb::arg("flags"), + nb::arg("thickness") ) .def( "AddConvexPolyFilled", @@ -2098,34 +2099,34 @@ void bind_imgui_methods(py::module& m) { } self.AddConvexPolyFilled(points_vec2.data(), num_points, col); }, - py::arg("points"), - py::arg("num_points"), - py::arg("col") + nb::arg("points"), + nb::arg("num_points"), + nb::arg("col") ) .def( "AddBezierCubic", [](ImDrawList& self, const Vec2T& p1, const Vec2T& p2, const Vec2T& p3, const Vec2T& p4, ImU32 col, float thickness, int num_segments = 0) { self.AddBezierCubic(to_vec2(p1), to_vec2(p2), to_vec2(p3), to_vec2(p4), col, thickness, num_segments); }, - py::arg("p1"), - py::arg("p2"), - py::arg("p3"), - py::arg("p4"), - py::arg("col"), - py::arg("thickness"), - py::arg("num_segments") = 0 + nb::arg("p1"), + nb::arg("p2"), + nb::arg("p3"), + nb::arg("p4"), + nb::arg("col"), + nb::arg("thickness"), + nb::arg("num_segments") = 0 ) .def( "AddBezierQuadratic", [](ImDrawList& self, const Vec2T& p1, const Vec2T& p2, const Vec2T& p3, ImU32 col, float thickness, int num_segments = 0) { self.AddBezierQuadratic(to_vec2(p1), to_vec2(p2), to_vec2(p3), col, thickness, num_segments); }, - py::arg("p1"), - py::arg("p2"), - py::arg("p3"), - py::arg("col"), - py::arg("thickness"), - py::arg("num_segments") = 0 + nb::arg("p1"), + nb::arg("p2"), + nb::arg("p3"), + nb::arg("col"), + nb::arg("thickness"), + nb::arg("num_segments") = 0 ) // General Polygon @@ -2139,11 +2140,11 @@ void bind_imgui_methods(py::module& m) { } self.AddPolyline(points_vec2.data(), num_points, col, flags, thickness); }, - py::arg("points"), - py::arg("num_points"), - py::arg("col"), - py::arg("flags"), - py::arg("thickness") + nb::arg("points"), + nb::arg("num_points"), + nb::arg("col"), + nb::arg("flags"), + nb::arg("thickness") ) .def( "AddConvexPolyFilled", @@ -2154,9 +2155,9 @@ void bind_imgui_methods(py::module& m) { } self.AddConvexPolyFilled(points_vec2.data(), num_points, col); }, - py::arg("points"), - py::arg("num_points"), - py::arg("col") + nb::arg("points"), + nb::arg("num_points"), + nb::arg("col") ) .def( "AddConcavePolyFilled", @@ -2167,9 +2168,9 @@ void bind_imgui_methods(py::module& m) { } self.AddConcavePolyFilled(points_vec2.data(), num_points, col); }, - py::arg("points"), - py::arg("num_points"), - py::arg("col") + nb::arg("points"), + nb::arg("num_points"), + nb::arg("col") ) ; @@ -2180,12 +2181,11 @@ void bind_imgui_methods(py::module& m) { } // clang-format on -void bind_imgui_enums(py::module& m) { +void bind_imgui_enums(nb::module_& m) { - py::enum_(m, "ImGuiDir"); - py::enum_(m, "ImGuiKey"); - py::enum_(m, "ImGuiMouseSource"); - py::enum_(m, "ImGuiSortDirection"); + nb::enum_(m, "ImGuiDir"); + nb::enum_(m, "ImGuiMouseSource"); + nb::enum_(m, "ImGuiSortDirection"); m.attr("ImGuiWindowFlags_None") = static_cast(ImGuiWindowFlags_None); m.attr("ImGuiWindowFlags_NoTitleBar") = static_cast(ImGuiWindowFlags_NoTitleBar); @@ -2416,155 +2416,306 @@ void bind_imgui_enums(py::module& m) { m.attr("ImGuiSortDirection_Ascending") = static_cast(ImGuiSortDirection_Ascending); m.attr("ImGuiSortDirection_Descending") = static_cast(ImGuiSortDirection_Descending); - m.attr("ImGuiKey_Tab") = static_cast(ImGuiKey_Tab); - m.attr("ImGuiKey_None") = static_cast(ImGuiKey_None); - m.attr("ImGuiKey_Tab") = static_cast(ImGuiKey_Tab); - m.attr("ImGuiKey_LeftArrow") = static_cast(ImGuiKey_LeftArrow); - m.attr("ImGuiKey_RightArrow") = static_cast(ImGuiKey_RightArrow); - m.attr("ImGuiKey_UpArrow") = static_cast(ImGuiKey_UpArrow); - m.attr("ImGuiKey_DownArrow") = static_cast(ImGuiKey_DownArrow); - m.attr("ImGuiKey_PageUp") = static_cast(ImGuiKey_PageUp); - m.attr("ImGuiKey_PageDown") = static_cast(ImGuiKey_PageDown); - m.attr("ImGuiKey_Home") = static_cast(ImGuiKey_Home); - m.attr("ImGuiKey_End") = static_cast(ImGuiKey_End); - m.attr("ImGuiKey_Insert") = static_cast(ImGuiKey_Insert); - m.attr("ImGuiKey_Delete") = static_cast(ImGuiKey_Delete); - m.attr("ImGuiKey_Backspace") = static_cast(ImGuiKey_Backspace); - m.attr("ImGuiKey_Space") = static_cast(ImGuiKey_Space); - m.attr("ImGuiKey_Enter") = static_cast(ImGuiKey_Enter); - m.attr("ImGuiKey_Escape") = static_cast(ImGuiKey_Escape); - m.attr("ImGuiKey_LeftCtrl") = static_cast(ImGuiKey_LeftCtrl); - m.attr("ImGuiKey_LeftShift") = static_cast(ImGuiKey_LeftShift); - m.attr("ImGuiKey_LeftAlt") = static_cast(ImGuiKey_LeftAlt); - m.attr("ImGuiKey_LeftSuper") = static_cast(ImGuiKey_LeftSuper); - m.attr("ImGuiKey_RightCtrl") = static_cast(ImGuiKey_RightCtrl); - m.attr("ImGuiKey_RightShift") = static_cast(ImGuiKey_RightShift); - m.attr("ImGuiKey_RightAlt") = static_cast(ImGuiKey_RightAlt); - m.attr("ImGuiKey_RightSuper") = static_cast(ImGuiKey_RightSuper); - m.attr("ImGuiKey_Menu") = static_cast(ImGuiKey_Menu); - m.attr("ImGuiKey_0") = static_cast(ImGuiKey_0); - m.attr("ImGuiKey_1") = static_cast(ImGuiKey_1); - m.attr("ImGuiKey_2") = static_cast(ImGuiKey_2); - m.attr("ImGuiKey_3") = static_cast(ImGuiKey_3); - m.attr("ImGuiKey_4") = static_cast(ImGuiKey_4); - m.attr("ImGuiKey_5") = static_cast(ImGuiKey_5); - m.attr("ImGuiKey_6") = static_cast(ImGuiKey_6); - m.attr("ImGuiKey_7") = static_cast(ImGuiKey_7); - m.attr("ImGuiKey_8") = static_cast(ImGuiKey_8); - m.attr("ImGuiKey_9") = static_cast(ImGuiKey_9); - m.attr("ImGuiKey_A") = static_cast(ImGuiKey_A); - m.attr("ImGuiKey_B") = static_cast(ImGuiKey_B); - m.attr("ImGuiKey_C") = static_cast(ImGuiKey_C); - m.attr("ImGuiKey_D") = static_cast(ImGuiKey_D); - m.attr("ImGuiKey_E") = static_cast(ImGuiKey_E); - m.attr("ImGuiKey_F") = static_cast(ImGuiKey_F); - m.attr("ImGuiKey_G") = static_cast(ImGuiKey_G); - m.attr("ImGuiKey_H") = static_cast(ImGuiKey_H); - m.attr("ImGuiKey_I") = static_cast(ImGuiKey_I); - m.attr("ImGuiKey_J") = static_cast(ImGuiKey_J); - m.attr("ImGuiKey_K") = static_cast(ImGuiKey_K); - m.attr("ImGuiKey_L") = static_cast(ImGuiKey_L); - m.attr("ImGuiKey_M") = static_cast(ImGuiKey_M); - m.attr("ImGuiKey_N") = static_cast(ImGuiKey_N); - m.attr("ImGuiKey_O") = static_cast(ImGuiKey_O); - m.attr("ImGuiKey_P") = static_cast(ImGuiKey_P); - m.attr("ImGuiKey_Q") = static_cast(ImGuiKey_Q); - m.attr("ImGuiKey_R") = static_cast(ImGuiKey_R); - m.attr("ImGuiKey_S") = static_cast(ImGuiKey_S); - m.attr("ImGuiKey_T") = static_cast(ImGuiKey_T); - m.attr("ImGuiKey_U") = static_cast(ImGuiKey_U); - m.attr("ImGuiKey_V") = static_cast(ImGuiKey_V); - m.attr("ImGuiKey_W") = static_cast(ImGuiKey_W); - m.attr("ImGuiKey_X") = static_cast(ImGuiKey_X); - m.attr("ImGuiKey_Y") = static_cast(ImGuiKey_Y); - m.attr("ImGuiKey_Z") = static_cast(ImGuiKey_Z); - m.attr("ImGuiKey_F1") = static_cast(ImGuiKey_F1); - m.attr("ImGuiKey_F2") = static_cast(ImGuiKey_F2); - m.attr("ImGuiKey_F3") = static_cast(ImGuiKey_F3); - m.attr("ImGuiKey_F4") = static_cast(ImGuiKey_F4); - m.attr("ImGuiKey_F5") = static_cast(ImGuiKey_F5); - m.attr("ImGuiKey_F6") = static_cast(ImGuiKey_F6); - m.attr("ImGuiKey_F7") = static_cast(ImGuiKey_F7); - m.attr("ImGuiKey_F8") = static_cast(ImGuiKey_F8); - m.attr("ImGuiKey_F9") = static_cast(ImGuiKey_F9); - m.attr("ImGuiKey_F10") = static_cast(ImGuiKey_F10); - m.attr("ImGuiKey_F11") = static_cast(ImGuiKey_F11); - m.attr("ImGuiKey_F12") = static_cast(ImGuiKey_F12); - m.attr("ImGuiKey_F13") = static_cast(ImGuiKey_F13); - m.attr("ImGuiKey_F14") = static_cast(ImGuiKey_F14); - m.attr("ImGuiKey_F15") = static_cast(ImGuiKey_F15); - m.attr("ImGuiKey_F16") = static_cast(ImGuiKey_F16); - m.attr("ImGuiKey_F17") = static_cast(ImGuiKey_F17); - m.attr("ImGuiKey_F18") = static_cast(ImGuiKey_F18); - m.attr("ImGuiKey_F19") = static_cast(ImGuiKey_F19); - m.attr("ImGuiKey_F20") = static_cast(ImGuiKey_F20); - m.attr("ImGuiKey_F21") = static_cast(ImGuiKey_F21); - m.attr("ImGuiKey_F22") = static_cast(ImGuiKey_F22); - m.attr("ImGuiKey_F23") = static_cast(ImGuiKey_F23); - m.attr("ImGuiKey_F24") = static_cast(ImGuiKey_F24); - m.attr("ImGuiKey_Apostrophe") = static_cast(ImGuiKey_Apostrophe); - m.attr("ImGuiKey_Comma") = static_cast(ImGuiKey_Comma); - m.attr("ImGuiKey_Minus") = static_cast(ImGuiKey_Minus); - m.attr("ImGuiKey_Period") = static_cast(ImGuiKey_Period); - m.attr("ImGuiKey_Slash") = static_cast(ImGuiKey_Slash); - m.attr("ImGuiKey_Semicolon") = static_cast(ImGuiKey_Semicolon); - m.attr("ImGuiKey_Equal") = static_cast(ImGuiKey_Equal); - m.attr("ImGuiKey_LeftBracket") = static_cast(ImGuiKey_LeftBracket); - m.attr("ImGuiKey_Backslash") = static_cast(ImGuiKey_Backslash); - m.attr("ImGuiKey_RightBracket") = static_cast(ImGuiKey_RightBracket); - m.attr("ImGuiKey_GraveAccent") = static_cast(ImGuiKey_GraveAccent); - m.attr("ImGuiKey_CapsLock") = static_cast(ImGuiKey_CapsLock); - m.attr("ImGuiKey_ScrollLock") = static_cast(ImGuiKey_ScrollLock); - m.attr("ImGuiKey_NumLock") = static_cast(ImGuiKey_NumLock); - m.attr("ImGuiKey_PrintScreen") = static_cast(ImGuiKey_PrintScreen); - m.attr("ImGuiKey_Pause") = static_cast(ImGuiKey_Pause); - m.attr("ImGuiKey_Keypad0") = static_cast(ImGuiKey_Keypad0); - m.attr("ImGuiKey_Keypad1") = static_cast(ImGuiKey_Keypad1); - m.attr("ImGuiKey_Keypad2") = static_cast(ImGuiKey_Keypad2); - m.attr("ImGuiKey_Keypad3") = static_cast(ImGuiKey_Keypad3); - m.attr("ImGuiKey_Keypad4") = static_cast(ImGuiKey_Keypad4); - m.attr("ImGuiKey_Keypad5") = static_cast(ImGuiKey_Keypad5); - m.attr("ImGuiKey_Keypad6") = static_cast(ImGuiKey_Keypad6); - m.attr("ImGuiKey_Keypad7") = static_cast(ImGuiKey_Keypad7); - m.attr("ImGuiKey_Keypad8") = static_cast(ImGuiKey_Keypad8); - m.attr("ImGuiKey_Keypad9") = static_cast(ImGuiKey_Keypad9); - m.attr("ImGuiKey_KeypadDecimal") = static_cast(ImGuiKey_KeypadDecimal); - m.attr("ImGuiKey_KeypadDivide") = static_cast(ImGuiKey_KeypadDivide); - m.attr("ImGuiKey_KeypadMultiply") = static_cast(ImGuiKey_KeypadMultiply); - m.attr("ImGuiKey_KeypadSubtract") = static_cast(ImGuiKey_KeypadSubtract); - m.attr("ImGuiKey_KeypadAdd") = static_cast(ImGuiKey_KeypadAdd); - m.attr("ImGuiKey_KeypadEnter") = static_cast(ImGuiKey_KeypadEnter); - m.attr("ImGuiKey_KeypadEqual") = static_cast(ImGuiKey_KeypadEqual); - m.attr("ImGuiKey_AppBack") = static_cast(ImGuiKey_AppBack); - m.attr("ImGuiKey_AppForward") = static_cast(ImGuiKey_AppForward); - m.attr("ImGuiKey_GamepadStart") = static_cast(ImGuiKey_GamepadStart); - m.attr("ImGuiKey_GamepadBack") = static_cast(ImGuiKey_GamepadBack); - m.attr("ImGuiKey_GamepadFaceUp") = static_cast(ImGuiKey_GamepadFaceUp); - m.attr("ImGuiKey_GamepadFaceDown") = static_cast(ImGuiKey_GamepadFaceDown); - m.attr("ImGuiKey_GamepadFaceLeft") = static_cast(ImGuiKey_GamepadFaceLeft); - m.attr("ImGuiKey_GamepadFaceRight") = static_cast(ImGuiKey_GamepadFaceRight); - m.attr("ImGuiKey_GamepadDpadUp") = static_cast(ImGuiKey_GamepadDpadUp); - m.attr("ImGuiKey_GamepadDpadDown") = static_cast(ImGuiKey_GamepadDpadDown); - m.attr("ImGuiKey_GamepadDpadLeft") = static_cast(ImGuiKey_GamepadDpadLeft); - m.attr("ImGuiKey_GamepadDpadRight") = static_cast(ImGuiKey_GamepadDpadRight); - m.attr("ImGuiKey_GamepadL1") = static_cast(ImGuiKey_GamepadL1); - m.attr("ImGuiKey_GamepadR1") = static_cast(ImGuiKey_GamepadR1); - m.attr("ImGuiKey_GamepadL2") = static_cast(ImGuiKey_GamepadL2); - m.attr("ImGuiKey_GamepadR2") = static_cast(ImGuiKey_GamepadR2); - m.attr("ImGuiKey_GamepadL3") = static_cast(ImGuiKey_GamepadL3); - m.attr("ImGuiKey_GamepadR3") = static_cast(ImGuiKey_GamepadR3); - m.attr("ImGuiKey_GamepadLStickUp") = static_cast(ImGuiKey_GamepadLStickUp); - m.attr("ImGuiKey_GamepadLStickDown") = static_cast(ImGuiKey_GamepadLStickDown); - m.attr("ImGuiKey_GamepadLStickLeft") = static_cast(ImGuiKey_GamepadLStickLeft); - m.attr("ImGuiKey_GamepadLStickRight") = static_cast(ImGuiKey_GamepadLStickRight); - m.attr("ImGuiKey_GamepadRStickUp") = static_cast(ImGuiKey_GamepadRStickUp); - m.attr("ImGuiKey_GamepadRStickDown") = static_cast(ImGuiKey_GamepadRStickDown); - m.attr("ImGuiKey_GamepadRStickLeft") = static_cast(ImGuiKey_GamepadRStickLeft); - m.attr("ImGuiKey_GamepadRStickRight") = static_cast(ImGuiKey_GamepadRStickRight); - m.attr("ImGuiKey_ModCtrl") = static_cast(ImGuiKey_ModCtrl); - m.attr("ImGuiKey_ModShift") = static_cast(ImGuiKey_ModShift); - m.attr("ImGuiKey_ModAlt") = static_cast(ImGuiKey_ModAlt); - m.attr("ImGuiKey_ModSuper") = static_cast(ImGuiKey_ModSuper); + // TODO replace all enum bindings to work like this (although it does force us to repeat ourselves twice) + nb::enum_(m, "ImGuiKey") + .value("ImGuiKey_None", ImGuiKey::ImGuiKey_None) + .value("ImGuiKey_Tab", ImGuiKey::ImGuiKey_Tab) + .value("ImGuiKey_LeftArrow", ImGuiKey::ImGuiKey_LeftArrow) + .value("ImGuiKey_RightArrow", ImGuiKey::ImGuiKey_RightArrow) + .value("ImGuiKey_UpArrow", ImGuiKey::ImGuiKey_UpArrow) + .value("ImGuiKey_DownArrow", ImGuiKey::ImGuiKey_DownArrow) + .value("ImGuiKey_PageUp", ImGuiKey::ImGuiKey_PageUp) + .value("ImGuiKey_PageDown", ImGuiKey::ImGuiKey_PageDown) + .value("ImGuiKey_Home", ImGuiKey::ImGuiKey_Home) + .value("ImGuiKey_End", ImGuiKey::ImGuiKey_End) + .value("ImGuiKey_Insert", ImGuiKey::ImGuiKey_Insert) + .value("ImGuiKey_Delete", ImGuiKey::ImGuiKey_Delete) + .value("ImGuiKey_Backspace", ImGuiKey::ImGuiKey_Backspace) + .value("ImGuiKey_Space", ImGuiKey::ImGuiKey_Space) + .value("ImGuiKey_Enter", ImGuiKey::ImGuiKey_Enter) + .value("ImGuiKey_Escape", ImGuiKey::ImGuiKey_Escape) + .value("ImGuiKey_LeftCtrl", ImGuiKey::ImGuiKey_LeftCtrl) + .value("ImGuiKey_LeftShift", ImGuiKey::ImGuiKey_LeftShift) + .value("ImGuiKey_LeftAlt", ImGuiKey::ImGuiKey_LeftAlt) + .value("ImGuiKey_LeftSuper", ImGuiKey::ImGuiKey_LeftSuper) + .value("ImGuiKey_RightCtrl", ImGuiKey::ImGuiKey_RightCtrl) + .value("ImGuiKey_RightShift", ImGuiKey::ImGuiKey_RightShift) + .value("ImGuiKey_RightAlt", ImGuiKey::ImGuiKey_RightAlt) + .value("ImGuiKey_RightSuper", ImGuiKey::ImGuiKey_RightSuper) + .value("ImGuiKey_Menu", ImGuiKey::ImGuiKey_Menu) + .value("ImGuiKey_0", ImGuiKey::ImGuiKey_0) + .value("ImGuiKey_1", ImGuiKey::ImGuiKey_1) + .value("ImGuiKey_2", ImGuiKey::ImGuiKey_2) + .value("ImGuiKey_3", ImGuiKey::ImGuiKey_3) + .value("ImGuiKey_4", ImGuiKey::ImGuiKey_4) + .value("ImGuiKey_5", ImGuiKey::ImGuiKey_5) + .value("ImGuiKey_6", ImGuiKey::ImGuiKey_6) + .value("ImGuiKey_7", ImGuiKey::ImGuiKey_7) + .value("ImGuiKey_8", ImGuiKey::ImGuiKey_8) + .value("ImGuiKey_9", ImGuiKey::ImGuiKey_9) + .value("ImGuiKey_A", ImGuiKey::ImGuiKey_A) + .value("ImGuiKey_B", ImGuiKey::ImGuiKey_B) + .value("ImGuiKey_C", ImGuiKey::ImGuiKey_C) + .value("ImGuiKey_D", ImGuiKey::ImGuiKey_D) + .value("ImGuiKey_E", ImGuiKey::ImGuiKey_E) + .value("ImGuiKey_F", ImGuiKey::ImGuiKey_F) + .value("ImGuiKey_G", ImGuiKey::ImGuiKey_G) + .value("ImGuiKey_H", ImGuiKey::ImGuiKey_H) + .value("ImGuiKey_I", ImGuiKey::ImGuiKey_I) + .value("ImGuiKey_J", ImGuiKey::ImGuiKey_J) + .value("ImGuiKey_K", ImGuiKey::ImGuiKey_K) + .value("ImGuiKey_L", ImGuiKey::ImGuiKey_L) + .value("ImGuiKey_M", ImGuiKey::ImGuiKey_M) + .value("ImGuiKey_N", ImGuiKey::ImGuiKey_N) + .value("ImGuiKey_O", ImGuiKey::ImGuiKey_O) + .value("ImGuiKey_P", ImGuiKey::ImGuiKey_P) + .value("ImGuiKey_Q", ImGuiKey::ImGuiKey_Q) + .value("ImGuiKey_R", ImGuiKey::ImGuiKey_R) + .value("ImGuiKey_S", ImGuiKey::ImGuiKey_S) + .value("ImGuiKey_T", ImGuiKey::ImGuiKey_T) + .value("ImGuiKey_U", ImGuiKey::ImGuiKey_U) + .value("ImGuiKey_V", ImGuiKey::ImGuiKey_V) + .value("ImGuiKey_W", ImGuiKey::ImGuiKey_W) + .value("ImGuiKey_X", ImGuiKey::ImGuiKey_X) + .value("ImGuiKey_Y", ImGuiKey::ImGuiKey_Y) + .value("ImGuiKey_Z", ImGuiKey::ImGuiKey_Z) + .value("ImGuiKey_F1", ImGuiKey::ImGuiKey_F1) + .value("ImGuiKey_F2", ImGuiKey::ImGuiKey_F2) + .value("ImGuiKey_F3", ImGuiKey::ImGuiKey_F3) + .value("ImGuiKey_F4", ImGuiKey::ImGuiKey_F4) + .value("ImGuiKey_F5", ImGuiKey::ImGuiKey_F5) + .value("ImGuiKey_F6", ImGuiKey::ImGuiKey_F6) + .value("ImGuiKey_F7", ImGuiKey::ImGuiKey_F7) + .value("ImGuiKey_F8", ImGuiKey::ImGuiKey_F8) + .value("ImGuiKey_F9", ImGuiKey::ImGuiKey_F9) + .value("ImGuiKey_F10", ImGuiKey::ImGuiKey_F10) + .value("ImGuiKey_F11", ImGuiKey::ImGuiKey_F11) + .value("ImGuiKey_F12", ImGuiKey::ImGuiKey_F12) + .value("ImGuiKey_F13", ImGuiKey::ImGuiKey_F13) + .value("ImGuiKey_F14", ImGuiKey::ImGuiKey_F14) + .value("ImGuiKey_F15", ImGuiKey::ImGuiKey_F15) + .value("ImGuiKey_F16", ImGuiKey::ImGuiKey_F16) + .value("ImGuiKey_F17", ImGuiKey::ImGuiKey_F17) + .value("ImGuiKey_F18", ImGuiKey::ImGuiKey_F18) + .value("ImGuiKey_F19", ImGuiKey::ImGuiKey_F19) + .value("ImGuiKey_F20", ImGuiKey::ImGuiKey_F20) + .value("ImGuiKey_F21", ImGuiKey::ImGuiKey_F21) + .value("ImGuiKey_F22", ImGuiKey::ImGuiKey_F22) + .value("ImGuiKey_F23", ImGuiKey::ImGuiKey_F23) + .value("ImGuiKey_F24", ImGuiKey::ImGuiKey_F24) + .value("ImGuiKey_Apostrophe", ImGuiKey::ImGuiKey_Apostrophe) + .value("ImGuiKey_Comma", ImGuiKey::ImGuiKey_Comma) + .value("ImGuiKey_Minus", ImGuiKey::ImGuiKey_Minus) + .value("ImGuiKey_Period", ImGuiKey::ImGuiKey_Period) + .value("ImGuiKey_Slash", ImGuiKey::ImGuiKey_Slash) + .value("ImGuiKey_Semicolon", ImGuiKey::ImGuiKey_Semicolon) + .value("ImGuiKey_Equal", ImGuiKey::ImGuiKey_Equal) + .value("ImGuiKey_LeftBracket", ImGuiKey::ImGuiKey_LeftBracket) + .value("ImGuiKey_Backslash", ImGuiKey::ImGuiKey_Backslash) + .value("ImGuiKey_RightBracket", ImGuiKey::ImGuiKey_RightBracket) + .value("ImGuiKey_GraveAccent", ImGuiKey::ImGuiKey_GraveAccent) + .value("ImGuiKey_CapsLock", ImGuiKey::ImGuiKey_CapsLock) + .value("ImGuiKey_ScrollLock", ImGuiKey::ImGuiKey_ScrollLock) + .value("ImGuiKey_NumLock", ImGuiKey::ImGuiKey_NumLock) + .value("ImGuiKey_PrintScreen", ImGuiKey::ImGuiKey_PrintScreen) + .value("ImGuiKey_Pause", ImGuiKey::ImGuiKey_Pause) + .value("ImGuiKey_Keypad0", ImGuiKey::ImGuiKey_Keypad0) + .value("ImGuiKey_Keypad1", ImGuiKey::ImGuiKey_Keypad1) + .value("ImGuiKey_Keypad2", ImGuiKey::ImGuiKey_Keypad2) + .value("ImGuiKey_Keypad3", ImGuiKey::ImGuiKey_Keypad3) + .value("ImGuiKey_Keypad4", ImGuiKey::ImGuiKey_Keypad4) + .value("ImGuiKey_Keypad5", ImGuiKey::ImGuiKey_Keypad5) + .value("ImGuiKey_Keypad6", ImGuiKey::ImGuiKey_Keypad6) + .value("ImGuiKey_Keypad7", ImGuiKey::ImGuiKey_Keypad7) + .value("ImGuiKey_Keypad8", ImGuiKey::ImGuiKey_Keypad8) + .value("ImGuiKey_Keypad9", ImGuiKey::ImGuiKey_Keypad9) + .value("ImGuiKey_KeypadDecimal", ImGuiKey::ImGuiKey_KeypadDecimal) + .value("ImGuiKey_KeypadDivide", ImGuiKey::ImGuiKey_KeypadDivide) + .value("ImGuiKey_KeypadMultiply", ImGuiKey::ImGuiKey_KeypadMultiply) + .value("ImGuiKey_KeypadSubtract", ImGuiKey::ImGuiKey_KeypadSubtract) + .value("ImGuiKey_KeypadAdd", ImGuiKey::ImGuiKey_KeypadAdd) + .value("ImGuiKey_KeypadEnter", ImGuiKey::ImGuiKey_KeypadEnter) + .value("ImGuiKey_KeypadEqual", ImGuiKey::ImGuiKey_KeypadEqual) + .value("ImGuiKey_AppBack", ImGuiKey::ImGuiKey_AppBack) + .value("ImGuiKey_AppForward", ImGuiKey::ImGuiKey_AppForward) + .value("ImGuiKey_GamepadStart", ImGuiKey::ImGuiKey_GamepadStart) + .value("ImGuiKey_GamepadBack", ImGuiKey::ImGuiKey_GamepadBack) + .value("ImGuiKey_GamepadFaceUp", ImGuiKey::ImGuiKey_GamepadFaceUp) + .value("ImGuiKey_GamepadFaceDown", ImGuiKey::ImGuiKey_GamepadFaceDown) + .value("ImGuiKey_GamepadFaceLeft", ImGuiKey::ImGuiKey_GamepadFaceLeft) + .value("ImGuiKey_GamepadFaceRight", ImGuiKey::ImGuiKey_GamepadFaceRight) + .value("ImGuiKey_GamepadDpadUp", ImGuiKey::ImGuiKey_GamepadDpadUp) + .value("ImGuiKey_GamepadDpadDown", ImGuiKey::ImGuiKey_GamepadDpadDown) + .value("ImGuiKey_GamepadDpadLeft", ImGuiKey::ImGuiKey_GamepadDpadLeft) + .value("ImGuiKey_GamepadDpadRight", ImGuiKey::ImGuiKey_GamepadDpadRight) + .value("ImGuiKey_GamepadL1", ImGuiKey::ImGuiKey_GamepadL1) + .value("ImGuiKey_GamepadR1", ImGuiKey::ImGuiKey_GamepadR1) + .value("ImGuiKey_GamepadL2", ImGuiKey::ImGuiKey_GamepadL2) + .value("ImGuiKey_GamepadR2", ImGuiKey::ImGuiKey_GamepadR2) + .value("ImGuiKey_GamepadL3", ImGuiKey::ImGuiKey_GamepadL3) + .value("ImGuiKey_GamepadR3", ImGuiKey::ImGuiKey_GamepadR3) + .value("ImGuiKey_GamepadLStickUp", ImGuiKey::ImGuiKey_GamepadLStickUp) + .value("ImGuiKey_GamepadLStickDown", ImGuiKey::ImGuiKey_GamepadLStickDown) + .value("ImGuiKey_GamepadLStickLeft", ImGuiKey::ImGuiKey_GamepadLStickLeft) + .value("ImGuiKey_GamepadLStickRight", ImGuiKey::ImGuiKey_GamepadLStickRight) + .value("ImGuiKey_GamepadRStickUp", ImGuiKey::ImGuiKey_GamepadRStickUp) + .value("ImGuiKey_GamepadRStickDown", ImGuiKey::ImGuiKey_GamepadRStickDown) + .value("ImGuiKey_GamepadRStickLeft", ImGuiKey::ImGuiKey_GamepadRStickLeft) + .value("ImGuiKey_GamepadRStickRight", ImGuiKey::ImGuiKey_GamepadRStickRight) + .value("ImGuiKey_ModCtrl", ImGuiKey::ImGuiKey_ModCtrl) + .value("ImGuiKey_ModShift", ImGuiKey::ImGuiKey_ModShift) + .value("ImGuiKey_ModAlt", ImGuiKey::ImGuiKey_ModAlt) + .value("ImGuiKey_ModSuper", ImGuiKey::ImGuiKey_ModSuper) + ; + + m.attr("ImGuiKey_None") = ImGuiKey::ImGuiKey_None; + m.attr("ImGuiKey_Tab") = ImGuiKey::ImGuiKey_Tab; + m.attr("ImGuiKey_LeftArrow") = ImGuiKey::ImGuiKey_LeftArrow; + m.attr("ImGuiKey_RightArrow") = ImGuiKey::ImGuiKey_RightArrow; + m.attr("ImGuiKey_UpArrow") = ImGuiKey::ImGuiKey_UpArrow; + m.attr("ImGuiKey_DownArrow") = ImGuiKey::ImGuiKey_DownArrow; + m.attr("ImGuiKey_PageUp") = ImGuiKey::ImGuiKey_PageUp; + m.attr("ImGuiKey_PageDown") = ImGuiKey::ImGuiKey_PageDown; + m.attr("ImGuiKey_Home") = ImGuiKey::ImGuiKey_Home; + m.attr("ImGuiKey_End") = ImGuiKey::ImGuiKey_End; + m.attr("ImGuiKey_Insert") = ImGuiKey::ImGuiKey_Insert; + m.attr("ImGuiKey_Delete") = ImGuiKey::ImGuiKey_Delete; + m.attr("ImGuiKey_Backspace") = ImGuiKey::ImGuiKey_Backspace; + m.attr("ImGuiKey_Space") = ImGuiKey::ImGuiKey_Space; + m.attr("ImGuiKey_Enter") = ImGuiKey::ImGuiKey_Enter; + m.attr("ImGuiKey_Escape") = ImGuiKey::ImGuiKey_Escape; + m.attr("ImGuiKey_LeftCtrl") = ImGuiKey::ImGuiKey_LeftCtrl; + m.attr("ImGuiKey_LeftShift") = ImGuiKey::ImGuiKey_LeftShift; + m.attr("ImGuiKey_LeftAlt") = ImGuiKey::ImGuiKey_LeftAlt; + m.attr("ImGuiKey_LeftSuper") = ImGuiKey::ImGuiKey_LeftSuper; + m.attr("ImGuiKey_RightCtrl") = ImGuiKey::ImGuiKey_RightCtrl; + m.attr("ImGuiKey_RightShift") = ImGuiKey::ImGuiKey_RightShift; + m.attr("ImGuiKey_RightAlt") = ImGuiKey::ImGuiKey_RightAlt; + m.attr("ImGuiKey_RightSuper") = ImGuiKey::ImGuiKey_RightSuper; + m.attr("ImGuiKey_Menu") = ImGuiKey::ImGuiKey_Menu; + m.attr("ImGuiKey_0") = ImGuiKey::ImGuiKey_0; + m.attr("ImGuiKey_1") = ImGuiKey::ImGuiKey_1; + m.attr("ImGuiKey_2") = ImGuiKey::ImGuiKey_2; + m.attr("ImGuiKey_3") = ImGuiKey::ImGuiKey_3; + m.attr("ImGuiKey_4") = ImGuiKey::ImGuiKey_4; + m.attr("ImGuiKey_5") = ImGuiKey::ImGuiKey_5; + m.attr("ImGuiKey_6") = ImGuiKey::ImGuiKey_6; + m.attr("ImGuiKey_7") = ImGuiKey::ImGuiKey_7; + m.attr("ImGuiKey_8") = ImGuiKey::ImGuiKey_8; + m.attr("ImGuiKey_9") = ImGuiKey::ImGuiKey_9; + m.attr("ImGuiKey_A") = ImGuiKey::ImGuiKey_A; + m.attr("ImGuiKey_B") = ImGuiKey::ImGuiKey_B; + m.attr("ImGuiKey_C") = ImGuiKey::ImGuiKey_C; + m.attr("ImGuiKey_D") = ImGuiKey::ImGuiKey_D; + m.attr("ImGuiKey_E") = ImGuiKey::ImGuiKey_E; + m.attr("ImGuiKey_F") = ImGuiKey::ImGuiKey_F; + m.attr("ImGuiKey_G") = ImGuiKey::ImGuiKey_G; + m.attr("ImGuiKey_H") = ImGuiKey::ImGuiKey_H; + m.attr("ImGuiKey_I") = ImGuiKey::ImGuiKey_I; + m.attr("ImGuiKey_J") = ImGuiKey::ImGuiKey_J; + m.attr("ImGuiKey_K") = ImGuiKey::ImGuiKey_K; + m.attr("ImGuiKey_L") = ImGuiKey::ImGuiKey_L; + m.attr("ImGuiKey_M") = ImGuiKey::ImGuiKey_M; + m.attr("ImGuiKey_N") = ImGuiKey::ImGuiKey_N; + m.attr("ImGuiKey_O") = ImGuiKey::ImGuiKey_O; + m.attr("ImGuiKey_P") = ImGuiKey::ImGuiKey_P; + m.attr("ImGuiKey_Q") = ImGuiKey::ImGuiKey_Q; + m.attr("ImGuiKey_R") = ImGuiKey::ImGuiKey_R; + m.attr("ImGuiKey_S") = ImGuiKey::ImGuiKey_S; + m.attr("ImGuiKey_T") = ImGuiKey::ImGuiKey_T; + m.attr("ImGuiKey_U") = ImGuiKey::ImGuiKey_U; + m.attr("ImGuiKey_V") = ImGuiKey::ImGuiKey_V; + m.attr("ImGuiKey_W") = ImGuiKey::ImGuiKey_W; + m.attr("ImGuiKey_X") = ImGuiKey::ImGuiKey_X; + m.attr("ImGuiKey_Y") = ImGuiKey::ImGuiKey_Y; + m.attr("ImGuiKey_Z") = ImGuiKey::ImGuiKey_Z; + m.attr("ImGuiKey_F1") = ImGuiKey::ImGuiKey_F1; + m.attr("ImGuiKey_F2") = ImGuiKey::ImGuiKey_F2; + m.attr("ImGuiKey_F3") = ImGuiKey::ImGuiKey_F3; + m.attr("ImGuiKey_F4") = ImGuiKey::ImGuiKey_F4; + m.attr("ImGuiKey_F5") = ImGuiKey::ImGuiKey_F5; + m.attr("ImGuiKey_F6") = ImGuiKey::ImGuiKey_F6; + m.attr("ImGuiKey_F7") = ImGuiKey::ImGuiKey_F7; + m.attr("ImGuiKey_F8") = ImGuiKey::ImGuiKey_F8; + m.attr("ImGuiKey_F9") = ImGuiKey::ImGuiKey_F9; + m.attr("ImGuiKey_F10") = ImGuiKey::ImGuiKey_F10; + m.attr("ImGuiKey_F11") = ImGuiKey::ImGuiKey_F11; + m.attr("ImGuiKey_F12") = ImGuiKey::ImGuiKey_F12; + m.attr("ImGuiKey_F13") = ImGuiKey::ImGuiKey_F13; + m.attr("ImGuiKey_F14") = ImGuiKey::ImGuiKey_F14; + m.attr("ImGuiKey_F15") = ImGuiKey::ImGuiKey_F15; + m.attr("ImGuiKey_F16") = ImGuiKey::ImGuiKey_F16; + m.attr("ImGuiKey_F17") = ImGuiKey::ImGuiKey_F17; + m.attr("ImGuiKey_F18") = ImGuiKey::ImGuiKey_F18; + m.attr("ImGuiKey_F19") = ImGuiKey::ImGuiKey_F19; + m.attr("ImGuiKey_F20") = ImGuiKey::ImGuiKey_F20; + m.attr("ImGuiKey_F21") = ImGuiKey::ImGuiKey_F21; + m.attr("ImGuiKey_F22") = ImGuiKey::ImGuiKey_F22; + m.attr("ImGuiKey_F23") = ImGuiKey::ImGuiKey_F23; + m.attr("ImGuiKey_F24") = ImGuiKey::ImGuiKey_F24; + m.attr("ImGuiKey_Apostrophe") = ImGuiKey::ImGuiKey_Apostrophe; + m.attr("ImGuiKey_Comma") = ImGuiKey::ImGuiKey_Comma; + m.attr("ImGuiKey_Minus") = ImGuiKey::ImGuiKey_Minus; + m.attr("ImGuiKey_Period") = ImGuiKey::ImGuiKey_Period; + m.attr("ImGuiKey_Slash") = ImGuiKey::ImGuiKey_Slash; + m.attr("ImGuiKey_Semicolon") = ImGuiKey::ImGuiKey_Semicolon; + m.attr("ImGuiKey_Equal") = ImGuiKey::ImGuiKey_Equal; + m.attr("ImGuiKey_LeftBracket") = ImGuiKey::ImGuiKey_LeftBracket; + m.attr("ImGuiKey_Backslash") = ImGuiKey::ImGuiKey_Backslash; + m.attr("ImGuiKey_RightBracket") = ImGuiKey::ImGuiKey_RightBracket; + m.attr("ImGuiKey_GraveAccent") = ImGuiKey::ImGuiKey_GraveAccent; + m.attr("ImGuiKey_CapsLock") = ImGuiKey::ImGuiKey_CapsLock; + m.attr("ImGuiKey_ScrollLock") = ImGuiKey::ImGuiKey_ScrollLock; + m.attr("ImGuiKey_NumLock") = ImGuiKey::ImGuiKey_NumLock; + m.attr("ImGuiKey_PrintScreen") = ImGuiKey::ImGuiKey_PrintScreen; + m.attr("ImGuiKey_Pause") = ImGuiKey::ImGuiKey_Pause; + m.attr("ImGuiKey_Keypad0") = ImGuiKey::ImGuiKey_Keypad0; + m.attr("ImGuiKey_Keypad1") = ImGuiKey::ImGuiKey_Keypad1; + m.attr("ImGuiKey_Keypad2") = ImGuiKey::ImGuiKey_Keypad2; + m.attr("ImGuiKey_Keypad3") = ImGuiKey::ImGuiKey_Keypad3; + m.attr("ImGuiKey_Keypad4") = ImGuiKey::ImGuiKey_Keypad4; + m.attr("ImGuiKey_Keypad5") = ImGuiKey::ImGuiKey_Keypad5; + m.attr("ImGuiKey_Keypad6") = ImGuiKey::ImGuiKey_Keypad6; + m.attr("ImGuiKey_Keypad7") = ImGuiKey::ImGuiKey_Keypad7; + m.attr("ImGuiKey_Keypad8") = ImGuiKey::ImGuiKey_Keypad8; + m.attr("ImGuiKey_Keypad9") = ImGuiKey::ImGuiKey_Keypad9; + m.attr("ImGuiKey_KeypadDecimal") = ImGuiKey::ImGuiKey_KeypadDecimal; + m.attr("ImGuiKey_KeypadDivide") = ImGuiKey::ImGuiKey_KeypadDivide; + m.attr("ImGuiKey_KeypadMultiply") = ImGuiKey::ImGuiKey_KeypadMultiply; + m.attr("ImGuiKey_KeypadSubtract") = ImGuiKey::ImGuiKey_KeypadSubtract; + m.attr("ImGuiKey_KeypadAdd") = ImGuiKey::ImGuiKey_KeypadAdd; + m.attr("ImGuiKey_KeypadEnter") = ImGuiKey::ImGuiKey_KeypadEnter; + m.attr("ImGuiKey_KeypadEqual") = ImGuiKey::ImGuiKey_KeypadEqual; + m.attr("ImGuiKey_AppBack") = ImGuiKey::ImGuiKey_AppBack; + m.attr("ImGuiKey_AppForward") = ImGuiKey::ImGuiKey_AppForward; + m.attr("ImGuiKey_GamepadStart") = ImGuiKey::ImGuiKey_GamepadStart; + m.attr("ImGuiKey_GamepadBack") = ImGuiKey::ImGuiKey_GamepadBack; + m.attr("ImGuiKey_GamepadFaceUp") = ImGuiKey::ImGuiKey_GamepadFaceUp; + m.attr("ImGuiKey_GamepadFaceDown") = ImGuiKey::ImGuiKey_GamepadFaceDown; + m.attr("ImGuiKey_GamepadFaceLeft") = ImGuiKey::ImGuiKey_GamepadFaceLeft; + m.attr("ImGuiKey_GamepadFaceRight") = ImGuiKey::ImGuiKey_GamepadFaceRight; + m.attr("ImGuiKey_GamepadDpadUp") = ImGuiKey::ImGuiKey_GamepadDpadUp; + m.attr("ImGuiKey_GamepadDpadDown") = ImGuiKey::ImGuiKey_GamepadDpadDown; + m.attr("ImGuiKey_GamepadDpadLeft") = ImGuiKey::ImGuiKey_GamepadDpadLeft; + m.attr("ImGuiKey_GamepadDpadRight") = ImGuiKey::ImGuiKey_GamepadDpadRight; + m.attr("ImGuiKey_GamepadL1") = ImGuiKey::ImGuiKey_GamepadL1; + m.attr("ImGuiKey_GamepadR1") = ImGuiKey::ImGuiKey_GamepadR1; + m.attr("ImGuiKey_GamepadL2") = ImGuiKey::ImGuiKey_GamepadL2; + m.attr("ImGuiKey_GamepadR2") = ImGuiKey::ImGuiKey_GamepadR2; + m.attr("ImGuiKey_GamepadL3") = ImGuiKey::ImGuiKey_GamepadL3; + m.attr("ImGuiKey_GamepadR3") = ImGuiKey::ImGuiKey_GamepadR3; + m.attr("ImGuiKey_GamepadLStickUp") = ImGuiKey::ImGuiKey_GamepadLStickUp; + m.attr("ImGuiKey_GamepadLStickDown") = ImGuiKey::ImGuiKey_GamepadLStickDown; + m.attr("ImGuiKey_GamepadLStickLeft") = ImGuiKey::ImGuiKey_GamepadLStickLeft; + m.attr("ImGuiKey_GamepadLStickRight") = ImGuiKey::ImGuiKey_GamepadLStickRight; + m.attr("ImGuiKey_GamepadRStickUp") = ImGuiKey::ImGuiKey_GamepadRStickUp; + m.attr("ImGuiKey_GamepadRStickDown") = ImGuiKey::ImGuiKey_GamepadRStickDown; + m.attr("ImGuiKey_GamepadRStickLeft") = ImGuiKey::ImGuiKey_GamepadRStickLeft; + m.attr("ImGuiKey_GamepadRStickRight") = ImGuiKey::ImGuiKey_GamepadRStickRight; + m.attr("ImGuiKey_ModCtrl") = ImGuiKey::ImGuiKey_ModCtrl; + m.attr("ImGuiKey_ModShift") = ImGuiKey::ImGuiKey_ModShift; + m.attr("ImGuiKey_ModAlt") = ImGuiKey::ImGuiKey_ModAlt; + m.attr("ImGuiKey_ModSuper") = ImGuiKey::ImGuiKey_ModSuper; m.attr("ImGuiMod_None") = static_cast(ImGuiMod_None); m.attr("ImGuiMod_Ctrl") = static_cast(ImGuiMod_Ctrl); diff --git a/src/cpp/imgui_utils.h b/src/cpp/imgui_utils.h index ed9503a..67496ff 100644 --- a/src/cpp/imgui_utils.h +++ b/src/cpp/imgui_utils.h @@ -1,7 +1,8 @@ #pragma once -namespace py = pybind11; namespace ps = polyscope; +namespace nb = nanobind; +using namespace nb::literals; // Type translations between Python and ImGui. Prefer native Python types (tuples, arrays), translating into ImGui // equivalents. diff --git a/src/cpp/implicit_helpers.cpp b/src/cpp/implicit_helpers.cpp index 7d818de..6dac178 100644 --- a/src/cpp/implicit_helpers.cpp +++ b/src/cpp/implicit_helpers.cpp @@ -1,9 +1,3 @@ -#include -#include -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/polyscope.h" @@ -14,31 +8,23 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - -// For overloaded functions, with C++11 compiler only -template -using overload_cast_ = pybind11::detail::overload_cast_impl; - - // clang-format off -void bind_implicit_helpers(py::module& m) { +void bind_implicit_helpers(nb::module_& m) { // == Render implicit surfaces - py::class_(m, "ImplicitRenderOpts") - .def(py::init<>()) - .def_readwrite("cameraParameters", &ps::ImplicitRenderOpts::cameraParameters) - .def_readwrite("dimX", &ps::ImplicitRenderOpts::dimX) - .def_readwrite("dimY", &ps::ImplicitRenderOpts::dimY) - .def_readwrite("subsampleFactor", &ps::ImplicitRenderOpts::subsampleFactor) + nb::class_(m, "ImplicitRenderOpts") + .def(nb::init<>()) + .def_rw("cameraParameters", &ps::ImplicitRenderOpts::cameraParameters) + .def_rw("dimX", &ps::ImplicitRenderOpts::dimX) + .def_rw("dimY", &ps::ImplicitRenderOpts::dimY) + .def_rw("subsampleFactor", &ps::ImplicitRenderOpts::subsampleFactor) .def("set_missDist", [](ps::ImplicitRenderOpts& o, float val, bool isRelative) { o.missDist.set(val, isRelative); }) .def("set_hitDist", [](ps::ImplicitRenderOpts& o, float val, bool isRelative) { o.hitDist.set(val, isRelative); }) - .def_readwrite("stepFactor", &ps::ImplicitRenderOpts::stepFactor) - .def_readwrite("normalSampleEps", &ps::ImplicitRenderOpts::normalSampleEps) + .def_rw("stepFactor", &ps::ImplicitRenderOpts::stepFactor) + .def_rw("normalSampleEps", &ps::ImplicitRenderOpts::normalSampleEps) .def("set_stepSize", [](ps::ImplicitRenderOpts& o, float val, bool isRelative) { o.stepSize.set(val, isRelative); }) - .def_readwrite("nMaxSteps", &ps::ImplicitRenderOpts::nMaxSteps) + .def_rw("nMaxSteps", &ps::ImplicitRenderOpts::nMaxSteps) ; @@ -46,7 +32,6 @@ void bind_implicit_helpers(py::module& m) { m.def("render_implicit_surface_batch", []( - std::string name, const std::function)>& func, ps::ImplicitRenderMode mode, ps::ImplicitRenderOpts opts, ps::CameraView* cameraView @@ -65,7 +50,13 @@ void bind_implicit_helpers(py::module& m) { } else { return ps::renderImplicitSurfaceBatch(cameraView, name, wrapped_func, mode, opts); } - }, py::return_value_policy::reference); + }, + nb::arg("name"), + nb::arg("func"), + nb::arg("mode"), + nb::arg("opts"), + nb::arg("cameraView") = nb::none(), + nb::rv_policy::reference); m.def("render_implicit_surface_color_batch", []( @@ -93,7 +84,14 @@ void bind_implicit_helpers(py::module& m) { } else { return ps::renderImplicitSurfaceColorBatch(cameraView, name, wrapped_func, wrapped_func_color, mode, opts); } - }, py::return_value_policy::reference); + }, + nb::arg("name"), + nb::arg("func"), + nb::arg("func_color"), + nb::arg("mode"), + nb::arg("opts"), + nb::arg("cameraView") = nb::none(), + nb::rv_policy::reference); m.def("render_implicit_surface_scalar_batch", []( @@ -121,7 +119,14 @@ void bind_implicit_helpers(py::module& m) { } else { return ps::renderImplicitSurfaceScalarBatch(cameraView, name, wrapped_func, wrapped_func_scalar, mode, opts); } - }, py::return_value_policy::reference); + }, + nb::arg("name"), + nb::arg("func"), + nb::arg("func_scalar"), + nb::arg("mode"), + nb::arg("opts"), + nb::arg("cameraView") = nb::none(), + nb::rv_policy::reference); m.def("render_implicit_surface_raw_color_batch", []( std::string name, @@ -148,7 +153,14 @@ void bind_implicit_helpers(py::module& m) { } else { return ps::renderImplicitSurfaceRawColorBatch(cameraView, name, wrapped_func, wrapped_func_color, mode, opts); } - }, py::return_value_policy::reference); + }, + nb::arg("name"), + nb::arg("func"), + nb::arg("func_color"), + nb::arg("mode"), + nb::arg("opts"), + nb::arg("cameraView") = nb::none(), + nb::rv_policy::reference); } diff --git a/src/cpp/implot.cpp b/src/cpp/implot.cpp index 363f852..bb66671 100644 --- a/src/cpp/implot.cpp +++ b/src/cpp/implot.cpp @@ -1,23 +1,16 @@ #include "imgui.h" #include "implot.h" -#include -#include -#include -#include - #include "Eigen/Dense" #include "utils.h" #include "imgui_utils.h" -namespace py = pybind11; - -void bind_implot_structs(py::module& m); -void bind_implot_methods(py::module& m); -void bind_implot_enums(py::module& m); +void bind_implot_structs(nb::module_& m); +void bind_implot_methods(nb::module_& m); +void bind_implot_enums(nb::module_& m); -void bind_implot(py::module& m) { +void bind_implot(nb::module_& m) { auto implot_module = m.def_submodule("implot", "ImPlot bindings"); bind_implot_structs(implot_module); @@ -27,13 +20,13 @@ void bind_implot(py::module& m) { // clang-format off -void bind_implot_structs(py::module& m) { +void bind_implot_structs(nb::module_& m) { } -void bind_implot_methods(py::module& m) { +void bind_implot_methods(nb::module_& m) { //----------------------------------------------------------------------------- // [SECTION] Begin/End Plot @@ -44,9 +37,9 @@ void bind_implot_methods(py::module& m) { [](const char* title_id, const Vec2T& size, ImPlotFlags flags) { return ImPlot::BeginPlot(title_id, to_vec2(size), flags); }, - py::arg("title_id"), - py::arg("size") = std::make_tuple(-1.f, 0.f), - py::arg("flags") = 0 + nb::arg("title_id"), + nb::arg("size") = std::make_tuple(-1.f, 0.f), + nb::arg("flags") = 0 ); m.def("EndPlot", []() { ImPlot::EndPlot(); }); @@ -68,13 +61,13 @@ void bind_implot_methods(py::module& m) { return ImPlot::BeginSubplots(title_id, rows, cols, to_vec2(size), flags, row_ratios_ptr, col_ratios_ptr); }, - py::arg("title_id"), - py::arg("rows"), - py::arg("cols"), - py::arg("size") = std::make_tuple(-1.f, 0.f), - py::arg("flags") = 0, - py::arg("row_ratios") = std::vector(), - py::arg("col_ratios") = std::vector() + nb::arg("title_id"), + nb::arg("rows"), + nb::arg("cols"), + nb::arg("size") = std::make_tuple(-1.f, 0.f), + nb::arg("flags") = 0, + nb::arg("row_ratios") = std::vector(), + nb::arg("col_ratios") = std::vector() ); m.def("EndSubplots", []() { ImPlot::EndSubplots(); }); @@ -89,9 +82,9 @@ void bind_implot_methods(py::module& m) { [](ImAxis axis, const char* label, ImPlotAxisFlags flags) { ImPlot::SetupAxis(axis, label, flags); }, - py::arg("axis"), - py::arg("label") = "", - py::arg("flags") = 0 + nb::arg("axis"), + nb::arg("label") = "", + nb::arg("flags") = 0 ); m.def( @@ -99,10 +92,10 @@ void bind_implot_methods(py::module& m) { [](ImAxis axis, double v_min, double v_max, ImPlotCond cond) { ImPlot::SetupAxisLimits(axis, v_min, v_max, cond); }, - py::arg("axis"), - py::arg("vmin"), - py::arg("vmax"), - py::arg("cond") = (int)ImPlotCond_Once + nb::arg("axis"), + nb::arg("vmin"), + nb::arg("vmax"), + nb::arg("cond") = (int)ImPlotCond_Once ); m.def( @@ -110,8 +103,8 @@ void bind_implot_methods(py::module& m) { [](ImAxis axis, const char* fmt) { ImPlot::SetupAxisFormat(axis, fmt); }, - py::arg("axis"), - py::arg("fmt") + nb::arg("axis"), + nb::arg("fmt") ); m.def( @@ -121,10 +114,10 @@ void bind_implot_methods(py::module& m) { const auto _labels = convert_string_items(labels); ImPlot::SetupAxisTicks(axis, values.data(), values.size(), labels.size() == 0 ? nullptr : _labels.data(), keep_default); }, - py::arg("axis"), - py::arg("values"), - py::arg("labels") = std::vector(), - py::arg("keep_default") = false + nb::arg("axis"), + nb::arg("values"), + nb::arg("labels") = std::vector(), + nb::arg("keep_default") = false ); m.def( @@ -134,12 +127,12 @@ void bind_implot_methods(py::module& m) { const auto _labels = convert_string_items(labels); ImPlot::SetupAxisTicks(axis, v_min, v_max, n_ticks, labels.size() == 0 ? nullptr : _labels.data(), keep_default); }, - py::arg("axis"), - py::arg("v_min"), - py::arg("v_max"), - py::arg("n_ticks"), - py::arg("labels") = std::vector(), - py::arg("keep_default") = false + nb::arg("axis"), + nb::arg("v_min"), + nb::arg("v_max"), + nb::arg("n_ticks"), + nb::arg("labels") = std::vector(), + nb::arg("keep_default") = false ); m.def( @@ -147,8 +140,8 @@ void bind_implot_methods(py::module& m) { [](ImAxis axis, ImPlotScale scale) { ImPlot::SetupAxisScale(axis, scale); }, - py::arg("axis"), - py::arg("scale") + nb::arg("axis"), + nb::arg("scale") ); m.def( @@ -156,9 +149,9 @@ void bind_implot_methods(py::module& m) { [](ImAxis axis, double v_min, double v_max) { ImPlot::SetupAxisLimitsConstraints(axis, v_min, v_max); }, - py::arg("axis"), - py::arg("v_min"), - py::arg("v_max") + nb::arg("axis"), + nb::arg("v_min"), + nb::arg("v_max") ); m.def( @@ -166,9 +159,9 @@ void bind_implot_methods(py::module& m) { [](ImAxis axis, double z_min, double z_max) { ImPlot::SetupAxisZoomConstraints(axis, z_min, z_max); }, - py::arg("axis"), - py::arg("z_min"), - py::arg("z_max") + nb::arg("axis"), + nb::arg("z_min"), + nb::arg("z_max") ); m.def( @@ -176,10 +169,10 @@ void bind_implot_methods(py::module& m) { [](const char* x_label, const char* y_label, ImPlotAxisFlags x_flags, ImPlotAxisFlags y_flags) { ImPlot::SetupAxes(x_label, y_label, x_flags, y_flags); }, - py::arg("x_label"), - py::arg("y_label"), - py::arg("x_flags") = 0, - py::arg("y_flags") = 0 + nb::arg("x_label"), + nb::arg("y_label"), + nb::arg("x_flags") = 0, + nb::arg("y_flags") = 0 ); m.def( @@ -187,11 +180,11 @@ void bind_implot_methods(py::module& m) { [](double x_min, double x_max, double y_min, double y_max, ImPlotCond cond) { ImPlot::SetupAxesLimits(x_min, x_max, y_min, y_max, cond); }, - py::arg("x_min"), - py::arg("x_max"), - py::arg("y_min"), - py::arg("y_max"), - py::arg("cond") = (int)ImPlotCond_Once + nb::arg("x_min"), + nb::arg("x_max"), + nb::arg("y_min"), + nb::arg("y_max"), + nb::arg("cond") = (int)ImPlotCond_Once ); m.def( @@ -199,8 +192,8 @@ void bind_implot_methods(py::module& m) { [](ImPlotLocation location, ImPlotLegendFlags flags) { ImPlot::SetupLegend(location, flags); }, - py::arg("location"), - py::arg("flags") = 0 + nb::arg("location"), + nb::arg("flags") = 0 ); m.def( @@ -208,8 +201,8 @@ void bind_implot_methods(py::module& m) { [](ImPlotLocation location, ImPlotMouseTextFlags flags) { ImPlot::SetupMouseText(location, flags); }, - py::arg("location"), - py::arg("flags") = 0 + nb::arg("location"), + nb::arg("flags") = 0 ); @@ -232,11 +225,11 @@ void bind_implot_methods(py::module& m) { [](const char* label_id, const Eigen::VectorXd& values, double xscale, double xstart, ImPlotLineFlags flags) { ImPlot::PlotLine(label_id, values.data(), values.size(), xscale, xstart, flags); }, - py::arg("label_id"), - py::arg("values"), - py::arg("xscale")=1., - py::arg("xstart")=0., - py::arg("flags")=0 + nb::arg("label_id"), + nb::arg("values"), + nb::arg("xscale")=1., + nb::arg("xstart")=0., + nb::arg("flags")=0 ); m.def( @@ -245,10 +238,10 @@ void bind_implot_methods(py::module& m) { if(xs.size() != ys.size()) throw std::runtime_error("invalid input sizes"); ImPlot::PlotLine(label_id, xs.data(), ys.data(), xs.size(), flags); }, - py::arg("label_id"), - py::arg("xs"), - py::arg("ys"), - py::arg("flags") = 0 + nb::arg("label_id"), + nb::arg("xs"), + nb::arg("ys"), + nb::arg("flags") = 0 ); // PlotScatter @@ -258,11 +251,11 @@ void bind_implot_methods(py::module& m) { [](const char* label_id, const Eigen::VectorXd& values, double xscale, double xstart, ImPlotScatterFlags flags) { ImPlot::PlotScatter(label_id, values.data(), values.size(), xscale, xstart, flags); }, - py::arg("label_id"), - py::arg("values"), - py::arg("xscale")=1., - py::arg("xstart")=0., - py::arg("flags")=0 + nb::arg("label_id"), + nb::arg("values"), + nb::arg("xscale")=1., + nb::arg("xstart")=0., + nb::arg("flags")=0 ); m.def( @@ -271,10 +264,10 @@ void bind_implot_methods(py::module& m) { if(xs.size() != ys.size()) throw std::runtime_error("invalid input sizes"); ImPlot::PlotScatter(label_id, xs.data(), ys.data(), xs.size(), flags); }, - py::arg("label_id"), - py::arg("xs"), - py::arg("ys"), - py::arg("flags") = 0 + nb::arg("label_id"), + nb::arg("xs"), + nb::arg("ys"), + nb::arg("flags") = 0 ); // PlotStairs @@ -284,11 +277,11 @@ void bind_implot_methods(py::module& m) { [](const char* label_id, const Eigen::VectorXd& values, double xscale, double xstart, ImPlotStairsFlags flags) { ImPlot::PlotStairs(label_id, values.data(), values.size(), xscale, xstart, flags); }, - py::arg("label_id"), - py::arg("values"), - py::arg("xscale")=1., - py::arg("xstart")=0., - py::arg("flags")=0 + nb::arg("label_id"), + nb::arg("values"), + nb::arg("xscale")=1., + nb::arg("xstart")=0., + nb::arg("flags")=0 ); m.def( @@ -297,10 +290,10 @@ void bind_implot_methods(py::module& m) { if(xs.size() != ys.size()) throw std::runtime_error("invalid input sizes"); ImPlot::PlotStairs(label_id, xs.data(), ys.data(), xs.size(), flags); }, - py::arg("label_id"), - py::arg("xs"), - py::arg("ys"), - py::arg("flags") = 0 + nb::arg("label_id"), + nb::arg("xs"), + nb::arg("ys"), + nb::arg("flags") = 0 ); // PlotShaded TODO @@ -310,12 +303,12 @@ void bind_implot_methods(py::module& m) { [](const char* label_id, const Eigen::VectorXd& values, double yref, double xscale, double xstart, ImPlotShadedFlags flags) { ImPlot::PlotShaded(label_id, values.data(), values.size(), yref, xscale, xstart, flags); }, - py::arg("label_id"), - py::arg("values"), - py::arg("yref")=0., - py::arg("xscale")=1., - py::arg("xstart")=0., - py::arg("flags")=0 + nb::arg("label_id"), + nb::arg("values"), + nb::arg("yref")=0., + nb::arg("xscale")=1., + nb::arg("xstart")=0., + nb::arg("flags")=0 ); m.def( @@ -324,11 +317,11 @@ void bind_implot_methods(py::module& m) { if(xs.size() != ys.size()) throw std::runtime_error("invalid input sizes"); ImPlot::PlotShaded(label_id, xs.data(), ys.data(), xs.size(), yref, flags); }, - py::arg("label_id"), - py::arg("xs"), - py::arg("ys"), - py::arg("yref")=0., - py::arg("flags") = 0 + nb::arg("label_id"), + nb::arg("xs"), + nb::arg("ys"), + nb::arg("yref")=0., + nb::arg("flags") = 0 ); m.def( @@ -338,11 +331,11 @@ void bind_implot_methods(py::module& m) { if(xs.size() != ys2.size()) throw std::runtime_error("invalid input sizes"); ImPlot::PlotShaded(label_id, xs.data(), ys1.data(), ys2.data(), xs.size(), flags); }, - py::arg("label_id"), - py::arg("xs"), - py::arg("ys1"), - py::arg("ys2"), - py::arg("flags") = 0 + nb::arg("label_id"), + nb::arg("xs"), + nb::arg("ys1"), + nb::arg("ys2"), + nb::arg("flags") = 0 ); // PlotBars TODO @@ -360,9 +353,9 @@ void bind_implot_methods(py::module& m) { [](const char* label_id, const Eigen::VectorXd& values, ImPlotInfLinesFlags flags) { ImPlot::PlotInfLines(label_id, values.data(), values.size(), flags); }, - py::arg("label_id"), - py::arg("values"), - py::arg("flags")=0 + nb::arg("label_id"), + nb::arg("values"), + nb::arg("flags")=0 ); // PlotPieChart @@ -373,14 +366,14 @@ void bind_implot_methods(py::module& m) { const auto _label_ids = convert_string_items(label_ids); ImPlot::PlotPieChart(_label_ids.data(), values.data(), values.size(), x, y, radius, label_fmt, angle0, flags); }, - py::arg("label_ids"), - py::arg("values"), - py::arg("x"), - py::arg("y"), - py::arg("radius"), - py::arg("label_fmt") = "%.1f", - py::arg("angle0") = 90, - py::arg("flags") = 0 + nb::arg("label_ids"), + nb::arg("values"), + nb::arg("x"), + nb::arg("y"), + nb::arg("radius"), + nb::arg("label_fmt") = "%.1f", + nb::arg("angle0") = 90, + nb::arg("flags") = 0 ); @@ -394,12 +387,12 @@ void bind_implot_methods(py::module& m) { ImPlotRange imrange(std::get<0>(range), std::get<1>(range)); ImPlot::PlotHistogram(label_id, values.data(), values.size(), bins, bar_scale, imrange, flags); }, - py::arg("label_id"), - py::arg("values"), - py::arg("bins") = (int)ImPlotBin_Sturges, - py::arg("bar_scale") = 1.0, - py::arg("range") = std::make_tuple(0.f, 0.f), - py::arg("flags") = 0 + nb::arg("label_id"), + nb::arg("values"), + nb::arg("bins") = (int)ImPlotBin_Sturges, + nb::arg("bar_scale") = 1.0, + nb::arg("range") = std::make_tuple(0.f, 0.f), + nb::arg("flags") = 0 ); // PlotHistogram2D TODO @@ -442,7 +435,7 @@ void bind_implot_methods(py::module& m) { //----------------------------------------------------------------------------- } -void bind_implot_enums(py::module& m) { +void bind_implot_enums(nb::module_& m) { // ImAxis m.attr("ImAxis_X1") = static_cast(ImAxis_X1); diff --git a/src/cpp/managed_buffer.cpp b/src/cpp/managed_buffer.cpp index f1aceeb..e356f73 100644 --- a/src/cpp/managed_buffer.cpp +++ b/src/cpp/managed_buffer.cpp @@ -1,8 +1,3 @@ -#include -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/polyscope.h" @@ -12,13 +7,10 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - template -py::class_> bind_managed_buffer_T(py::module& m, ps::ManagedBufferType t) { +nb::class_> bind_managed_buffer_T(nb::module_& m, ps::ManagedBufferType t) { - return py::class_>(m, ("ManagedBuffer_" + ps::typeName(t)).c_str()) + return nb::class_>(m, ("ManagedBuffer_" + ps::typeName(t)).c_str()) .def("size", &ps::render::ManagedBuffer::size) .def("get_texture_size", &ps::render::ManagedBuffer::getTextureSize) .def("has_data", &ps::render::ManagedBuffer::hasData) @@ -28,9 +20,9 @@ py::class_> bind_managed_buffer_T(py::module& m, ps [](ps::render::ManagedBuffer& s) { return s.getGenericWeakHandle(); } /* intentionally let Python manage ownership */) - .def("get_value", overload_cast_()(&ps::render::ManagedBuffer::getValue)) - .def("get_value", overload_cast_()(&ps::render::ManagedBuffer::getValue)) - .def("get_value", overload_cast_()(&ps::render::ManagedBuffer::getValue)) + .def("get_value", nb::overload_cast(&ps::render::ManagedBuffer::getValue)) + .def("get_value", nb::overload_cast(&ps::render::ManagedBuffer::getValue)) + .def("get_value", nb::overload_cast(&ps::render::ManagedBuffer::getValue)) .def("mark_host_buffer_updated", &ps::render::ManagedBuffer::markHostBufferUpdated) .def("get_device_buffer_size_in_bytes", [](ps::render::ManagedBuffer& s) { @@ -64,7 +56,7 @@ py::class_> bind_managed_buffer_T(py::module& m, ps } // clang-format off -void bind_managed_buffer(py::module& m) { +void bind_managed_buffer(nb::module_& m) { // explicit template instantiations diff --git a/src/cpp/point_cloud.cpp b/src/cpp/point_cloud.cpp index 8dc6a59..c4818de 100644 --- a/src/cpp/point_cloud.cpp +++ b/src/cpp/point_cloud.cpp @@ -1,7 +1,3 @@ -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/point_cloud.h" @@ -9,21 +5,13 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - -// For overloaded functions, with C++11 compiler only -template -using overload_cast_ = pybind11::detail::overload_cast_impl; - - // clang-format off -void bind_point_cloud(py::module& m) { +void bind_point_cloud(nb::module_& m) { // == Helper classes - py::class_(m, "PointCloudPickResult") - .def(py::init<>()) - .def_readonly("index", &ps::PointCloudPickResult::index) + nb::class_(m, "PointCloudPickResult") + .def(nb::init<>()) + .def_ro("index", &ps::PointCloudPickResult::index) ; // Scalar quantities @@ -36,7 +24,7 @@ void bind_point_cloud(py::module& m) { bindVectorQuantity(m, "PointCloudVectorQuantity"); // Parameterization quantities - py::class_(m, "PointCloudParameterizationQuantity") + nb::class_(m, "PointCloudParameterizationQuantity") .def("set_enabled", &ps::PointCloudParameterizationQuantity::setEnabled, "Set enabled") .def("set_style", &ps::PointCloudParameterizationQuantity::setStyle, "Set style") .def("set_grid_colors", &ps::PointCloudParameterizationQuantity::setGridColors, "Set grid colors") @@ -68,36 +56,36 @@ void bind_point_cloud(py::module& m) { // variable radius .def("set_point_radius_quantity", - overload_cast_()(&ps::PointCloud::setPointRadiusQuantity), - "Use a scalar to set radius by name", py::arg("quantity_name"), py::arg("autoscale")=true) + nb::overload_cast(&ps::PointCloud::setPointRadiusQuantity), + "Use a scalar to set radius by name", nb::arg("quantity_name"), nb::arg("autoscale")=true) .def("clear_point_radius_quantity", &ps::PointCloud::clearPointRadiusQuantity, "Clear any quantity setting the radius") // scalar transparency .def("set_transparency_quantity", - overload_cast_()(&ps::PointCloud::setTransparencyQuantity), py::arg("quantity_name")) + nb::overload_cast(&ps::PointCloud::setTransparencyQuantity), nb::arg("quantity_name")) .def("clear_transparency_quantity", &ps::PointCloud::clearTransparencyQuantity) // quantities .def("add_color_quantity", &ps::PointCloud::addColorQuantity, "Add a color function at points", - py::arg("name"), py::arg("values"), py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::rv_policy::reference) .def("add_scalar_quantity", &ps::PointCloud::addScalarQuantity, "Add a scalar function at points", - py::arg("name"), py::arg("values"), py::arg("data_type")=ps::DataType::STANDARD, py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("data_type")=ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_vector_quantity", &ps::PointCloud::addVectorQuantity, "Add a vector function at points", - py::arg("name"), py::arg("values"), py::arg("vector_type")=ps::VectorType::STANDARD, py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("vector_type")=ps::VectorType::STANDARD, nb::rv_policy::reference) .def("add_vector_quantity2D", &ps::PointCloud::addVectorQuantity2D, "Add a vector function at points", - py::arg("name"), py::arg("values"), py::arg("vector_type")=ps::VectorType::STANDARD, py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("vector_type")=ps::VectorType::STANDARD, nb::rv_policy::reference) .def("add_parameterization_quantity", &ps::PointCloud::addParameterizationQuantity, - py::return_value_policy::reference) + nb::rv_policy::reference) ; // Static adders and getters m.def("register_point_cloud", &ps::registerPointCloud, - py::arg("name"), py::arg("values"), "Register a point cloud", py::return_value_policy::reference); + nb::arg("name"), nb::arg("values"), "Register a point cloud", nb::rv_policy::reference); m.def("register_point_cloud2D", &ps::registerPointCloud2D, - py::arg("name"), py::arg("values"), "Register a point cloud", py::return_value_policy::reference); + nb::arg("name"), nb::arg("values"), "Register a point cloud", nb::rv_policy::reference); m.def("remove_point_cloud", &polyscope::removePointCloud, "Remove a point cloud by name"); - m.def("get_point_cloud", &polyscope::getPointCloud, "Get a point cloud by name", py::return_value_policy::reference); + m.def("get_point_cloud", &polyscope::getPointCloud, "Get a point cloud by name", nb::rv_policy::reference); m.def("has_point_cloud", &polyscope::hasPointCloud, "Check for a point cloud by name"); } diff --git a/src/cpp/surface_mesh.cpp b/src/cpp/surface_mesh.cpp index a70060f..ed21fee 100644 --- a/src/cpp/surface_mesh.cpp +++ b/src/cpp/surface_mesh.cpp @@ -1,8 +1,3 @@ -#include -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/polyscope.h" @@ -11,19 +6,15 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - - -void bind_surface_mesh(py::module& m) { +void bind_surface_mesh(nb::module_& m) { // == Helper classes - py::class_(m, "SurfaceMeshPickResult") - .def(py::init<>()) - .def_readonly("element_type", &ps::SurfaceMeshPickResult::elementType) - .def_readonly("index", &ps::SurfaceMeshPickResult::index) - .def_readonly("bary_coords", &ps::SurfaceMeshPickResult::baryCoords) + nb::class_(m, "SurfaceMeshPickResult") + .def(nb::init<>()) + .def_ro("element_type", &ps::SurfaceMeshPickResult::elementType) + .def_ro("index", &ps::SurfaceMeshPickResult::index) + .def_ro("bary_coords", &ps::SurfaceMeshPickResult::baryCoords) ; @@ -33,20 +24,20 @@ void bind_surface_mesh(py::module& m) { bindScalarQuantity(m, "SurfaceEdgeScalarQuantity"); bindScalarQuantity(m, "SurfaceHalfedgeScalarQuantity"); bindScalarQuantity(m, "SurfaceCornerScalarQuantity"); - py::class_ boundScalarQ = + nb::class_ boundScalarQ = bindScalarQuantity(m, "SurfaceTextureScalarQuantity"); addTextureMapQuantityBindings(boundScalarQ); // Color quantities bindColorQuantity(m, "SurfaceVertexColorQuantity"); bindColorQuantity(m, "SurfaceFaceColorQuantity"); - py::class_ boundColorQ = + nb::class_ boundColorQ = bindColorQuantity(m, "SurfaceTextureColorQuantity"); addTextureMapQuantityBindings(boundColorQ); // Parameterization quantities - py::class_(m, "SurfaceCornerParameterizationQuantity") + nb::class_(m, "SurfaceCornerParameterizationQuantity") .def("set_enabled", &ps::SurfaceCornerParameterizationQuantity::setEnabled, "Set enabled") .def("set_style", &ps::SurfaceCornerParameterizationQuantity::setStyle, "Set style") .def("set_grid_colors", &ps::SurfaceCornerParameterizationQuantity::setGridColors, "Set grid colors") @@ -54,8 +45,8 @@ void bind_surface_mesh(py::module& m) { .def("set_checker_size", &ps::SurfaceCornerParameterizationQuantity::setCheckerSize, "Set checker size") .def("set_color_map", &ps::SurfaceCornerParameterizationQuantity::setColorMap, "Set color map") .def("set_island_labels", &ps::SurfaceCornerParameterizationQuantity::setIslandLabels) - .def("create_curve_network_from_seams", &ps::SurfaceCornerParameterizationQuantity::createCurveNetworkFromSeams, py::return_value_policy::reference); - py::class_(m, "SurfaceVertexParameterizationQuantity") + .def("create_curve_network_from_seams", &ps::SurfaceCornerParameterizationQuantity::createCurveNetworkFromSeams, nb::rv_policy::reference); + nb::class_(m, "SurfaceVertexParameterizationQuantity") .def("set_enabled", &ps::SurfaceVertexParameterizationQuantity::setEnabled, "Set enabled") .def("set_style", &ps::SurfaceVertexParameterizationQuantity::setStyle, "Set style") .def("set_grid_colors", &ps::SurfaceVertexParameterizationQuantity::setGridColors, "Set grid colors") @@ -63,7 +54,7 @@ void bind_surface_mesh(py::module& m) { .def("set_checker_size", &ps::SurfaceVertexParameterizationQuantity::setCheckerSize, "Set checker size") .def("set_color_map", &ps::SurfaceVertexParameterizationQuantity::setColorMap, "Set color map") .def("set_island_labels", &ps::SurfaceVertexParameterizationQuantity::setIslandLabels) - .def("create_curve_network_from_seams", &ps::SurfaceVertexParameterizationQuantity::createCurveNetworkFromSeams, py::return_value_policy::reference); + .def("create_curve_network_from_seams", &ps::SurfaceVertexParameterizationQuantity::createCurveNetworkFromSeams, nb::rv_policy::reference); // Vector quantities bindVectorQuantity(m, "SurfaceVertexVectorQuantity"); @@ -122,91 +113,91 @@ void bind_surface_mesh(py::module& m) { // scalar transparency .def("set_transparency_quantity", - overload_cast_()(&ps::SurfaceMesh::setTransparencyQuantity), py::arg("quantity_name")) + nb::overload_cast(&ps::SurfaceMesh::setTransparencyQuantity), nb::arg("quantity_name")) .def("clear_transparency_quantity", &ps::SurfaceMesh::clearTransparencyQuantity) // = quantities // Scalars .def("add_vertex_scalar_quantity", &ps::SurfaceMesh::addVertexScalarQuantity, - "Add a scalar function at vertices", py::arg("name"), py::arg("values"), - py::arg("data_type") = ps::DataType::STANDARD, py::return_value_policy::reference) + "Add a scalar function at vertices", nb::arg("name"), nb::arg("values"), + nb::arg("data_type") = ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_face_scalar_quantity", &ps::SurfaceMesh::addFaceScalarQuantity, - "Add a scalar function at faces", py::arg("name"), py::arg("values"), - py::arg("data_type") = ps::DataType::STANDARD, py::return_value_policy::reference) + "Add a scalar function at faces", nb::arg("name"), nb::arg("values"), + nb::arg("data_type") = ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_edge_scalar_quantity", &ps::SurfaceMesh::addEdgeScalarQuantity, - "Add a scalar function at edges", py::arg("name"), py::arg("values"), - py::arg("data_type") = ps::DataType::STANDARD, py::return_value_policy::reference) + "Add a scalar function at edges", nb::arg("name"), nb::arg("values"), + nb::arg("data_type") = ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_halfedge_scalar_quantity", &ps::SurfaceMesh::addHalfedgeScalarQuantity, - "Add a scalar function at halfedges", py::arg("name"), py::arg("values"), - py::arg("data_type") = ps::DataType::STANDARD, py::return_value_policy::reference) + "Add a scalar function at halfedges", nb::arg("name"), nb::arg("values"), + nb::arg("data_type") = ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_corner_scalar_quantity", &ps::SurfaceMesh::addCornerScalarQuantity, - "Add a scalar function at corners", py::arg("name"), py::arg("values"), - py::arg("data_type") = ps::DataType::STANDARD, py::return_value_policy::reference) + "Add a scalar function at corners", nb::arg("name"), nb::arg("values"), + nb::arg("data_type") = ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_texture_scalar_quantity", - overload_cast_()(&ps::SurfaceMesh::addTextureScalarQuantity), - "Add a scalar function from a texture map", py::arg("name"), py::arg("param_name"), py::arg("dimX"), - py::arg("dimY"), py::arg("values"), py::arg("image_origin"), py::arg("data_type") = ps::DataType::STANDARD, - py::return_value_policy::reference) + nb::overload_cast(&ps::SurfaceMesh::addTextureScalarQuantity), + "Add a scalar function from a texture map", nb::arg("name"), nb::arg("param_name"), nb::arg("dimX"), + nb::arg("dimY"), nb::arg("values"), nb::arg("image_origin"), nb::arg("data_type") = ps::DataType::STANDARD, + nb::rv_policy::reference) // Colors .def("add_vertex_color_quantity", &ps::SurfaceMesh::addVertexColorQuantity, - "Add a color value at vertices", py::return_value_policy::reference) + "Add a color value at vertices", nb::rv_policy::reference) .def("add_face_color_quantity", &ps::SurfaceMesh::addFaceColorQuantity, - "Add a color value at faces", py::return_value_policy::reference) + "Add a color value at faces", nb::rv_policy::reference) .def("add_texture_color_quantity", - overload_cast_()( + nb::overload_cast( &ps::SurfaceMesh::addTextureColorQuantity), - "Add a color function from a texture map", py::arg("name"), py::arg("param_name"), py::arg("dimX"), - py::arg("dimY"), py::arg("colors"), py::arg("image_origin"), py::return_value_policy::reference) + "Add a color function from a texture map", nb::arg("name"), nb::arg("param_name"), nb::arg("dimX"), + nb::arg("dimY"), nb::arg("colors"), nb::arg("image_origin"), nb::rv_policy::reference) // Distance .def("add_vertex_distance_quantity", &ps::SurfaceMesh::addVertexDistanceQuantity, - "Add a distance function at vertices", py::return_value_policy::reference) + "Add a distance function at vertices", nb::rv_policy::reference) .def("add_vertex_signed_distance_quantity", &ps::SurfaceMesh::addVertexSignedDistanceQuantity, - "Add a signed distance function at vertices", py::return_value_policy::reference) + "Add a signed distance function at vertices", nb::rv_policy::reference) // Parameterization .def("add_corner_parameterization_quantity", &ps::SurfaceMesh::addParameterizationQuantity, - "Add a parameterization at corners", py::return_value_policy::reference) + "Add a parameterization at corners", nb::rv_policy::reference) .def("add_vertex_parameterization_quantity", &ps::SurfaceMesh::addVertexParameterizationQuantity, - "Add a parameterization at vertices", py::return_value_policy::reference) + "Add a parameterization at vertices", nb::rv_policy::reference) // Vector .def("add_vertex_vector_quantity", &ps::SurfaceMesh::addVertexVectorQuantity, - "Add a vertex vector quantity", py::return_value_policy::reference) + "Add a vertex vector quantity", nb::rv_policy::reference) .def("add_face_vector_quantity", &ps::SurfaceMesh::addFaceVectorQuantity, - "Add a face vector quantity", py::return_value_policy::reference) + "Add a face vector quantity", nb::rv_policy::reference) .def("add_vertex_vector_quantity2D", &ps::SurfaceMesh::addVertexVectorQuantity2D, - "Add a vertex 2D vector quantity", py::return_value_policy::reference) + "Add a vertex 2D vector quantity", nb::rv_policy::reference) .def("add_face_vector_quantity2D", &ps::SurfaceMesh::addFaceVectorQuantity2D, - "Add a face 2D vector quantity", py::return_value_policy::reference) + "Add a face 2D vector quantity", nb::rv_policy::reference) .def("add_vertex_tangent_vector_quantity", &ps::SurfaceMesh::addVertexTangentVectorQuantity, - "Add a vertex tangent vector quantity", py::return_value_policy::reference) + "Add a vertex tangent vector quantity", nb::rv_policy::reference) .def("add_face_tangent_vector_quantity", &ps::SurfaceMesh::addFaceTangentVectorQuantity, - "Add a face tangent vector quantity", py::return_value_policy::reference) + "Add a face tangent vector quantity", nb::rv_policy::reference) .def("add_one_form_tangent_vector_quantity", &ps::SurfaceMesh::addOneFormTangentVectorQuantity>, - "Add a one form tangent vector quantity", py::return_value_policy::reference); + "Add a one form tangent vector quantity", nb::rv_policy::reference); // Static adders and getters - m.def("register_surface_mesh", &ps::registerSurfaceMesh, py::arg("name"), - py::arg("vertices"), py::arg("faces"), "Register a surface mesh", py::return_value_policy::reference); - m.def("register_surface_mesh2D", &ps::registerSurfaceMesh2D, py::arg("name"), - py::arg("vertices"), py::arg("faces"), "Register a surface mesh", py::return_value_policy::reference); + m.def("register_surface_mesh", &ps::registerSurfaceMesh, nb::arg("name"), + nb::arg("vertices"), nb::arg("faces"), "Register a surface mesh", nb::rv_policy::reference); + m.def("register_surface_mesh2D", &ps::registerSurfaceMesh2D, nb::arg("name"), + nb::arg("vertices"), nb::arg("faces"), "Register a surface mesh", nb::rv_policy::reference); m.def("register_surface_mesh_list", &ps::registerSurfaceMesh>>, - py::arg("name"), py::arg("vertices"), py::arg("faces"), "Register a surface mesh from a nested list", - py::return_value_policy::reference); + nb::arg("name"), nb::arg("vertices"), nb::arg("faces"), "Register a surface mesh from a nested list", + nb::rv_policy::reference); m.def("register_surface_mesh_list2D", &ps::registerSurfaceMesh2D>>, - py::arg("name"), py::arg("vertices"), py::arg("faces"), "Register a surface mesh from a nested list", - py::return_value_policy::reference); + nb::arg("name"), nb::arg("vertices"), nb::arg("faces"), "Register a surface mesh from a nested list", + nb::rv_policy::reference); m.def("remove_surface_mesh", &polyscope::removeSurfaceMesh, "Remove a surface mesh by name"); m.def("get_surface_mesh", &polyscope::getSurfaceMesh, "Get a surface mesh by name", - py::return_value_policy::reference); + nb::rv_policy::reference); m.def("has_surface_mesh", &polyscope::hasSurfaceMesh, "Check for a surface mesh by name"); } diff --git a/src/cpp/utils.h b/src/cpp/utils.h index 6541cc4..bfc5951 100644 --- a/src/cpp/utils.h +++ b/src/cpp/utils.h @@ -1,8 +1,13 @@ #pragma once -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include @@ -10,13 +15,10 @@ #include "polyscope/image_quantity.h" -namespace py = pybind11; +namespace nb = nanobind; +using namespace nb::literals; namespace ps = polyscope; -// For overloaded functions, with C++11 compiler only -template -using overload_cast_ = pybind11::detail::overload_cast_impl; - // Some conversion helpers template inline glm::mat eigen2glm(const Eigen::Matrix& mat_eigen) { @@ -61,7 +63,7 @@ void def_get_managed_buffer(C& c, std::string postfix) { [](StructureT& s, std::string buffer_name) -> ps::render::ManagedBuffer& { return s.template getManagedBuffer(buffer_name); }, - "get managed buffer", py::return_value_policy::reference); + "get managed buffer", nb::rv_policy::reference); } template @@ -82,7 +84,7 @@ void def_get_quantity_managed_buffer(C& c, std::string postfix) { // here, to silence warnings throw std::logic_error("structure has no such quantity"); }, - "get quantity managed buffer", py::return_value_policy::reference); + "get quantity managed buffer", nb::rv_policy::reference); } @@ -95,14 +97,13 @@ void def_all_managed_buffer_funcs(C& c, ps::ManagedBufferType t) { // Add common bindings for structures template -py::class_ bindStructure(py::module& m, std::string name) { +nb::class_ bindStructure(nb::module_& m, std::string name) { - py::class_ s(m, name.c_str()); + nb::class_ s(m, name.c_str()); // structure basics s.def("remove", &StructureT::remove, "Remove the structure") - .def( - "get_name", [](StructureT& s) { return s.name; }, "Ge the name") + .def("get_name", [](StructureT& s) { return s.name; }, "Ge the name") .def("get_unique_prefix", &StructureT::uniquePrefix, "Get unique prefix") .def("set_enabled", &StructureT::setEnabled, "Enable the structure") .def("enable_isolate", &StructureT::enableIsolate, "Enable the structure, disable all of same type") @@ -111,7 +112,7 @@ py::class_ bindStructure(py::module& m, std::string name) { .def("get_transparency", &StructureT::getTransparency, "Get transparency alpha") // group things - .def("add_to_group", overload_cast_()(&StructureT::addToGroup), "Add to group") + .def("add_to_group", nb::overload_cast(&StructureT::addToGroup), "Add to group") // slice plane things .def("set_ignore_slice_plane", &StructureT::setIgnoreSlicePlane, "Set ignore slice plane") @@ -121,7 +122,7 @@ py::class_ bindStructure(py::module& m, std::string name) { // quantites .def("remove_all_quantities", &StructureT::removeAllQuantities, "Remove all quantities") - .def("remove_quantity", &StructureT::removeQuantity, py::arg("name"), py::arg("errorIfAbsent") = false, + .def("remove_quantity", &StructureT::removeQuantity, nb::arg("name"), nb::arg("errorIfAbsent") = false, "Remove a quantity") // transform management @@ -136,17 +137,17 @@ py::class_ bindStructure(py::module& m, std::string name) { .def("get_position", [](StructureT& s) { return glm2eigen(s.getPosition()); }, "get the position of the shape origin after transform") .def("set_transform_gizmo_enabled", &StructureT::setTransformGizmoEnabled) .def("get_transform_gizmo_enabled", &StructureT::getTransformGizmoEnabled) - .def("get_transformation_gizmo", &StructureT::getTransformGizmo, py::return_value_policy::reference, "Get the TransformationGizmo associated with this structure") + .def("get_transformation_gizmo", &StructureT::getTransformGizmo, nb::rv_policy::reference, "Get the TransformationGizmo associated with this structure") // floating quantites - .def("add_scalar_image_quantity", &StructureT::template addScalarImageQuantity, py::arg("name"), py::arg("dimX"), py::arg("dimY"), py::arg("values"), py::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, py::arg("type")=ps::DataType::STANDARD, py::return_value_policy::reference) - .def("add_color_image_quantity", &StructureT::template addColorImageQuantity, py::arg("name"), py::arg("dimX"), py::arg("dimY"), py::arg("values_rgb"), py::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, py::return_value_policy::reference) - .def("add_color_alpha_image_quantity", &StructureT::template addColorAlphaImageQuantity, py::arg("name"), py::arg("dimX"), py::arg("dimY"), py::arg("values_rgba"), py::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, py::return_value_policy::reference) - .def("add_depth_render_image_quantity", &StructureT::template addDepthRenderImageQuantity, py::arg("name"), py::arg("dimX"), py::arg("dimY"), py::arg("depthData"), py::arg("normalData"), py::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, py::return_value_policy::reference) - .def("add_color_render_image_quantity", &StructureT::template addColorRenderImageQuantity, py::arg("name"), py::arg("dimX"), py::arg("dimY"), py::arg("depthData"), py::arg("normalData"), py::arg("colorData"), py::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, py::return_value_policy::reference) - .def("add_scalar_render_image_quantity", &StructureT::template addScalarRenderImageQuantity, py::arg("name"), py::arg("dimX"), py::arg("dimY"), py::arg("depthData"), py::arg("normalData"), py::arg("scalarData"), py::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, py::arg("type")=ps::DataType::STANDARD, py::return_value_policy::reference) - .def("add_raw_color_render_image_quantity", &StructureT::template addRawColorRenderImageQuantity, py::arg("name"), py::arg("dimX"), py::arg("dimY"), py::arg("depthData"), py::arg("colorData"), py::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, py::return_value_policy::reference) - .def("add_raw_color_alpha_render_image_quantity", &StructureT::template addRawColorAlphaRenderImageQuantity, py::arg("name"), py::arg("dimX"), py::arg("dimY"), py::arg("depthData"), py::arg("colorData"), py::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, py::return_value_policy::reference) + .def("add_scalar_image_quantity", &StructureT::template addScalarImageQuantity, nb::arg("name"), nb::arg("dimX"), nb::arg("dimY"), nb::arg("values"), nb::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, nb::arg("type")=ps::DataType::STANDARD, nb::rv_policy::reference) + .def("add_color_image_quantity", &StructureT::template addColorImageQuantity, nb::arg("name"), nb::arg("dimX"), nb::arg("dimY"), nb::arg("values_rgb"), nb::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, nb::rv_policy::reference) + .def("add_color_alpha_image_quantity", &StructureT::template addColorAlphaImageQuantity, nb::arg("name"), nb::arg("dimX"), nb::arg("dimY"), nb::arg("values_rgba"), nb::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, nb::rv_policy::reference) + .def("add_depth_render_image_quantity", &StructureT::template addDepthRenderImageQuantity, nb::arg("name"), nb::arg("dimX"), nb::arg("dimY"), nb::arg("depthData"), nb::arg("normalData"), nb::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, nb::rv_policy::reference) + .def("add_color_render_image_quantity", &StructureT::template addColorRenderImageQuantity, nb::arg("name"), nb::arg("dimX"), nb::arg("dimY"), nb::arg("depthData"), nb::arg("normalData"), nb::arg("colorData"), nb::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, nb::rv_policy::reference) + .def("add_scalar_render_image_quantity", &StructureT::template addScalarRenderImageQuantity, nb::arg("name"), nb::arg("dimX"), nb::arg("dimY"), nb::arg("depthData"), nb::arg("normalData"), nb::arg("scalarData"), nb::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, nb::arg("type")=ps::DataType::STANDARD, nb::rv_policy::reference) + .def("add_raw_color_render_image_quantity", &StructureT::template addRawColorRenderImageQuantity, nb::arg("name"), nb::arg("dimX"), nb::arg("dimY"), nb::arg("depthData"), nb::arg("colorData"), nb::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, nb::rv_policy::reference) + .def("add_raw_color_alpha_render_image_quantity", &StructureT::template addRawColorAlphaRenderImageQuantity, nb::arg("name"), nb::arg("dimX"), nb::arg("dimY"), nb::arg("depthData"), nb::arg("colorData"), nb::arg("imageOrigin")=ps::ImageOrigin::UpperLeft, nb::rv_policy::reference) ; @@ -189,21 +190,20 @@ py::class_ bindStructure(py::module& m, std::string name) { // Common bindings for quantities that do not fall in to a more specific quantity below template -py::class_ bindQuantity(py::module& m, std::string name) { - return py::class_(m, name.c_str()).def("set_enabled", &Q::setEnabled, "Set enabled"); +nb::class_ bindQuantity(nb::module_& m, std::string name) { + return nb::class_(m, name.c_str()).def("set_enabled", &Q::setEnabled, "Set enabled"); } // Add common bindings for all scalar quantities template -py::class_ bindScalarQuantity(py::module& m, std::string name) { +nb::class_ bindScalarQuantity(nb::module_& m, std::string name) { return bindQuantity(m, name.c_str()) .def("set_color_map", &ScalarQ::setColorMap, "Set color map") - .def("set_map_range", &ScalarQ::setMapRange, "Set map range") + .def("set_map_range", [] (ScalarQ& self, std::tuple vals) { self.setMapRange({std::get<0>(vals), std::get<1>(vals)}); }, "Set map range") .def("set_onscreen_colorbar_enabled", &ScalarQ::setOnscreenColorbarEnabled, "Set onscreen color bar enabled") .def("set_onscreen_colorbar_location", &ScalarQ::setOnscreenColorbarLocation, "Set onscreen color bar location") // TODO add exportColorMapToSVG() - .def("set_map_range", &ScalarQ::setMapRange, "Set map range") .def("set_isolines_enabled", &ScalarQ::setIsolinesEnabled) .def("set_isoline_style", &ScalarQ::setIsolineStyle) .def("set_isoline_period", &ScalarQ::setIsolinePeriod, "Set isoline period") @@ -213,7 +213,7 @@ py::class_ bindScalarQuantity(py::module& m, std::string name) { } template -py::class_ bindVMVScalarQuantity(py::module& m, std::string name) { +nb::class_ bindVMVScalarQuantity(nb::module_& m, std::string name) { return bindScalarQuantity(m, name.c_str()) .def("set_level_set_enable", &VolumeMeshVertexScalarQuantity::setEnabledLevelSet, "Set level set rendering enabled") @@ -224,13 +224,13 @@ py::class_ bindVMVScalarQuantity(py::module& m, // Add common bindings for all color quantities template -py::class_ bindColorQuantity(py::module& m, std::string name) { +nb::class_ bindColorQuantity(nb::module_& m, std::string name) { return bindQuantity(m, name.c_str()); } // Add common bindings for all vector quantities template -py::class_ bindVectorQuantity(py::module& m, std::string name) { +nb::class_ bindVectorQuantity(nb::module_& m, std::string name) { return bindQuantity(m, name.c_str()) .def("set_length", &VectorQ::setVectorLengthScale, "Set length") .def("set_radius", &VectorQ::setVectorRadius, "Set radius") @@ -241,14 +241,14 @@ py::class_ bindVectorQuantity(py::module& m, std::string name) { // Add common bindings for all texture map quantities // (this one is 'additive', ) template -void addTextureMapQuantityBindings(py::class_& boundTextureQ) { +void addTextureMapQuantityBindings(nb::class_& boundTextureQ) { boundTextureQ.def("set_filter_mode", &TextureQ::setFilterMode, "Set filter mode"); } // Add common image options // Note: unlike the others above, this adds methods to an existing quantity rather than binding a new one. template -void addImageQuantityBindings(py::class_& imageQ) { +void addImageQuantityBindings(nb::class_& imageQ) { imageQ.def("set_show_fullscreen", &ImageQ::setShowFullscreen); imageQ.def("get_show_fullscreen", &ImageQ::getShowFullscreen); diff --git a/src/cpp/volume_grid.cpp b/src/cpp/volume_grid.cpp index ea72501..0d7789e 100644 --- a/src/cpp/volume_grid.cpp +++ b/src/cpp/volume_grid.cpp @@ -1,9 +1,3 @@ -#include -#include -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/polyscope.h" @@ -11,17 +5,14 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - -void bind_volume_grid(py::module& m) { +void bind_volume_grid(nb::module_& m) { // == Helper classes - py::class_(m, "VolumeGridPickResult") - .def(py::init<>()) - .def_readonly("element_type", &ps::VolumeGridPickResult::elementType) - .def_readonly("index", &ps::VolumeGridPickResult::index) + nb::class_(m, "VolumeGridPickResult") + .def(nb::init<>()) + .def_ro("element_type", &ps::VolumeGridPickResult::elementType) + .def_ro("index", &ps::VolumeGridPickResult::index) ; // Scalar quantities @@ -33,7 +24,7 @@ void bind_volume_grid(py::module& m) { .def("set_slice_planes_affect_isosurface", &ps::VolumeGridNodeScalarQuantity::setSlicePlanesAffectIsosurface) .def("register_isosurface_as_mesh_with_name", [](ps::VolumeGridNodeScalarQuantity& x, std::string name) { return x.registerIsosurfaceAsMesh(name); }, - py::return_value_policy::reference) + nb::rv_policy::reference) ; bindScalarQuantity(m, "VolumeGridCellScalarQuantity") @@ -74,12 +65,12 @@ void bind_volume_grid(py::module& m) { // Scalars .def("add_node_scalar_quantity", &ps::VolumeGrid::addNodeScalarQuantity, - py::arg("name"), py::arg("values"), py::arg("data_type") = ps::DataType::STANDARD, - py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("data_type") = ps::DataType::STANDARD, + nb::rv_policy::reference) .def("add_cell_scalar_quantity", &ps::VolumeGrid::addCellScalarQuantity, - py::arg("name"), py::arg("values"), py::arg("data_type") = ps::DataType::STANDARD, - py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("data_type") = ps::DataType::STANDARD, + nb::rv_policy::reference) // add from a callable lambda .def("add_node_scalar_quantity_from_callable", []( @@ -98,8 +89,8 @@ void bind_volume_grid(py::module& m) { return grid.addNodeScalarQuantityFromBatchCallable(name, wrapped_func, data_type); }, - py::arg("name"), py::arg("values"), py::arg("data_type") = ps::DataType::STANDARD, - py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("data_type") = ps::DataType::STANDARD, + nb::rv_policy::reference) .def("add_cell_scalar_quantity_from_callable", []( ps::VolumeGrid& grid, @@ -117,8 +108,8 @@ void bind_volume_grid(py::module& m) { return grid.addNodeScalarQuantityFromBatchCallable(name, wrapped_func, data_type); }, - py::arg("name"), py::arg("values"), py::arg("data_type") = ps::DataType::STANDARD, - py::return_value_policy::reference) + nb::arg("name"), nb::arg("values"), nb::arg("data_type") = ps::DataType::STANDARD, + nb::rv_policy::reference) // Colors @@ -127,10 +118,10 @@ void bind_volume_grid(py::module& m) { ; // Static adders and getters - m.def("register_volume_grid", overload_cast_()(&ps::registerVolumeGrid), py::arg("name"), - py::arg("gridNodeDim"), py::arg("boundMin"), py::arg("boundMax"), py::return_value_policy::reference); + m.def("register_volume_grid", nb::overload_cast(&ps::registerVolumeGrid), nb::arg("name"), + nb::arg("gridNodeDim"), nb::arg("boundMin"), nb::arg("boundMax"), nb::rv_policy::reference); m.def("remove_volume_grid", &polyscope::removeVolumeGrid); - m.def("get_volume_grid", &polyscope::getVolumeGrid, py::return_value_policy::reference); + m.def("get_volume_grid", &polyscope::getVolumeGrid, nb::rv_policy::reference); m.def("has_volume_grid", &polyscope::hasVolumeGrid); } diff --git a/src/cpp/volume_mesh.cpp b/src/cpp/volume_mesh.cpp index 78781d1..9235da7 100644 --- a/src/cpp/volume_mesh.cpp +++ b/src/cpp/volume_mesh.cpp @@ -1,8 +1,3 @@ -#include -#include -#include -#include - #include "Eigen/Dense" #include "polyscope/polyscope.h" @@ -10,17 +5,14 @@ #include "utils.h" -namespace py = pybind11; -namespace ps = polyscope; - -void bind_volume_mesh(py::module& m) { +void bind_volume_mesh(nb::module_& m) { // == Helper classes - py::class_(m, "VolumeMeshPickResult") - .def(py::init<>()) - .def_readonly("element_type", &ps::VolumeMeshPickResult::elementType) - .def_readonly("index", &ps::VolumeMeshPickResult::index) + nb::class_(m, "VolumeMeshPickResult") + .def(nb::init<>()) + .def_ro("element_type", &ps::VolumeMeshPickResult::elementType) + .def_ro("index", &ps::VolumeMeshPickResult::index) ; // Scalar quantities @@ -64,41 +56,41 @@ void bind_volume_mesh(py::module& m) { // Scalars .def("add_vertex_scalar_quantity", &ps::VolumeMesh::addVertexScalarQuantity, - "Add a scalar function at vertices", py::arg("name"), py::arg("values"), - py::arg("data_type") = ps::DataType::STANDARD, py::return_value_policy::reference) + "Add a scalar function at vertices", nb::arg("name"), nb::arg("values"), + nb::arg("data_type") = ps::DataType::STANDARD, nb::rv_policy::reference) .def("add_cell_scalar_quantity", &ps::VolumeMesh::addCellScalarQuantity, - "Add a scalar function at cells", py::arg("name"), py::arg("values"), - py::arg("data_type") = ps::DataType::STANDARD, py::return_value_policy::reference) + "Add a scalar function at cells", nb::arg("name"), nb::arg("values"), + nb::arg("data_type") = ps::DataType::STANDARD, nb::rv_policy::reference) // Colors .def("add_vertex_color_quantity", &ps::VolumeMesh::addVertexColorQuantity, - "Add a color value at vertices", py::return_value_policy::reference) + "Add a color value at vertices", nb::rv_policy::reference) .def("add_cell_color_quantity", &ps::VolumeMesh::addCellColorQuantity, - "Add a color value at cells", py::return_value_policy::reference) + "Add a color value at cells", nb::rv_policy::reference) // Vector .def("add_vertex_vector_quantity", &ps::VolumeMesh::addVertexVectorQuantity, - "Add a vertex vector quantity", py::return_value_policy::reference) + "Add a vertex vector quantity", nb::rv_policy::reference) .def("add_cell_vector_quantity", &ps::VolumeMesh::addCellVectorQuantity, - "Add a cell vector quantity", py::return_value_policy::reference); + "Add a cell vector quantity", nb::rv_policy::reference); // Static adders and getters - m.def("register_tet_mesh", &ps::registerTetMesh, py::arg("name"), - py::arg("vertices"), py::arg("tets"), "Register a volume mesh of tet cells", - py::return_value_policy::reference); - m.def("register_hex_mesh", &ps::registerHexMesh, py::arg("name"), - py::arg("vertices"), py::arg("hexes"), "Register a volume mesh of hex cells", - py::return_value_policy::reference); - m.def("register_volume_mesh", &ps::registerVolumeMesh, py::arg("name"), - py::arg("vertices"), py::arg("cells"), "Register a volume mesh with a mix of element types", - py::return_value_policy::reference); + m.def("register_tet_mesh", &ps::registerTetMesh, nb::arg("name"), + nb::arg("vertices"), nb::arg("tets"), "Register a volume mesh of tet cells", + nb::rv_policy::reference); + m.def("register_hex_mesh", &ps::registerHexMesh, nb::arg("name"), + nb::arg("vertices"), nb::arg("hexes"), "Register a volume mesh of hex cells", + nb::rv_policy::reference); + m.def("register_volume_mesh", &ps::registerVolumeMesh, nb::arg("name"), + nb::arg("vertices"), nb::arg("cells"), "Register a volume mesh with a mix of element types", + nb::rv_policy::reference); m.def("register_tet_hex_mesh", &ps::registerTetHexMesh, - py::arg("name"), py::arg("vertices"), py::arg("tets"), py::arg("hexes"), - "Register a volume mesh with lists of tet and hex elements", py::return_value_policy::reference); + nb::arg("name"), nb::arg("vertices"), nb::arg("tets"), nb::arg("hexes"), + "Register a volume mesh with lists of tet and hex elements", nb::rv_policy::reference); m.def("remove_volume_mesh", &polyscope::removeVolumeMesh, "Remove a volume mesh by name"); - m.def("get_volume_mesh", &polyscope::getVolumeMesh, "Get a volume mesh by name", py::return_value_policy::reference); + m.def("get_volume_mesh", &polyscope::getVolumeMesh, "Get a volume mesh by name", nb::rv_policy::reference); m.def("has_volume_mesh", &polyscope::hasVolumeMesh, "Check for a volume mesh by name"); } diff --git a/src/polyscope/core.py b/src/polyscope/core.py index a1c9de5..d019d3e 100644 --- a/src/polyscope/core.py +++ b/src/polyscope/core.py @@ -342,7 +342,10 @@ def terminating_error(message): ### Callback def set_user_callback(func): - psb.set_user_callback(func) + if func is None: + psb.clear_user_callback() + else: + psb.set_user_callback(func) def clear_user_callback(): psb.clear_user_callback() @@ -1259,6 +1262,6 @@ def get_key_code(k): k = k.upper() if k not in keycode_dict: - raise ValueError(f"character {k} not in keycode mapping. Keys which have multiple characters on them, try the other character (like @ vs 2). Alternately, don't use this function, look up the appropriate enum from the imgui documentation, use them like polyscope.imgui.ImGuiKey_Semicolon") + raise ValueError(f"character {k} not in keycode mapping. For keys which have multiple characters on them, try the other character (like @ vs 2). Alternately, don't use this function, look up the appropriate enum from the imgui documentation, use them like polyscope.imgui.ImGuiKey_Semicolon") return keycode_dict[k] diff --git a/src/polyscope/managed_buffer.py b/src/polyscope/managed_buffer.py index cf3135d..fb8fd0b 100644 --- a/src/polyscope/managed_buffer.py +++ b/src/polyscope/managed_buffer.py @@ -37,6 +37,10 @@ def size(self): return self.bound_buffer.size() + def shape(self): + self.check_ref_still_valid() + return tuple(self.bound_buffer.data_shape()) + def get_texture_size(self): self.check_ref_still_valid() @@ -63,9 +67,6 @@ def get_value(self, ind, indY=None, indZ=None): def update_data(self, new_vals): self.check_ref_still_valid() - - new_vals = new_vals.reshape((self.size(),-1)) - self.update_data_from_host(new_vals) def update_data_from_host(self, new_vals): diff --git a/test/polyscope_test.py b/test/polyscope_test.py index b81dba4..6a79952 100644 --- a/test/polyscope_test.py +++ b/test/polyscope_test.py @@ -2739,6 +2739,13 @@ def generate_scalar(n_pts=10): ps_scalar = ps_cloud.add_scalar_quantity("test_vals", generate_scalar()) ps.show(3) + # test a quantity buffer of float + scalar_buf = ps_cloud.get_quantity_buffer("test_vals", "values") + self.assertEqual(scalar_buf.size(), 10) + self.assertTrue(scalar_buf.has_data()) + scalar_buf.get_value(3) + scalar_buf.update_data(generate_scalar()) + # test a structure buffer of vec3 pos_buf = ps_cloud.get_buffer("points") self.assertEqual(pos_buf.size(), 10) @@ -2746,14 +2753,6 @@ def generate_scalar(n_pts=10): pos_buf.summary_string() pos_buf.get_value(3) pos_buf.update_data(generate_points()) - - # test a quantity buffer of float - scalar_buf = ps_cloud.get_quantity_buffer("test_vals", "values") - self.assertEqual(scalar_buf.size(), 10) - self.assertTrue(scalar_buf.has_data()) - scalar_buf.summary_string() - scalar_buf.get_value(3) - scalar_buf.update_data(generate_scalar()) ps.show(3) From 11999a7a60fa127e496c5d36abc5f1fbbaf09470 Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Thu, 25 Dec 2025 02:18:53 -0500 Subject: [PATCH 4/4] update some comments --- src/cpp/core.cpp | 2 +- src/cpp/implicit_helpers.cpp | 8 ++++---- src/cpp/volume_grid.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cpp/core.cpp b/src/cpp/core.cpp index 74b76da..55ab379 100644 --- a/src/cpp/core.cpp +++ b/src/cpp/core.cpp @@ -209,7 +209,7 @@ NB_MODULE(polyscope_bindings, m) { m.def("set_user_callback", [](const std::function& func) { // Create a wrapper which checks signals before calling the passed fuction // Captures by value, because otherwise func seems to become invalid. This is probably happening - // on the Python side, and could be fixed with some Pybind11 keep_alive-s or something, but in + // on the Python side, and could be fixed with some nanobind keep_alive-s or something, but in // lieu of figuring that out capture by value seems fine. // See also the atexit() cleanup registered above, which is used to ensure any bound functions get deleted and we can exit cleanly. auto wrapperFunc = [=]() { diff --git a/src/cpp/implicit_helpers.cpp b/src/cpp/implicit_helpers.cpp index 6dac178..970fe41 100644 --- a/src/cpp/implicit_helpers.cpp +++ b/src/cpp/implicit_helpers.cpp @@ -37,7 +37,7 @@ void bind_implicit_helpers(nb::module_& m) { ps::ImplicitRenderMode mode, ps::ImplicitRenderOpts opts, ps::CameraView* cameraView ) { - // Polyscope's API uses raw buffer pointers, but we use Eigen mats for pybind11. + // Polyscope's API uses raw buffer pointers, but we use Eigen mats for numpy<->eigen interop with python. // Create a wrapper function that goes to/from the Eigen mats auto wrapped_func = [&](const float* pos_ptr, float* result_ptr, uint64_t size) { Eigen::Map> mapped_pos(pos_ptr, size, 3); @@ -66,7 +66,7 @@ void bind_implicit_helpers(nb::module_& m) { ps::ImplicitRenderMode mode, ps::ImplicitRenderOpts opts, ps::CameraView* cameraView ) { - // Polyscope's API uses raw buffer pointers, but we use Eigen mats for pybind11. + // Polyscope's API uses raw buffer pointers, but we use Eigen mats for numpy<->eigen interop with python. // Create a wrapper function that goes to/from the Eigen mats auto wrapped_func = [&](const float* pos_ptr, float* result_ptr, uint64_t size) { Eigen::Map> mapped_pos(pos_ptr, size, 3); @@ -101,7 +101,7 @@ void bind_implicit_helpers(nb::module_& m) { ps::ImplicitRenderMode mode, ps::ImplicitRenderOpts opts, ps::CameraView* cameraView ) { - // Polyscope's API uses raw buffer pointers, but we use Eigen mats for pybind11. + // Polyscope's API uses raw buffer pointers, but we use Eigen mats for numpy<->eigen interop with python. // Create a wrapper function that goes to/from the Eigen mats auto wrapped_func = [&](const float* pos_ptr, float* result_ptr, uint64_t size) { Eigen::Map> mapped_pos(pos_ptr, size, 3); @@ -135,7 +135,7 @@ void bind_implicit_helpers(nb::module_& m) { ps::ImplicitRenderMode mode, ps::ImplicitRenderOpts opts, ps::CameraView* cameraView ) { - // Polyscope's API uses raw buffer pointers, but we use Eigen mats for pybind11. + // Polyscope's API uses raw buffer pointers, but we use Eigen mats for numpy<->eigen interop with python. // Create a wrapper function that goes to/from the Eigen mats auto wrapped_func = [&](const float* pos_ptr, float* result_ptr, uint64_t size) { Eigen::Map> mapped_pos(pos_ptr, size, 3); diff --git a/src/cpp/volume_grid.cpp b/src/cpp/volume_grid.cpp index 0d7789e..4e4098f 100644 --- a/src/cpp/volume_grid.cpp +++ b/src/cpp/volume_grid.cpp @@ -79,7 +79,7 @@ void bind_volume_grid(nb::module_& m) { const std::function)>& func, ps::DataType data_type) { - // Polyscope's API uses raw buffer pointers, but we use Eigen mats for pybind11. + // Polyscope's API uses raw buffer pointers, but we use Eigen mats for numpy<->eigen interop with python. // Create a wrapper function that goes to/from the Eigen mats auto wrapped_func = [&](const float* pos_ptr, float* result_ptr, uint64_t size) { Eigen::Map> mapped_pos(pos_ptr, size, 3); @@ -98,7 +98,7 @@ void bind_volume_grid(nb::module_& m) { const std::function)>& func, ps::DataType data_type) { - // Polyscope's API uses raw buffer pointers, but we use Eigen mats for pybind11. + // Polyscope's API uses raw buffer pointers, but we use Eigen mats for numpy<->eigen interop with python. // Create a wrapper function that goes to/from the Eigen mats auto wrapped_func = [&](const float* pos_ptr, float* result_ptr, uint64_t size) { Eigen::Map> mapped_pos(pos_ptr, size, 3);