on xenial help sign in
Moving towards unique container
43115d6Andrea Cimitan
plugins/Dash/CardCreator.js+15−29
@@ -181,37 +181,23 @@ var kHeaderRow3Code = 'Row { \n\
181 ] \n\
181 ] \n\
182 }\n';
182 }\n';
183
183
184−// %1 is used as anchors
184+// multiple column version of kHeaderContainerCode.
185−// %2 is used as height of the container
185+function kHeaderContainerCodeGenerator() {
186−// %3 is used as first child of the container
186+ var headerContainerCodeTemplate = 'Item { \n\
187−// %4 is used as second child of the container
188−var kHeader2ContainerCode = 'Item { \n\
189 id: headerTitleContainer; \n\
187 id: headerTitleContainer; \n\
190 anchors { %1 } \n\
188 anchors { %1 } \n\
191 width: parent.width - x; \n\
189 width: parent.width - x; \n\
192 implicitHeight: %2; \n\
190 implicitHeight: %2; \n\
193− data: [ %3\n\
191+ data: [ \n\
194− ,\n\
192+ %3 \n\
195− %4 \n\
196− ] \n\
197− }\n';
198−
199−// %1 is used as anchors
200−// %2 is used as first child of the container
201−// %3 is used as second child of the container
202−// %4 is used as third child of the container
203−var kHeader3ContainerCode = 'Item { \n\
204− id: headerTitleContainer; \n\
205− anchors { %1 } \n\
206− width: parent.width - x; \n\
207− implicitHeight: titleLabel.height + subtitleLabel.height; \n\
208− data: [ %2\n\
209− ,\n\
210− %3 \n\
211− ,\n\
212− %4 \n\
213− ] \n\
193+ ]\n\
214 }\n';
194 }\n';
195+ var args = Array.prototype.slice.call(arguments);
196+ var anchors = args.shift();
197+ var height = args.shift();
198+ var code = headerContainerCodeTemplate.arg(anchors).arg(height).arg(args.join(',\n'));
199+ return code;
200+}
215
201
216// %1 is used as anchors of mascotShapeLoader
202// %1 is used as anchors of mascotShapeLoader
217var kMascotShapeLoaderCode = 'Loader { \n\
203var kMascotShapeLoaderCode = 'Loader { \n\
@@ -545,13 +531,13 @@ function cardString(template, components) {
545 }
531 }
546 if (hasEmblem && hasSubtitle) {
532 if (hasEmblem && hasSubtitle) {
547 // using container 3
533 // using container 3
548− titleSubtitleCode = kHeader3ContainerCode.arg(titleContainerAnchors).arg(titleCode).arg(emblemCode).arg(kSubtitleLabelCode.arg(subtitleAnchors).arg(color));
534+ titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, 'titleLabel.height + subtitleLabel.height', titleCode, emblemCode, kSubtitleLabelCode.arg(subtitleAnchors).arg(color));
549 } else if (hasEmblem) {
535 } else if (hasEmblem) {
550 // container with emblem
536 // container with emblem
551− titleSubtitleCode = kHeader2ContainerCode.arg(titleContainerAnchors).arg('titleLabel.height').arg(titleCode).arg(emblemCode);
537+ titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, 'titleLabel.height', titleCode, emblemCode);
552 } else if (hasMascot && hasSubtitle) {
538 } else if (hasMascot && hasSubtitle) {
553 // container with subtitle
539 // container with subtitle
554− titleSubtitleCode = kHeader2ContainerCode.arg(titleContainerAnchors).arg('titleLabel.height + subtitleLabel.height').arg(titleCode).arg(subtitleCode);
540+ titleSubtitleCode = kHeaderContainerCodeGenerator(titleContainerAnchors, 'titleLabel.height + subtitleLabel.height', titleCode, subtitleCode);
555 } else {
541 } else {
556 // no container
542 // no container
557 titleSubtitleCode = titleCode + subtitleCode;
543 titleSubtitleCode = titleCode + subtitleCode;