Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
UI anchors – third version
-
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
ui.View
update
method 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
update
method 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 withimport anchors
.