on xenial help sign in
Improve Card and CardHeader layouts:

- anchor summary to art when no header - don't indent header when no mascot - reduce header and summary font sizes and weights - increase art shape radius

commit9d03f198681e9cfde646d784214afa749cc070ed authorMichał Sawicz <michal.sawicz@canonical.com> dateTue 4 Feb 2014, 14:08 (13 years ago) parentc3398069f3468c
4 files changed+42−12
qml/Dash/Card.qml+3−1 qml/Dash/CardHeader.qml+14−3 tests/qmltests/Dash/tst_Card.qml+22−5 tests/qmltests/Dash/tst_CardHeader.qml+3−3
qml/Dash/Card.qml+3−1
@@ -37,6 +37,7 @@ Item {
3737
3838 UbuntuShape {
3939 id: artShape
40+ radius: "medium"
4041 objectName: "artShape"
4142 width: {
4243 if (!visible) return 0
@@ -82,11 +83,12 @@ Item {
8283
8384 Label {
8485 objectName: "summaryLabel"
85− anchors { top: header.bottom; left: parent.left; right: parent.right }
86+ anchors { top: header.visible ? header.bottom : artShape.bottom; left: parent.left; right: parent.right }
8687 wrapMode: Text.Wrap
8788 maximumLineCount: 5
8889 elide: Text.ElideRight
8990 text: cardData && cardData["summary"] || ""
9091 height: text ? implicitHeight : 0
92+ fontSize: "small"
9193 }
9294}
qml/Dash/CardHeader.qml+14−3
@@ -27,14 +27,21 @@ Item {
2727 property alias altPrice: altPriceLabel.text
2828
2929 visible: mascotImage.status === Image.Ready || title || price
30− height: row.height > 0 ? row.height + row.spacing * 2 : 0
30+ height: row.height > 0 ? row.height + row.margins * 2 : 0
3131
3232 Row {
3333 id: row
3434 objectName: "outerRow"
3535
36− anchors { top: parent.top; left: parent.left; right: parent.right; margins: spacing }
37− spacing: units.gu(1)
36+ property real margins: units.gu(1)
37+
38+ anchors {
39+ top: parent.top; left: parent.left; right: parent.right
40+ margins: margins
41+ leftMargin: spacing
42+ rightMargin: spacing
43+ }
44+ spacing: mascotShape.visible ? margins : 0
3845
3946 UbuntuShape {
4047 id: mascotShape
@@ -59,6 +66,7 @@ Item {
5966 Column {
6067 objectName: "column"
6168 width: parent.width - x
69+ spacing: units.gu(0.5)
6270
6371 Label {
6472 id: titleLabel
@@ -68,6 +76,7 @@ Item {
6876 font.weight: Font.DemiBold
6977 wrapMode: Text.Wrap
7078 maximumLineCount: 2
79+ fontSize: "small"
7180 }
7281
7382 Label {
@@ -75,7 +84,9 @@ Item {
7584 objectName: "subtitleLabel"
7685 anchors { left: parent.left; right: parent.right }
7786 elide: Text.ElideRight
87+ font.weight: Font.Light
7888 visible: titleLabel.text && text
89+ fontSize: "x-small"
7990 }
8091
8192 Row {
tests/qmltests/Dash/tst_Card.qml+22−5
@@ -110,6 +110,10 @@ Rectangle {
110110 "name": "Art, header - vertical",
111111 "layout": { "components": Helpers.update(JSON.parse(root.fullMapping), { "summary": undefined }) }
112112 },
113+ {
114+ "name": "Art, summary - vertical",
115+ "layout": { "components": { "art": "art", "summary": "summary" } }
116+ },
113117 {
114118 "name": "Header title only - horizontal",
115119 "layout": { "template": { "card-layout": "horizontal" },
@@ -356,13 +360,26 @@ Rectangle {
356360 tryCompareFunction(function() { return testCase.header.x === data.left() }, true);
357361 }
358362
363+ function test_summary_layout_data() {
364+ return [
365+ { tag: "With header", top: function() { return header.y + header.height }, index: 0 },
366+ { tag: "Without header", top: function() { return art.y + art.height }, index: 7 },
367+ ]
368+ }
369+
370+ function test_summary_layout(data) {
371+ selector.selectedIndex = data.index;
372+
373+ tryCompareFunction(function() { return testCase.summary.y === data.top() }, true);
374+ }
375+
359376 function test_art_visibility() {
360− selector.selectedIndex = 7
377+ selector.selectedIndex = 8;
361378
362− tryCompare(testCase.artImage, "source", "")
363− compare(testCase.art.visible, false)
364− compare(testCase.art.height, 0)
365− compare(testCase.art.width, 0)
379+ tryCompare(testCase.artImage, "source", "");
380+ compare(testCase.art.visible, false);
381+ compare(testCase.art.height, 0);
382+ compare(testCase.art.width, 0);
366383 }
367384 }
368385}
tests/qmltests/Dash/tst_CardHeader.qml+3−3
@@ -120,9 +120,9 @@ Rectangle {
120120
121121 function test_dimensions_data() {
122122 return [
123− { tag: "Column width", object: column, width: cardHeader.width - testCase.outerRow.spacing * 2 },
124− { tag: "Column width", object: column, width: cardHeader.width - mascot.width - testCase.outerRow.spacing * 3, mascot: "artwork/avatar.png" },
125− { tag: "Header height", object: cardHeader, height: function() { return subtitleLabel.y + subtitleLabel.height + outerRow.spacing * 2 } },
123+ { tag: "Column width", object: column, width: cardHeader.width },
124+ { tag: "Column width with mascot", object: column, width: cardHeader.width - mascot.width - outerRow.margins * 3, mascot: "artwork/avatar.png" },
125+ { tag: "Header height", object: cardHeader, height: function() { return subtitleLabel.y + subtitleLabel.height + outerRow.margins * 2 } },
126126 ]
127127 }
128128