UI anchors – third version
mikael last edited by
Why another version?
First version of UI constraints for Pythonista was created as a wrapper around Apple NSLayoutConstraint class. While functional, it suffered from the same restrictions as the underlying Apple class, and was somewhat inconvenient to develop with, due to the "either frames or constraints" mindset and some mystical crashes.
Second version was built on top of the scripter, utilizing the
updatemethod that gets called several times a second. Constraints could now be designed freely, and this version acted as an excellent proof of concept. There was the obvious performance concern due to the constraints being checked constantly, even if nothing was happening in the UI – easily few thousand small checks per second for a realistic UI.
This third version replaces the
updatemethod with the KVO (Key Value Observing) protocol, running the constraint checks only when the position or the frame of the view changes. Thus we avoid the performance overhead while retaining the freedom of custom constraints.
The API is largely the same as the previous version, with some rationalization of parameter order and the addition of support for constants and functions.
Easy install in stash:
pip install pythonista-anchors. Use with