Alignment: reactive or automatically calculated repositioning of UIDrawables on their parent
This commit is contained in:
parent
73230989ad
commit
4bf590749c
23 changed files with 1350 additions and 397 deletions
|
|
@ -500,6 +500,30 @@ PyGetSetDef PySceneClass::getsetters[] = {
|
|||
{NULL}
|
||||
};
|
||||
|
||||
// Scene.realign() - recalculate alignment for all children
|
||||
static PyObject* PySceneClass_realign(PySceneObject* self, PyObject* args)
|
||||
{
|
||||
GameEngine* game = McRFPy_API::game;
|
||||
if (!game) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "No game engine");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
auto scene = game->getScene(self->name);
|
||||
if (!scene || !scene->ui_elements) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
// Iterate through all UI elements and realign those with alignment set
|
||||
for (auto& drawable : *scene->ui_elements) {
|
||||
if (drawable && drawable->align_type != AlignmentType::NONE) {
|
||||
drawable->applyAlignment();
|
||||
}
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
// Methods
|
||||
PyMethodDef PySceneClass::methods[] = {
|
||||
{"activate", (PyCFunction)activate, METH_VARARGS | METH_KEYWORDS,
|
||||
|
|
@ -521,6 +545,13 @@ PyMethodDef PySceneClass::methods[] = {
|
|||
MCRF_RETURNS("None")
|
||||
MCRF_NOTE("Alternative to setting on_key property. Handler is called for both key press and release events.")
|
||||
)},
|
||||
{"realign", (PyCFunction)PySceneClass_realign, METH_NOARGS,
|
||||
MCRF_METHOD(SceneClass, realign,
|
||||
MCRF_SIG("()", "None"),
|
||||
MCRF_DESC("Recalculate alignment for all children with alignment set."),
|
||||
MCRF_NOTE("Call this after window resize or when game_resolution changes. "
|
||||
"For responsive layouts, connect this to on_resize callback.")
|
||||
)},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue