15
15
namespace py = pybind11;
16
16
using namespace BPrivate ;
17
17
18
+ /*
19
+ struct text_run {
20
+ int32_t offset;
21
+ BFont font;
22
+ rgb_color color;
23
+ };
24
+
25
+ struct text_run_array {
26
+ int32_t count;
27
+ std::vector<text_run> runs;
28
+ text_run_array(int32_t count) : count(count), runs(count) {}
29
+ };
30
+ */
31
+
18
32
class PyBTextView : public BTextView {
19
33
public:
20
34
using BTextView::BTextView;
@@ -131,6 +145,7 @@ py::class_<text_run_array>(m, "text_run_array")
131
145
.def (py::init<>())
132
146
.def_readwrite (" count" , &text_run_array::count, " " )
133
147
// .def_readonly("runs", &text_run_array::runs, "")
148
+ /* first attempt
134
149
.def_property("runs",[](const text_run_array& self){
135
150
return std::vector<text_run>(self.runs, self.runs + self.text_run_array::count);
136
151
},[](text_run_array& self, const std::vector<text_run>& new_values) {
@@ -139,8 +154,43 @@ py::class_<text_run_array>(m, "text_run_array")
139
154
}
140
155
std::copy(new_values.begin(),new_values.end(),self.runs);
141
156
})
157
+ ;*/
158
+ /*
159
+ .def_property("runs",[](const text_run_array& self){
160
+ return std::vector<text_run>(self.runs, self.runs + self.text_run_array::count);
161
+ },[](text_run_array& self, const std::vector<text_run>& new_values) {
162
+ if (new_values.size() != self.count){
163
+ throw std::runtime_error("Invalid buffer size or dimensions");
164
+ }
165
+ std::memcpy(self.runs, new_values.data(), new_values.size() * sizeof(text_run));
166
+ //std::copy(new_values.begin(),new_values.end(),self.runs);
167
+ })
168
+ ;*/
169
+ .def_property (" runs" ,[](const text_run_array& self){
170
+ return std::vector<text_run>(self.runs , self.runs + self.text_run_array ::count);
171
+ },[](text_run_array& self, const py::list &new_values) {
172
+ std::vector<text_run> newruns;
173
+ for (auto item : new_values) {
174
+ newruns.push_back (item.cast <text_run>());
175
+ }
176
+ std::memcpy (self.runs , newruns.data (), newruns.size () * sizeof (text_run));
177
+ })
142
178
;
143
-
179
+ /* look at this
180
+ /*suggested attempt
181
+ py::class_<text_run_array>(m, "text_run_array")
182
+ .def(py::init<int32_t>(), py::arg("count") = 1)
183
+ .def_readwrite("count", &text_run_array::count)
184
+ .def_property("runs", [](const text_run_array& self) {
185
+ return self.runs;
186
+ },
187
+ [](text_run_array& self, const std::vector<text_run>& new_values) {
188
+ if (new_values.size() != self.count) {
189
+ throw std::runtime_error("Invalid buffer size or dimensions");
190
+ }
191
+ self.runs = new_values;
192
+ })
193
+ ;*/
144
194
/*
145
195
py::class_<text_run_array>(m, "text_run_array")
146
196
.def_readwrite("count", &text_run_array::count, "")
0 commit comments