Hello World program with StringHolder - details
Last updated at 6:21 am UTC on 9 December 2017
If you want to better control the position of the window generated by the Hello World Program with the StringHolder use the following code:
|sh|
sh := (StringHolder new textContents: ('Hello World!! This is a test.')
withSqueakLineEndings; openLabel: 'Workspace test').
sh model topView extent: 200 @ 100.
sh model topView position: 10 @ 20
sh model topView is a SystemWindow. You can control it's extent and position. Both methods take as parameter a Point. In the case of #extent: it is interpreted as the size of the rectangle and in the case of position it is the coordinate of the upper left corner of the window (first parameter is x going from left to right, second parameter is y going from top to bottom; absolute coordinates).
If you want the window to appear on the right hand side of the screen, in whatever size, use:
|sh|
sh := (StringHolder new textContents: ('Hello World!!
This is a test.
') withSqueakLineEndings; openLabel: 'Workspace test').
sh model topView extent: 200 @ 100.
sh model topView position: (Display width - 220) @ 20
If you want to prevent the window from being moved, send the message #beSticky. This message may be sent to any Morph as it is implemented there. Actually this is true for #extent: and #position: as well.
|sh|
sh := (StringHolder new textContents: ('Hello World!!
This is a test.
') withSqueakLineEndings; openLabel: 'Workspace test').
sh model topView extent: 200 @ (Display height - 40).
sh model topView position: (Display width - 220) @ 20.
sh model topView beSticky.
If you want the SystemWindow to be collapsed add another two lines:
|sh|
sh := (StringHolder new textContents: ('Hello World!!
This is a test.
') withSqueakLineEndings; openLabel: 'Workspace test').
sh model topView extent: 200 @ (Display height - 40).
sh model topView position: (Display width - 220) @ 20.
sh model topView beSticky.
sh model topView collapse.
sh model topView position: (Display width - 220) @ 20.
If you want to update the content of the workspace use add these three lines after #beSticky:
[(Delay forSeconds: 3) wait.
sh model contents: 'something new...'.
sh model changed: #contents] fork.
This does not work in 5.1. I cannot find a replacement for HtmlParser, I think it is a deprecated class. Try it in 6.0
And finally if you want to show some HTML text (subset of the tags, notables for example) use
sh model contents: (*2248* parse: '<html>hello <b>World!</b></html>') formattedText.
sh model changed: #contents.