[Qt-qml] Advanced layout support
jan-arve.saether at nokia.com
jan-arve.saether at nokia.com
Thu Oct 20 11:59:00 CEST 2011
ext jens.bache-wiig at nokia.com wrote on 2011-10-19:
> I don't neccessarily disagree, as having it built into the language
> seems like the obvious solution. But I don't think it is _that_ clear
> cut: - If we do not support those constraints it for anchors, but give
> items properties like minimum/maximumWidth, it would just add to the
> confusion. - Adding constraints could have a significant performance
> penalty for low end hardware. Hopefully this would be negligible if you
> don't make use of them. - Giving anchors hard constraints can impact how
> easy it is to animate certain things. Making layouts explicit makes it
> easier to determine when you are giving away control over positioning. -
> Giving anchors constraints makes them unpredictable. Who wins when you
> have conflicting min/max sizes? The largest item? Most likely by random?
> Again, I somewhat like the distinction that anchors are somewhat more
> rigid/harder and wins over layouts every time.
As long as all anchors in QML are directional (it simply uses the property
propagation system), it does not make sense to add min/max sizes. Think about how you can make an item stretch in Qt Quick anchor layout: Two independent propagation paths must meet one item (e.g. one stops on the left edge, the other stops on the right edge). This does not allow distribution of available space to different items. (it's rather all remaining space gets allocated to the item in "the middle")
This would most likely mean that we'd need a different syntax (\see VisualFormatLanguage below) for anchors if we want to have proper distribution, and each anchor should not be directed.
>
> But I just noticed (and excuse me if it is well known) But there are
> actually two existing complete layout examples for GridLayout and
> LinearLayout that ships with Qt 4.7 already.
>
> They both seem to favor the LayoutItem approach:
>
> http://doc.qt.nokia.com/4.7-snapshot/declarative-cppextensions-
> qgraphicslayouts-qgraphicsgridlayout-qgraphicsgridlayout-qml.html
> http://doc.qt.nokia.com/4.7-snapshot/declarative-cppextensions-
> qgraphicslayouts-qgraphicslinearlayout-qgraphicslinearlayout-qml.html
>
I think they favor the LayoutItem approach because they make use of QGraphicsLayout.
(i.e. there is no alternative unless they want to pull off the layouting themselves)
regards,
Jan-Arve
/*! VisualFormatLanguage
Since we're entering this alley... I find the "Visual Format Language" of Cocoa Autolayout
http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AutolayoutPG/Articles/formatLanguage.html#//apple_ref/doc/uid/TP40010853-CH3-SW1
interesting in that respect. It allows me to specify anchors and constraints on each item, but the anchors and constraints are passed on to the layout (so there is no need for storing the constraints on the items themselves, this is in fact an implementation detail)
To give a small example (from developer.apple.com):
|-[find]-[findNext]-[findField(>=20)]-|
Would do:
* Anchor the left edge of the item named "find" to the left of the parent.
* Anchor right edge of "find" to the left edge of "findNext"
* etc...
* The findField item has an additional constraint where its minimumSize is 20.
* All items will have a default spacing
Since Cocoa Autolayout is *very* similar to QGraphicsAnchorLayout, I have wanted to try to make a similar "language" for QGAL. This could then be used in Qt Quick. Unfortunately I haven't had the time yet (sometimes I wish I could clone myself). It should be quite easy to implement, since it's a very simple language.
*/
More information about the Qt-qml
mailing list