I am writing a specialised richtextbox using a MaxGUI canvas. I can't use a standard TextArea because I need very specific control over margins and text style which may vary every line (I am writing a Theatrical script editor). I have therefore coded some wordwrap functions, pseudo code:
The beauty of using recursion here is that processing will stop automatically as soon as words can no longer be wrapped. Unfortunately, with a really long paragraph, this could generate an "Out Of Stack Space" error. Since FlameDuck has confirmed there is no way to monitor available stack space, I have decided to modify the Method to wrap once (this is necessary in order to correctly adjust the claret position), then reformat the whole paragraph:
which will work, but will almost certainly include a lot of unnecessary processing on larger paragraphs.
Repeat Process_Keys() Wrap_WordDown(ClaretLine,1) Forever Method Wrap_WordDown(LineNo:Int,UpdateClaret:Int) If Len(WordAtEndOfLine(LineNo))<GapAtEndOfLine(LineNo+1) ' ' Move word to start of next line here ' If UpdateClaret ' Update Claret parms EndIf Wrap_WordDown(LineNo+1,0) EndIf End Method
The beauty of using recursion here is that processing will stop automatically as soon as words can no longer be wrapped. Unfortunately, with a really long paragraph, this could generate an "Out Of Stack Space" error. Since FlameDuck has confirmed there is no way to monitor available stack space, I have decided to modify the Method to wrap once (this is necessary in order to correctly adjust the claret position), then reformat the whole paragraph:
Method Wrap_WordDown(LineNo:Int,UpdateClaret:Int) If Len(WordAtEndOfLine(LineNo))<GapAtEndOfLine(LineNo+1) ' ' Move word to start of next line here ' If UpdateClaret ' Update Claret parms EndIf Wrap_CurrentParagraph() EndIf End Method
which will work, but will almost certainly include a lot of unnecessary processing on larger paragraphs.