From 38b6a3cade767cc5ca8fc43daa19d9cb93e6f107 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Sat, 9 Sep 2023 08:49:02 -0400 Subject: [PATCH] UICollection.append, tests are good for Caption and Frame objects created by Python to be drawn by the UITestScene --- src/UI.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/UI.h b/src/UI.h index f32628c..13c97a8 100644 --- a/src/UI.h +++ b/src/UI.h @@ -1032,7 +1032,32 @@ switch (target->derived_type()) \ { // if not UIDrawable subclass, reject it // self->data->push_back( c++ object inside o ); - return NULL; // TODO + + // this would be a great use case for .tp_base + if (!PyObject_IsInstance(o, (PyObject*)&PyUIFrameType) && + //!PyObject_IsInstance(o, (PyObject*)&PyUISpriteType) && + !PyObject_IsInstance(o, (PyObject*)&PyUICaptionType)) + { + PyErr_SetString(PyExc_TypeError, "Only Frame, Caption, Sprite, and Grid objects can be added to UICollection"); + return NULL; + } + + if (PyObject_IsInstance(o, (PyObject*)&PyUIFrameType)) + { + PyUIFrameObject* frame = (PyUIFrameObject*)o; + self->data->push_back(frame->data); + } + if (PyObject_IsInstance(o, (PyObject*)&PyUICaptionType)) + { + PyUICaptionObject* caption = (PyUICaptionObject*)o; + self->data->push_back(caption->data); + } + //if (PyObject_IsInstance(o, (PyObject*)&PyUISpriteType)) + //{ + //} + + Py_INCREF(Py_None); + return Py_None; } static PyObject* PyUICollection_remove(PyUICollectionObject* self, PyObject* o)