feat: implement name system for finding UI elements (#39/40/41)
- Add 'name' property to UIDrawable base class - All UI elements (Frame, Caption, Sprite, Grid, Entity) support .name - Entity delegates name to its sprite member - Add find(name, scene=None) function for exact match search - Add findAll(pattern, scene=None) with wildcard support (* matches any sequence) - Both functions search recursively through Frame children and Grid entities - Comprehensive test coverage for all functionality This provides a simple way to find UI elements by name in Python scripts, supporting both exact matches and wildcard patterns. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
97067a104e
commit
edfe3ba184
13 changed files with 557 additions and 6 deletions
|
|
@ -45,4 +45,31 @@ static int UIEntity_set_opacity(PyUIEntityObject* self, PyObject* value, void* c
|
|||
|
||||
self->data->sprite.opacity = opacity;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Name property - delegate to sprite
|
||||
static PyObject* UIEntity_get_name(PyUIEntityObject* self, void* closure)
|
||||
{
|
||||
return PyUnicode_FromString(self->data->sprite.name.c_str());
|
||||
}
|
||||
|
||||
static int UIEntity_set_name(PyUIEntityObject* self, PyObject* value, void* closure)
|
||||
{
|
||||
if (value == NULL || value == Py_None) {
|
||||
self->data->sprite.name = "";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!PyUnicode_Check(value)) {
|
||||
PyErr_SetString(PyExc_TypeError, "name must be a string");
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* name_str = PyUnicode_AsUTF8(value);
|
||||
if (!name_str) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
self->data->sprite.name = name_str;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue