on xenial help sign in
Small fixes:

Make the comment be doc Make tryResponsiveVerticalJournal actually change width with window width changes

commit952e11ac9d89baffa7189f0f934e8258f803be26 authorAlbert Astals <albert.astals@canonical.com> dateTue 17 Jun 2014, 17:42 (12 years ago) parent231420c
2 files changed+26−31
qml/Components/ResponsiveVerticalJournal.qml+24−29 tests/qmltests/Components/tst_ResponsiveVerticalJournal.qml+2−2
qml/Components/ResponsiveVerticalJournal.qml+24−29
@@ -19,23 +19,26 @@ import Ubuntu.Components 0.1
1919import "../Components"
2020import Dash 0.1
2121
22−// A VerticalJournal. Based on defined column width,
23−// delegates are layouted in columns following
24−// a top-left most position rule.
25−//
26−// Example:
27−//
28−// +-----+ +-----+ +-----+
29−// | | | 2 | | |
30−// | | | | | |
31−// | 1 | +-----+ | 3 |
32−// | | +-----+ | |
33−// | | | | +-----+
34−// +-----+ | 4 | +-----+
35−// +-----+ | | | 5 |
36−// | 6 | +-----+ | |
37−// | | +-----+
38−// +-----+
22+/*!
23+ \brief A responsive wrapper around VerticalJournal.
24+
25+ Based on defined column width, delegates are laid out in columns following
26+ a top-left most position rule.
27+
28+ Example:
29+
30+ +-----+ +-----+ +-----+
31+ | | | 2 | | |
32+ | | | | | |
33+ | 1 | +-----+ | 3 |
34+ | | +-----+ | |
35+ | | | | +-----+
36+ +-----+ | 4 | +-----+
37+ +-----+ | | | 5 |
38+ | 6 | +-----+ | |
39+ | | +-----+
40+ +-----+
41+*/
3942Item {
4043 property int minimumColumnSpacing: units.gu(1)
4144
@@ -63,18 +66,10 @@ Item {
6366 return Math.floor(pixels / units.gu(1))
6467 }
6568
66− function columnsForSpacing(spacing) {
67− // parent.width = columns * columnWidth +
68− // (columns-1) * spacing + spacing(margins)
69− return Math.max(1, Math.floor(parent.width / (columnWidth + spacing)))
69+ columnSpacing: {
70+ // parent.width = columns * columnWidth + (columns-1) * spacing + spacing(margins)
71+ var expectedColumns = Math.max(1, Math.floor(parent.width / (columnWidth + minimumColumnSpacing)));
72+ Math.floor((parent.width - expectedColumns * columnWidth) / expectedColumns);
7073 }
71−
72− function spacingForColumns(columns) {
73− var spacingGU = px2gu((parent.width - columns * columnWidth) / columns)
74− return units.gu(spacingGU)
75− }
76−
77− readonly property int expectedColumns: columnsForSpacing(minimumColumnSpacing)
78− columnSpacing: spacingForColumns(expectedColumns)
7974 }
8075}
tests/qmltests/Components/tst_ResponsiveVerticalJournal.qml+2−2
@@ -24,7 +24,7 @@ import Utils 0.1
2424import Unity.Test 0.1 as UT
2525
2626Item {
27− width: journalRect.width + controls.width
27+ width: units.gu(80) + controls.width
2828 height: units.gu(80)
2929
3030 Column {
@@ -86,11 +86,11 @@ Item {
8686
8787 Rectangle {
8888 id: journalRect
89− width: units.gu(80)
9089 height: parent.height
9190 color: "grey"
9291 anchors.top: parent.top
9392 anchors.left: parent.left
93+ anchors.right: controls.left
9494
9595 ResponsiveVerticalJournal {
9696 id: journal