summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 23:05:34 -0400
committerNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 23:05:34 -0400
commit0245a81fc04cf787bae2f3467f850a07d9791ca7 (patch)
tree04c78a36d7b40656054fa51ec9487387273b9531
parent95a815b6d63b57f46a72be25b9723366f4af76bd (diff)
downloadsnap-0245a81fc04cf787bae2f3467f850a07d9791ca7.tar.gz
snap-0245a81fc04cf787bae2f3467f850a07d9791ca7.zip
Optimize loading projects a bit more
-rw-r--r--blocks.js63
-rw-r--r--morphic.js6
2 files changed, 36 insertions, 33 deletions
diff --git a/blocks.js b/blocks.js
index 6c10354..8aad311 100644
--- a/blocks.js
+++ b/blocks.js
@@ -1421,16 +1421,19 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
new Point() : this.embossing;
part.drawNew();
} else {
- part = new StringMorph(spec);
- part.fontName = this.labelFontName;
- part.fontStyle = this.labelFontStyle;
- part.fontSize = this.fontSize;
- part.color = new Color(255, 255, 255);
- part.isBold = true;
- part.shadowColor = this.color.darker(this.labelContrast);
- part.shadowOffset = MorphicPreferences.isFlat ?
- new Point() : this.embossing;
- part.drawNew();
+ part = new StringMorph(
+ spec, // text
+ this.fontSize, // fontSize
+ this.labelFontStyle, // fontStyle
+ true, // bold
+ false, // italic
+ false, // isNumeric
+ MorphicPreferences.isFlat ?
+ new Point() : this.embossing, // shadowOffset
+ this.color.darker(this.labelContrast), // shadowColor
+ new Color(255, 255, 255), // color
+ this.labelFontName // fontName
+ );
}
return part;
};
@@ -6918,7 +6921,8 @@ InputSlotMorph.prototype.setChoices = function (dict, readonly) {
// InputSlotMorph layout:
InputSlotMorph.prototype.fixLayout = function () {
- var contents = this.contents(),
+ var width, height, arrowWidth,
+ contents = this.contents(),
arrow = this.arrow();
contents.isNumeric = this.isNumeric;
@@ -6935,32 +6939,29 @@ InputSlotMorph.prototype.fixLayout = function () {
arrow.setSize(this.fontSize);
arrow.show();
} else {
- arrow.setSize(0);
arrow.hide();
}
- this.setHeight(
- contents.height()
- + this.edge * 2
- // + this.typeInPadding * 2
- );
+ arrowWidth = arrow.isVisible ? arrow.width() : 0;
+
+ height = contents.height() + this.edge * 2; // + this.typeInPadding * 2
if (this.isNumeric) {
- this.setWidth(contents.width()
- + Math.floor(arrow.width() * 0.5)
+ width = contents.width()
+ + Math.floor(arrowWidth * 0.5)
+ this.height()
- + this.typeInPadding * 2
- );
+ + this.typeInPadding * 2;
} else {
- this.setWidth(Math.max(
+ width = Math.max(
contents.width()
- + arrow.width()
+ + arrowWidth
+ this.edge * 2
+ this.typeInPadding * 2,
contents.rawHeight ? // single vs. multi-line contents
- contents.rawHeight() + arrow.width()
- : contents.height() / 1.2 + arrow.width(),
+ contents.rawHeight() + arrowWidth
+ : contents.height() / 1.2 + arrowWidth,
this.minWidth // for text-type slots
- ));
+ );
}
+ this.setExtent(new Point(width, height));
if (this.isNumeric) {
contents.setPosition(new Point(
Math.floor(this.height() / 2),
@@ -6973,10 +6974,12 @@ InputSlotMorph.prototype.fixLayout = function () {
).add(new Point(this.typeInPadding, 0)).add(this.position()));
}
- arrow.setPosition(new Point(
- this.right() - arrow.width() - this.edge,
- contents.top()
- ));
+ if (arrow.isVisible) {
+ arrow.setPosition(new Point(
+ this.right() - arrowWidth - this.edge,
+ contents.top()
+ ));
+ }
if (this.parent) {
if (this.parent.fixLayout) {
diff --git a/morphic.js b/morphic.js
index 0b20eb5..1552d78 100644
--- a/morphic.js
+++ b/morphic.js
@@ -2199,7 +2199,7 @@ function Morph() {
// Morph initialization:
-Morph.prototype.init = function () {
+Morph.prototype.init = function (noDraw) {
Morph.uber.init.call(this);
this.isMorph = true;
this.bounds = new Rectangle(0, 0, 50, 40);
@@ -2212,7 +2212,7 @@ Morph.prototype.init = function () {
this.isTemplate = false;
this.acceptsDrops = false;
this.noticesTransparentClick = false;
- this.drawNew();
+ if (!noDraw) this.drawNew();
this.fps = 0;
this.customContextMenu = null;
this.lastTime = Date.now();
@@ -6999,7 +6999,7 @@ StringMorph.prototype.init = function (
this.markedBackgoundColor = new Color(60, 60, 120);
// initialize inherited properties:
- StringMorph.uber.init.call(this);
+ StringMorph.uber.init.call(this, true);
// override inherited properites:
this.color = color || new Color(0, 0, 0);