Skip to content

Commit 6b25790

Browse files
committed
Added __repr__ for Margins to provide nicer default values.
1 parent ac95b0e commit 6b25790

File tree

1 file changed

+13
-1
lines changed
  • cpp/pybind/visualization/gui

1 file changed

+13
-1
lines changed

cpp/pybind/visualization/gui/gui.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,19 @@ void pybind_gui_definitions(py::module &m) {
18091809
.def_readwrite("right", &Margins::right)
18101810
.def_readwrite("bottom", &Margins::bottom)
18111811
.def("get_horiz", &Margins::GetHoriz)
1812-
.def("get_vert", &Margins::GetVert);
1812+
.def("get_vert", &Margins::GetVert)
1813+
.def("__repr__", [](const Margins &m) -> std::string {
1814+
if (m.left == 0 && m.top == 0 && m.right == 0 && m.bottom == 0)
1815+
return "Margins()";
1816+
else if (m.left == m.top && m.top == m.right &&
1817+
m.right == m.bottom)
1818+
return fmt::format("Margins({})", m.left);
1819+
else if (m.left == m.right && m.top == m.bottom)
1820+
return fmt::format("Margins({}, {})", m.left, m.top);
1821+
else
1822+
return fmt::format("Margins({}, {}, {}, {})", m.left, m.top,
1823+
m.right, m.bottom);
1824+
});
18131825

18141826
// ---- Layout1D ----
18151827
auto layout1d =

0 commit comments

Comments
 (0)