[Cuis] StringMorph and lf

Dan dnorton at mindspring.com
Wed Jan 28 21:22:26 CST 2015


On 28 Jan 2015 at 10:39, Juan Vuletich wrote:

> Hi Dan,
> 
> (below)
> 
> On 1/26/2015 12:19 AM, Dan wrote:
> > Howdy,
> >
> > On 24 Jan 2015 at 20:44, dnorton at mindspring.com wrote:
> >
> >> Hi Juan,
> >>
> >> By subclassing SystemWindow, I defined a simple window with 3
> panes,
> >> using LayoutMorph
> >> newRow for each. Two of these have StringMorph as a submorph.
> >> Strings in this app, which
> >> are for display only, contain Character lf in several places
> are
> >> sent using
> >> StringMorph>contents:. They are drawn with every lf removed.
> Can
> >> StringMorph be
> >> commanded to honor the lf? Is there something better that should
> be
> >> used instead of
> >> StringMorph?
> >>
> > Using StringMorph in this way may be too simplistic.
> > Instead use TextModelMorph with a model which is a subclass of
> TextModel. At least this
> > can draw with the lf characters in place. It's more complex and it
> allows editing of the string
> > by default but maybe that can be suppressed?
> >
> >   - Dan Norton
> >
> 
> You don't really need a new class. This works:
> 
>          model := TextModel new contents: 'Hi folks, \this is a 
> multiline text, \see?' withNewLines .
>          doWrap := true.
>          m := TextModelMorph withModel: model.
>          m wrapFlag: doWrap.
>          m hideScrollBarsIndefinitely.
>          m lock.
>          m openInWorld
> 
> Locking the morph is not the ideal thing to do, as you can't grab it
> with the halo anymore. You can add a readOnly capability to 
> TextModelMorph, that would be a welcome addition. Also, maybe some
> convenience method with code like my snippet above could be
> useful.
>
The window won't contain all the lines at times, so lock and hideScrollBarsIndefinitely prevent 
the user from seeing everything. Here's what seems to give the best results so far, but there 
are problems with the scroll bars. This method is sent to self by #initialize:

setupBoard
	"Specify the layout for the <...> window"
	| status statusMorph clues |
	
	status := LayoutMorph newRow
		addMorph: (statusMorph := TextModelMorph 
			withModel: (statusString := TextModel withText: 'Status Area')).
			
	buttonPane := LayoutMorph newRow
		padding: #center;
		color: Color lightGreen.
	
	clues := LayoutMorph newRow
		addMorph: (cluesMorph := TextModelMorph 
			withModel: (cluesString := TextModel withText: 'Clues Area')).
			
	statusMorph askBeforeDiscardingEdits: false;
		wrapFlag: true;
		hideOrShowScrollBars.
			
	cluesMorph askBeforeDiscardingEdits: false;
		wrapFlag: false; "false because clues are short one-liners"
		hHideScrollBar; "<--- ***** note: it is not hidden"
		hideOrShowScrollBars.
		
	self layoutMorph
			addMorph: status proportionalHeight: 0.15;		
			addAdjusterAndMorph: buttonPane proportionalHeight: 0.05;		
			addAdjusterAndMorph: clues proportionalHeight: 0.80.

This way of laying out is a big improvement over Morphic 2. However problems with the 
above are that the vertical scroll slider extends beyond its owner's extent. It resumes normal 
size only after the window is resized. The horizontal scroll bar defies my efforts to remove it. 
Let me know if I should send the rest of the code to you.





More information about the Cuis mailing list