Codementor Events

Squeak/Smalltalk: Creating new SystemWindow

Published Jan 21, 2023
Squeak/Smalltalk: Creating new SystemWindow

It’s very easy to get started with Squeak/Smalltalk. You can use Workspace and Transcript for basic programming tasks. But soon you need your own user interface, and it’s good to get started with the SystemWindow object in this case.

Here is some Smalltalk code that can help you create and display a SystemWindow.

Code

window := SystemWindow new.
window setLabel:'New Window'.
pasteUpMorph := PasteUpMorph new.
pasteUpMorph extent: 640@480.
window addMorph: pasteUpMorph frame: (0@0 corner: 1@1).
window openInWorld.

Screenshot

New Window.PNG

Here is another code example with scrollPane.

window := SystemWindow new.
scrollPane := ScrollPane new.
pasteUpMorph := PasteUpMorph new.
pasteUpMorph extent: 1000@1000.
scrollPane scroller addMorph: pasteUpMorph.
window addMorph: scrollPane frame: (0@0 corner: 1@1).
window openInWorld.

Screenshot

New Window scrollpane.PNG

Definations

ScrollPane

The scroller (a transform) of a scrollPane is driven by the scrollBar. The scroll values vary from 0.0, meaning zero offset to 1.0 meaning sufficient offset such that the bottom of the scrollable material appears 3/4 of the way down the pane. The total distance to achieve this range is called the totalScrollRange.

PasteUpMorph

A morph whose submorphs comprise a paste-up of rectangular subparts which “show through”. Anything called a ‘Playfield’ is a PasteUpMorph.

Facilities commonly needed on pages of graphical presentations and on simulation playfields, such as the painting of new objects, turtle trails, gradient fills, background paintings, parts-bin behavior, collision-detection, etc., are (or will be) provided.

A World, the entire Smalltalk screen, is a PasteUpMorph. A World responds true to isWorld. Morph subclasses that have specialized menus (BookMorph) build them in the message addBookMenuItemsTo:hand:. A PasteUpMorph that is a world, builds its menu in HandMorph buildWorldMenu.

SystemWindow

SystemWindow is the Morphic equivalent of StandardSystemView — a labelled container for rectangular views, with iconic facilities for close, collapse/expand, and resizing.

The attribute onlyActiveOnTop, if set to true (and any call to activate will set this), determines that only the top member of a collection of such windows on the screen shall be active. To be not active means that a mouse click in any region will only result in bringing the window to the top and then making it active.

Conclusion

I hope this is helpful. This window object opens many opportunities for creating UI elements and drawing. I look forward to follow this up with more articles that show how to draw on a window.

Looking forward to your feedback and questions.

Discover and read more posts from Humayun Shabbir
get started
post commentsBe the first to share your opinion
Show more replies