Folding labeled box positioning into rendering
This commit is contained in:
parent
b9f1cfae55
commit
407167a4ae
@ -120,35 +120,36 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
renderLabeledBox(label) {
|
renderLabeledBox(label, content, options) {
|
||||||
this.label = this.container.text()
|
var deferred = Q.defer(),
|
||||||
|
label = this.container.text()
|
||||||
.addClass([this.type, 'label'].join('-'))
|
.addClass([this.type, 'label'].join('-'))
|
||||||
.attr({
|
.attr({
|
||||||
text: label
|
text: label
|
||||||
});
|
}),
|
||||||
|
box = this.container.rect()
|
||||||
this.box = this.container.rect()
|
|
||||||
.addClass([this.type, 'box'].join('-'))
|
.addClass([this.type, 'box'].join('-'))
|
||||||
.attr({
|
.attr({
|
||||||
rx: 3,
|
rx: 3,
|
||||||
ry: 3
|
ry: 3
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
positionLabeledBox(content, options) {
|
|
||||||
var labelBox, contentBox;
|
|
||||||
|
|
||||||
_.defaults(options, {
|
_.defaults(options, {
|
||||||
padding: 0
|
padding: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
labelBox = this.label.getBBox();
|
this.container.prepend(label);
|
||||||
|
this.container.prepend(box);
|
||||||
|
|
||||||
|
setTimeout(deferred.resolve);
|
||||||
|
deferred.promise.then(() => {
|
||||||
|
var labelBox = label.getBBox(),
|
||||||
contentBox = content.getBBox();
|
contentBox = content.getBBox();
|
||||||
|
|
||||||
this.label.transform(Snap.matrix()
|
label.transform(Snap.matrix()
|
||||||
.translate(0, labelBox.height));
|
.translate(0, labelBox.height));
|
||||||
|
|
||||||
this.box
|
box
|
||||||
.transform(Snap.matrix()
|
.transform(Snap.matrix()
|
||||||
.translate(0, labelBox.height))
|
.translate(0, labelBox.height))
|
||||||
.attr({
|
.attr({
|
||||||
@ -157,6 +158,9 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
content.transform(Snap.matrix()
|
content.transform(Snap.matrix()
|
||||||
.translate(this.box.getBBox().cx - contentBox.cx, labelBox.height + options.padding));
|
.translate(box.getBBox().cx - contentBox.cx, labelBox.height + options.padding));
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -6,11 +6,7 @@ export default _.extend({}, Base, {
|
|||||||
type: 'charset',
|
type: 'charset',
|
||||||
|
|
||||||
_render() {
|
_render() {
|
||||||
var partContainer;
|
var partContainer = this.container.group();
|
||||||
|
|
||||||
this.renderLabeledBox(this.invert() ? 'None of:' : 'One of:');
|
|
||||||
|
|
||||||
partContainer = this.container.group();
|
|
||||||
|
|
||||||
return Q.all(_.map(this.parts.elements, part => {
|
return Q.all(_.map(this.parts.elements, part => {
|
||||||
return part.render(partContainer.group());
|
return part.render(partContainer.group());
|
||||||
@ -20,7 +16,7 @@ export default _.extend({}, Base, {
|
|||||||
padding: 5
|
padding: 5
|
||||||
});
|
});
|
||||||
|
|
||||||
this.positionLabeledBox(partContainer, {
|
return this.renderLabeledBox(this.invert() ? 'None of:' : 'One of:', partContainer, {
|
||||||
padding: 5
|
padding: 5
|
||||||
});
|
});
|
||||||
}).bind(this));
|
}).bind(this));
|
||||||
|
@ -16,14 +16,10 @@ export default _.extend({}, Base, {
|
|||||||
var label = this.groupLabel();
|
var label = this.groupLabel();
|
||||||
|
|
||||||
if (label) {
|
if (label) {
|
||||||
this.renderLabeledBox(label);
|
|
||||||
|
|
||||||
return this.regexp.render(this.container.group())
|
return this.regexp.render(this.container.group())
|
||||||
.then((() => {
|
.then(this.renderLabeledBox.bind(this, label, this.regexp, {
|
||||||
this.positionLabeledBox(this.regexp, {
|
|
||||||
padding: 10
|
padding: 10
|
||||||
});
|
}));
|
||||||
}).bind(this));
|
|
||||||
} else {
|
} else {
|
||||||
return this.proxy(this.regexp);
|
return this.proxy(this.regexp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user