on xenial help sign in
This gets most of the cards used nowadays in the scopes on the desktop to work

I know there's a few broken variations, and yet have to run the phone to test a carousel

commitb50c0471e647d9245d18c8d4fd7a1d81e1e3f292 authorAlbert Astals <albert.astals@canonical.com> dateWed 30 Apr 2014, 16:27 (12 years ago) parentbe592b2
1 file changed+49−21
plugins/Dash/CardCreator.js+49−21
plugins/Dash/CardCreator.js+49−21
@@ -1,8 +1,7 @@
1−
21.pragma library
32
43/*
5− * Copyright (C) 2013 Canonical, Ltd.
4+ * Copyright (C) 2014 Canonical, Ltd.
65 *
76 * This program is free software; you can redistribute it and/or modify
87 * it under the terms of the GNU General Public License as published by
@@ -46,6 +45,7 @@ function createCardComponent(parent, template, components) {
4645 var hasTitle = components["title"] || false;
4746 var hasMascot = components["mascot"] || false;
4847 var hasSubtitle = components["subtitle"] || false;
48+ var hasHeaderRow = hasMascot && hasTitle;
4949 var mascotImageHeight = 'units.gu(5.625)';
5050
5151 if (hasBackground) {
@@ -210,18 +210,40 @@ function createCardComponent(parent, template, components) {
210210 anchors.topMargin: units.gu(1);';
211211 }
212212 }
213+ var headerLeftAnchor;
214+ if (isHorizontal) {
215+ if (hasArt) {
216+ headerLeftAnchor = 'anchors.left: artShapeHolder.right; \
217+ anchors.leftMargin: units.gu(1);';
218+ } else {
219+ headerLeftAnchor = 'anchors.left: parent.left;';
220+ }
221+ } else {
222+ headerLeftAnchor = 'anchors.left: parent.left; \
223+ anchors.leftMargin: units.gu(1);';
224+ }
225+
226+ if (hasHeaderRow) {
227+ code += 'Row { \
228+ id: row; \
229+ objectName: "outerRow"; \
230+ property real margins: units.gu(1); \
231+ spacing: margins; \
232+ ' + headerVerticalAnchors + '\
233+ ' + headerLeftAnchor + '\
234+ anchors.right: parent.right; \
235+ anchors.margins: margins;';
236+ }
213237
214238 if (hasMascot) {
215239 var useMascotShape = !hasBackground && !inOverlay;
216240 var anchors = "";
217− if (isHorizontal) {
218− anchors += 'anchors.left: artShapeHolder.right; \
219− anchors.leftMargin: units.gu(1);';
241+ if (!hasHeaderRow) {
242+ anchors += headerLeftAnchor;
243+ anchors += headerVerticalAnchors;
220244 } else {
221− anchors += 'anchors.left: parent.left; \
222− anchors.leftMargin: units.gu(1);';
245+ anchors = "anchors.verticalCenter: parent.verticalCenter;"
223246 }
224− anchors += headerVerticalAnchors;
225247
226248 if (useMascotShape) {
227249 code += 'Loader { \
@@ -280,13 +302,10 @@ function createCardComponent(parent, template, components) {
280302 if (hasMascot && hasSubtitle) {
281303 titleAnchors = 'anchors { left: parent.left; right: parent.right }';
282304 subtitleAnchors = titleAnchors;
283− code += 'Item { \
284− ' + anchors + '\
285− height: mascotImage.height; \
286− Column { \
287− anchors.verticalCenter: parent.verticalCenter; \
288− spacing: units.dp(2); \
289− width: parent.width - x;';
305+ code += 'Column { \
306+ anchors.verticalCenter: parent.verticalCenter; \
307+ spacing: units.dp(2); \
308+ width: parent.width - x;';
290309 } else {
291310 titleAnchors = anchors;
292311 subtitleAnchors = 'anchors.left: parent.left; \
@@ -317,24 +336,29 @@ function createCardComponent(parent, template, components) {
317336 ' + subtitleAnchors + '\
318337 elide: Text.ElideRight; \
319338 fontSize: "small"; \
320− wrapMode: Text.Wrap; \
321− maximumLineCount: 2; \
322339 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \
323340 color: ' + color + '; \
324− text: cardData && cardData["subtitle"] || " "; \
341+ visible: titleLabel.text; \
342+ text: cardData && cardData["subtitle"] || ""; \
325343 font.weight: Font.Light; \
326344 horizontalAlignment: root.headerAlignment; \
327345 }';
328346
329− // Close Column and Item
347+ // Close Column
330348 if (hasMascot)
331− code += '} }';
349+ code += '}';
332350 }
333351 }
334352
353+ if (hasHeaderRow) {
354+ // Close Row
355+ code += '}';
356+ }
357+
335358 if (hasSummary) {
336359 var summaryTopAnchor;
337360 if (isHorizontal) summaryTopAnchor = "artShapeHolder.bottom";
361+ else if (hasHeaderRow) summaryTopAnchor = "row.bottom";
338362 else if (hasMascot) summaryTopAnchor = "mascotImage.bottom";
339363 else if (hasSubtitle) summaryTopAnchor = "subtitleLabel.bottom";
340364 else if (hasTitle) summaryTopAnchor = "titleLabel.bottom";
@@ -371,10 +395,14 @@ function createCardComponent(parent, template, components) {
371395 code += 'implicitHeight: summary.y + summary.height + (summary.text && backgroundLoader.active ? units.gu(1) : 0);';
372396 } else if (hasSummary) {
373397 code += 'implicitHeight: summary.y + summary.height;';
398+ } else if (hasHeaderRow) {
399+ code += 'implicitHeight: row.y + row.height + units.gu(1);';
374400 } else if (hasMascot) {
375401 code += 'implicitHeight: mascotImage.y + mascotImage.height;';
402+ } else if (hasSubtitle) {
403+ code += 'implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);';
376404 } else if (hasTitle) {
377− code += 'implicitHeight: titleLabel.y + titleLabel.height;';
405+ code += 'implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);';
378406 }
379407 code += '}';
380408