1.2 Quick Start

Rendering a single morph isn’t particularly interesting. Let’s render some labels, a text input, and a button to implement a simple application.

In a new Workspace, select and invoke the following code. Ctrl+a to select All, then Ctrl+d to DoIt.

| view input greetingLabel button row |

view := LayoutMorph newColumn.

"Create a single-line text input.
 Using zero for the height causes it to calculate
 the minimum required height for a single line."
input := TextModelMorph withText: '' ::
    hideScrollBarsIndefinitely;
    morphExtent: 200 @ 0;
    wrapFlag: false.

greetingLabel := LabelMorph contents: '' ::
    color: Color red;
    font: FontFamily defaultFamilyAndPointSize bold.

"Create a button that when clicked execute
 the associated block of code"
button := PluggableButtonMorph
    model: [greetingLabel contents: 'Hello, ', input text, '!']
    action: #value.
button label: 'Greet'.

row := LayoutMorph newRow
    gap: 10;
    addMorph: (LabelMorph contents: 'Name:');
    addMorph: input;
    addMorph: button.

view
    padding: 20;
    addMorph: row;
    addMorph: greetingLabel;
    openInWorld

Example 1.2: My first layout

ch01-morphicGreeter

Figure 1.1: My first interface

This morph is a bit like a “Hello World” panel, it should be inserted in window with proper title and icon to operate on. To remove this panel, you need again the request its halo, it is not very practical. Let’s change the simple app we’ve built so it can be inside a window. In the previous code, edit the end of the script to insert our view in a SystemWindow instance.

Again, select the entire script and invoke it.

[...]
view
    padding: 20;
    addMorph: row;
    addMorph: greetingLabel.

SystemWindow new ::
   setLabel: 'Hello World!';
   addMorph: view;
   openInWorld;
   morphExtent: 300@100
ch01-windowGreeter

Figure 1.2: My first window