1 | #ifdef NANOGUI_PYTHON |
2 | |
3 | #include "python.h" |
4 | |
5 | DECLARE_LAYOUT(Layout); |
6 | DECLARE_LAYOUT(GroupLayout); |
7 | DECLARE_LAYOUT(BoxLayout); |
8 | DECLARE_LAYOUT(GridLayout); |
9 | DECLARE_LAYOUT(AdvancedGridLayout); |
10 | |
11 | void register_layout(py::module &m) { |
12 | py::class_<Layout, ref<Layout>, PyLayout> layout(m, "Layout" , D(Layout)); |
13 | layout |
14 | .def("preferredSize" , &Layout::preferredSize, D(Layout, preferredSize)) |
15 | .def("performLayout" , &Layout::performLayout, D(Layout, performLayout)); |
16 | |
17 | py::class_<BoxLayout, Layout, ref<BoxLayout>, PyBoxLayout>(m, "BoxLayout" , D(BoxLayout)) |
18 | .def(py::init<Orientation, Alignment, int, int>(), |
19 | py::arg("orientation" ), py::arg("alignment" ) = Alignment::Middle, |
20 | py::arg("margin" ) = 0, py::arg("spacing" ) = 0, D(BoxLayout, BoxLayout)) |
21 | .def("orientation" , &BoxLayout::orientation, D(BoxLayout, orientation)) |
22 | .def("setOrientation" , &BoxLayout::setOrientation, D(BoxLayout, setOrientation)) |
23 | .def("alignment" , &BoxLayout::alignment, D(BoxLayout, alignment)) |
24 | .def("setAlignment" , &BoxLayout::setAlignment, D(BoxLayout, setAlignment)) |
25 | .def("margin" , &BoxLayout::margin, D(BoxLayout, margin)) |
26 | .def("setMargin" , &BoxLayout::setMargin, D(BoxLayout, setMargin)) |
27 | .def("spacing" , &BoxLayout::spacing, D(BoxLayout, spacing)) |
28 | .def("setSpacing" , &BoxLayout::setSpacing, D(BoxLayout, setSpacing)); |
29 | |
30 | py::class_<GroupLayout, Layout, ref<GroupLayout>, PyGroupLayout>(m, "GroupLayout" , D(GroupLayout)) |
31 | .def(py::init<int, int, int, int>(), |
32 | py::arg("margin" ) = 15, py::arg("spacing" ) = 6, |
33 | py::arg("groupSpacing" ) = 14, py::arg("groupIndent" ) = 20, |
34 | D(GroupLayout, GroupLayout)) |
35 | .def("margin" , &GroupLayout::margin, D(GroupLayout, margin)) |
36 | .def("setMargin" , &GroupLayout::setMargin, D(GroupLayout, setMargin)) |
37 | .def("spacing" , &GroupLayout::spacing, D(GroupLayout, spacing)) |
38 | .def("setSpacing" , &GroupLayout::setSpacing, D(GroupLayout, setSpacing)) |
39 | .def("groupIndent" , &GroupLayout::groupIndent, D(GroupLayout, groupIndent)) |
40 | .def("setGroupIndent" , &GroupLayout::setGroupIndent, D(GroupLayout, setGroupIndent)) |
41 | .def("groupSpacing" , &GroupLayout::groupSpacing, D(GroupLayout, groupSpacing)) |
42 | .def("setGroupSpacing" , &GroupLayout::setGroupSpacing, D(GroupLayout, setGroupSpacing)); |
43 | |
44 | py::class_<GridLayout, Layout, ref<GridLayout>, PyGridLayout>(m, "GridLayout" , D(GridLayout)) |
45 | .def(py::init<Orientation, int, Alignment, int, int>(), |
46 | py::arg("orientation" ) = Orientation::Horizontal, |
47 | py::arg("resolution" ) = 2, py::arg("alignment" ) = Alignment::Middle, |
48 | py::arg("margin" ) = 0, py::arg("spacing" ) = 0, |
49 | D(GridLayout, GridLayout)) |
50 | .def("orientation" , &GridLayout::orientation, D(GridLayout, orientation)) |
51 | .def("setOrientation" , &GridLayout::setOrientation, D(GridLayout, setOrientation)) |
52 | .def("resolution" , &GridLayout::resolution, D(GridLayout, resolution)) |
53 | .def("setResolution" , &GridLayout::setResolution, D(GridLayout, setResolution)) |
54 | .def("margin" , &GridLayout::margin, D(GridLayout, margin)) |
55 | .def("setMargin" , &GridLayout::setMargin, D(GridLayout, setMargin)) |
56 | .def("spacing" , &GridLayout::spacing, D(GridLayout, spacing)) |
57 | .def("setSpacing" , (void(GridLayout::*)(int)) &GridLayout::setSpacing, D(GridLayout, setSpacing)) |
58 | .def("setSpacing" , (void(GridLayout::*)(int, int)) &GridLayout::setSpacing, D(GridLayout, setSpacing, 2)) |
59 | .def("alignment" , &GridLayout::alignment, D(GridLayout, alignment)) |
60 | .def("setColAlignment" , (void(GridLayout::*)(Alignment)) &GridLayout::setColAlignment, D(GridLayout, setColAlignment)) |
61 | .def("setRowAlignment" , (void(GridLayout::*)(Alignment)) &GridLayout::setRowAlignment, D(GridLayout, setRowAlignment)) |
62 | .def("setColAlignment" , (void(GridLayout::*)(const std::vector<Alignment>&)) &GridLayout::setColAlignment/*, D(GridLayout, setColAlignment, 2)*/) |
63 | .def("setRowAlignment" , (void(GridLayout::*)(const std::vector<Alignment>&)) &GridLayout::setRowAlignment/*, D(GridLayout, setRowAlignment, 2)*/); |
64 | |
65 | py::class_<AdvancedGridLayout, Layout, ref<AdvancedGridLayout>, PyAdvancedGridLayout> advGridLayout( |
66 | m, "AdvancedGridLayout" , D(AdvancedGridLayout)); |
67 | |
68 | advGridLayout |
69 | .def(py::init<const std::vector<int> &, const std::vector<int> &>(), |
70 | py::arg("widths" ), py::arg("heights" ), |
71 | D(AdvancedGridLayout, AdvancedGridLayout)) |
72 | .def("rowCount" , &AdvancedGridLayout::rowCount, D(AdvancedGridLayout, rowCount)) |
73 | .def("colCount" , &AdvancedGridLayout::colCount, D(AdvancedGridLayout, colCount)) |
74 | .def("margin" , &AdvancedGridLayout::margin, D(AdvancedGridLayout, margin)) |
75 | .def("setMargin" , &AdvancedGridLayout::setMargin, D(AdvancedGridLayout, setMargin)) |
76 | .def("appendRow" , &AdvancedGridLayout::appendRow, py::arg("size" ), |
77 | py::arg("stretch" ) = 0, D(AdvancedGridLayout, appendRow)) |
78 | .def("appendCol" , &AdvancedGridLayout::appendCol, py::arg("size" ), |
79 | py::arg("stretch" ) = 0, D(AdvancedGridLayout, appendCol)) |
80 | .def("setRowStretch" , &AdvancedGridLayout::setRowStretch, D(AdvancedGridLayout, setRowStretch)) |
81 | .def("setColStretch" , &AdvancedGridLayout::setColStretch, D(AdvancedGridLayout, setColStretch)) |
82 | .def("setAnchor" , &AdvancedGridLayout::setAnchor, D(AdvancedGridLayout, setAnchor)) |
83 | .def("anchor" , &AdvancedGridLayout::anchor, D(AdvancedGridLayout, anchor)); |
84 | |
85 | py::class_<AdvancedGridLayout::Anchor>(advGridLayout, "Anchor" ) |
86 | .def(py::init<int, int, Alignment, Alignment>(), |
87 | py::arg("x" ), py::arg("y" ), |
88 | py::arg("horiz" ) = Alignment::Fill, |
89 | py::arg("vert" ) = Alignment::Fill, |
90 | D(AdvancedGridLayout, Anchor, Anchor, 2)) |
91 | .def(py::init<int, int, int, int, Alignment, Alignment>(), |
92 | py::arg("x" ), py::arg("y" ), py::arg("w" ), py::arg("h" ), |
93 | py::arg("horiz" ) = Alignment::Fill, |
94 | py::arg("vert" ) = Alignment::Fill, |
95 | D(AdvancedGridLayout, Anchor, Anchor, 3)); |
96 | } |
97 | |
98 | #endif |
99 | |