kopia lustrzana https://github.com/backface/turtlestitch
Blocks: Multi-line input slots (TextSlotMorphs - %mlt)
rodzic
ff75d76472
commit
26475fc0aa
90
blocks.js
90
blocks.js
|
@ -55,6 +55,7 @@
|
||||||
ReporterSlotMorph
|
ReporterSlotMorph
|
||||||
RingReporterSlotMorph
|
RingReporterSlotMorph
|
||||||
InputSlotMorph
|
InputSlotMorph
|
||||||
|
TextSlotMorph
|
||||||
MultiArgMorph
|
MultiArgMorph
|
||||||
TemplateSlotMorph
|
TemplateSlotMorph
|
||||||
BlockMorph
|
BlockMorph
|
||||||
|
@ -87,6 +88,7 @@
|
||||||
InputSlotMorph
|
InputSlotMorph
|
||||||
BooleanSlotMorph
|
BooleanSlotMorph
|
||||||
ArrowMorph
|
ArrowMorph
|
||||||
|
TextSlotMorph
|
||||||
SymbolMorph
|
SymbolMorph
|
||||||
ColorSlotMorph
|
ColorSlotMorph
|
||||||
TemplateSlotMorph
|
TemplateSlotMorph
|
||||||
|
@ -179,6 +181,7 @@ var RingReporterSlotMorph;
|
||||||
var SymbolMorph;
|
var SymbolMorph;
|
||||||
var CommentMorph;
|
var CommentMorph;
|
||||||
var ArgLabelMorph;
|
var ArgLabelMorph;
|
||||||
|
var TextSlotMorph;
|
||||||
|
|
||||||
WorldMorph.prototype.customMorphs = function () {
|
WorldMorph.prototype.customMorphs = function () {
|
||||||
// add examples to the world's demo menu
|
// add examples to the world's demo menu
|
||||||
|
@ -721,6 +724,10 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
|
||||||
part.minWidth = part.height() * 1.7; // "landscape"
|
part.minWidth = part.height() * 1.7; // "landscape"
|
||||||
part.fixLayout();
|
part.fixLayout();
|
||||||
break;
|
break;
|
||||||
|
case '%mlt':
|
||||||
|
part = new TextSlotMorph();
|
||||||
|
part.fixLayout();
|
||||||
|
break;
|
||||||
case '%obj':
|
case '%obj':
|
||||||
part = new ArgMorph('object');
|
part = new ArgMorph('object');
|
||||||
break;
|
break;
|
||||||
|
@ -1590,6 +1597,7 @@ SyntaxElementMorph.prototype.endLayout = function () {
|
||||||
%br - user-forced line break
|
%br - user-forced line break
|
||||||
%s - white rectangular type-in slot ("string-type")
|
%s - white rectangular type-in slot ("string-type")
|
||||||
%txt - white rectangular type-in slot ("text-type")
|
%txt - white rectangular type-in slot ("text-type")
|
||||||
|
%mlt - white rectangular type-in slot ("multi-line-text-type")
|
||||||
%n - white roundish type-in slot ("numerical")
|
%n - white roundish type-in slot ("numerical")
|
||||||
%dir - white roundish type-in slot with drop-down for directions
|
%dir - white roundish type-in slot with drop-down for directions
|
||||||
%inst - white roundish type-in slot with drop-down for instruments
|
%inst - white roundish type-in slot with drop-down for instruments
|
||||||
|
@ -6224,7 +6232,9 @@ InputSlotMorph.prototype.fixLayout = function () {
|
||||||
+ arrow.width()
|
+ arrow.width()
|
||||||
+ this.edge * 2
|
+ this.edge * 2
|
||||||
+ this.typeInPadding * 2,
|
+ this.typeInPadding * 2,
|
||||||
contents.rawHeight() + arrow.width(),
|
contents.rawHeight ? // single vs. multi-line contents
|
||||||
|
contents.rawHeight() + arrow.width()
|
||||||
|
: contents.height() / 1.2 + arrow.width(),
|
||||||
this.minWidth // for text-type slots
|
this.minWidth // for text-type slots
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -6969,6 +6979,84 @@ ArrowMorph.prototype.drawNew = function () {
|
||||||
context.fill();
|
context.fill();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TextSlotMorph //////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/*
|
||||||
|
I am a multi-line input slot, primarily used in Snap's code-mapping
|
||||||
|
blocks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// TextSlotMorph inherits from InputSlotMorph:
|
||||||
|
|
||||||
|
TextSlotMorph.prototype = new InputSlotMorph();
|
||||||
|
TextSlotMorph.prototype.constructor = TextSlotMorph;
|
||||||
|
TextSlotMorph.uber = InputSlotMorph.prototype;
|
||||||
|
|
||||||
|
// TextSlotMorph instance creation:
|
||||||
|
|
||||||
|
function TextSlotMorph(text, isNumeric, choiceDict, isReadOnly) {
|
||||||
|
this.init(text, isNumeric, choiceDict, isReadOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextSlotMorph.prototype.init = function (
|
||||||
|
text,
|
||||||
|
isNumeric,
|
||||||
|
choiceDict,
|
||||||
|
isReadOnly
|
||||||
|
) {
|
||||||
|
var contents = new TextMorph(''),
|
||||||
|
arrow = new ArrowMorph(
|
||||||
|
'down',
|
||||||
|
0,
|
||||||
|
Math.max(Math.floor(this.fontSize / 6), 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
contents.fontSize = this.fontSize;
|
||||||
|
contents.drawNew();
|
||||||
|
|
||||||
|
this.isUnevaluated = false;
|
||||||
|
this.choices = choiceDict || null; // object, function or selector
|
||||||
|
this.oldContentsExtent = contents.extent();
|
||||||
|
this.isNumeric = isNumeric || false;
|
||||||
|
this.isReadOnly = isReadOnly || false;
|
||||||
|
this.minWidth = 0; // can be chaged for text-type inputs ("landscape")
|
||||||
|
this.constant = null;
|
||||||
|
|
||||||
|
InputSlotMorph.uber.init.call(this);
|
||||||
|
this.color = new Color(255, 255, 255);
|
||||||
|
this.add(contents);
|
||||||
|
this.add(arrow);
|
||||||
|
contents.isEditable = true;
|
||||||
|
contents.isDraggable = false;
|
||||||
|
contents.enableSelecting();
|
||||||
|
this.setContents(text);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// TextSlotMorph accessing:
|
||||||
|
|
||||||
|
TextSlotMorph.prototype.getSpec = function () {
|
||||||
|
if (this.isNumeric) {
|
||||||
|
return '%mln';
|
||||||
|
}
|
||||||
|
return '%mlt'; // default
|
||||||
|
};
|
||||||
|
|
||||||
|
TextSlotMorph.prototype.contents = function () {
|
||||||
|
return detect(
|
||||||
|
this.children,
|
||||||
|
function (child) {
|
||||||
|
return (child instanceof TextMorph);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// TextSlotMorph events:
|
||||||
|
|
||||||
|
TextSlotMorph.prototype.layoutChanged = function () {
|
||||||
|
this.fixLayout();
|
||||||
|
};
|
||||||
|
|
||||||
// SymbolMorph //////////////////////////////////////////////////////////
|
// SymbolMorph //////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1746,3 +1746,4 @@ ______
|
||||||
------
|
------
|
||||||
* GUI: add code mapping preference to persistent settings
|
* GUI: add code mapping preference to persistent settings
|
||||||
* Blocks, BYOB, Lists, Objects: "flat" design enhancements for blocks and watchers
|
* Blocks, BYOB, Lists, Objects: "flat" design enhancements for blocks and watchers
|
||||||
|
* Blocks: Multi-line input slots (TextSlotMorphs - %mlt)
|
||||||
|
|
Ładowanie…
Reference in New Issue