Automatically creating (unequal size) (vertical | horizontal) split TSE window

5 views
Skip to first unread message

knud van eeden

unread,
May 14, 2021, 4:14:19 PM5/14/21
to SemWare TSE Pro Text Editor, TSE Editor List
Hello,

Challenge: anyone can create a better (short) one (preferably also equal sized split windows)?

===

Automatically creating (but UNEQUAL window size) (vertical | horizontal) split TSE window

 INTEGER PROC FN2( INTEGER I, INTEGER totalI )
  IF ( I < 1 )
   RETURN( FALSE )
  ENDIF
  IF ( I == totalI )
   RETURN( TRUE )
  ENDIF
  IF ( HWindow() == 0 ) // replace here HWindow() with VWindow() for vertical windows
   RETURN( FALSE )
  ENDIF
  GotoWindow( I )
  RETURN( FN2( I + 1, totalI ) )
 END
 INTEGER PROC FN1( INTEGER totalI )
  OneWindow()
  RETURN( FN2( 1, totalI ) )
 END
 PROC Main()
  STRING s1[255] = "4"
  IF ( NOT ( Ask( "total vertical windows (choose between 1 and 8) = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) RETURN() ENDIF
  Message( FN1( Val( s1 ) ) )
 END

with friendly greetings
Knud van Eeden

knud van eeden

unread,
May 15, 2021, 9:07:57 AM5/15/21
to tse...@freelists.org, SemWare TSE Pro Text Editor
Thanks a lot Carlo,

The source code earlier supplied was thus a recursive version.

Recursive versions are usually very short, usually 'beautiful' and much more compact than iterative versions
(this because a lot of the handling (storage, stack, ...) is done internally in the interpreter / compiler in most programming languages, including TSE SAL, so a lot is going in but the user simply does not see that happening because it stays internal).

There is clearly some kind of recursion (kind of backup) when splitting the TSE windows.

Each split of the windows creates 2 smaller ones with size 1/2 of that inside the current window.

You work from the left to the right:

So you start with size one, then create smaller ones with size 1/2, select right most one, then smaller ones with size 1/4, select the right most one, then smaller ones with size 1/8, select the right most one, then smaller ones with size 1/16. 

And there it stops by design (here on my monitor at 1/16). If you try  to split then it typically does not do splitting anymore.

Then you backup (that is where the recursion jumps in) and take the first available non-1/16 size window to the left and repeat the splitting in that window similarly also until 1/16 size is reached there also. Then you go the previous split window to the left and repeat this. Until no longer possible anymore as you have reached window 1 at the left.

The problem is that the split window numbers are created in a not really successive order, 
if 8 windows then the typical order of the split windows created is:

1 2 7 8 3 6 4 5

Of course there is a systematic pattern here, it is not a random order thus,. because the new window number created here is the next last number to the right of the current number. You would have to code that particular order. While typing this I see now possibly a very simple way to do this using a string as a stack for example, maybe I will be able to implement that. 

The typical numbers of the split windows created in this way are typically:

1 (full window)
1 2 (you split 1, so split window 1 and split window 2 to the right of it)
1 2 3 (you split 2, so split window 1 and split window 2 with 3 to the right of it)
1 2 3 4 (you split 3, so split window 1 and split window 2 and split window 3 with 4 to the right of it)
1 2 3 4 5 and so on...
1 2 3 6 4 5
1 2 7 3 6 4 5
1 2 7 8 3 6 4 5
1 2 9 7 8 3 6 4 5
1 10 2 9 7 8 3 6 4 5
1 10 11 2 9 7 8 3 6 4 5
1 10 11 12 2 9 7 8 3 6 4 5
1 10 13 11 12 2 9 7 8 3 6 4 5
1 14 10 13 11 12 2 9 7 8 3 6 4 5
1 14 15 10 13 11 12 2 9 7 8 3 6 4 5
1 16 14 15 10 13 11 12 2 9 7 8 3 6 4 5

Further I actually do have an iterative version that certainly works.

It consists of 2 parts:

1. In the first part it creates the UNEQUAL SIZED split windows, just by hard coding the above numbers.

2. In the second part, also hard coded, it RESIZES EACH UNEQUALLY SIZED split window to EQUALLY SIZED. It goes through the split windows but now in reverse order. So it starts by split window 1 and ends at the right. Why reverse order? Because that resizing seemed not really possible sometimes in split windows with 1/16 size, so you can try to resize but nothing seem to happen. But this reverse method worked here for sure.

FORWARD INTEGER PROC FNWindowSetSplitSizeHorizontalCreateEqualB( INTEGER i1, INTEGER i2, INTEGER i3 )
FORWARD INTEGER PROC FNWindowSetSplitSizeHorizontalExistEqualB( INTEGER i1, INTEGER i2, INTEGER i3 )
FORWARD PROC Main()
FORWARD PROC PROCWindowCreateHorizontalIterativeSplitN( INTEGER i1 )

PROC Main()
 STRING s1[255] = "10"
 STRING s2[255] = "318" // Query( windowCols ) at full screen on my monitor // change this to your own value
 STRING s3[255] = "81" // Query( windowRows ) at full screen on my monitor // change this to your own value
 IF ( NOT ( Ask( "window: set: split: size: horizontal: create: equal: maxI = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) RETURN() ENDIF
 IF ( NOT ( Ask( "window: set: split: size: horizontal: create: equal: maxWidthI = ", s2, _EDIT_HISTORY_ ) ) AND ( Length( s2 ) > 0 ) ) RETURN() ENDIF
 IF ( NOT ( Ask( "window: set: split: size: horizontal: create: equal: maxHeigthI = ", s3, _EDIT_HISTORY_ ) ) AND ( Length( s3 ) > 0 ) ) RETURN() ENDIF
 Message( FNWindowSetSplitSizeHorizontalCreateEqualB( Val( s1 ), Val( s2 ), Val( s3 ) ) ) // gives e.g. TRUE
END

<F12> Main()

// --- LIBRARY --- //

INTEGER PROC FNWindowSetSplitSizeHorizontalCreateEqualB( INTEGER maxI, INTEGER maxWidthI, INTEGER maxHeigthI )
 //
 INTEGER B = FALSE
 //
 PROCWindowCreateHorizontalIterativeSplitN( maxI )
 //
 B = FNWindowSetSplitSizeHorizontalExistEqualB( maxI, maxWidthI, maxHeigthI )
 //
 RETURN( B )
 //
END

PROC PROCWindowCreateHorizontalIterativeSplitN( INTEGER I )
 //
 OneWindow()
 //
 GotoWindow( 1 )
 IF ( I == 1 )
  RETURN()
 ENDIF
 //
 GotoWindow( 1 )
 HWindow() // 1, 2
 IF ( I == 2 )
  RETURN()
 ENDIF
 //
 GotoWindow( 2 )
 HWindow() // 1, 2, 3
 IF ( I == 3 )
  RETURN()
 ENDIF
 //
 GotoWindow( 3 )
 HWindow() // 1, 2, 3, 4
 IF ( I == 4 )
  RETURN()
 ENDIF
 //
 GotoWindow( 4 )
 HWindow() // 1, 2, 3, 4, 5
 IF ( I == 5 )
  RETURN()
 ENDIF
 //
 GotoWindow( 3 )
 HWindow() // 1, 2, 3, 6, 4, 5
 IF ( I == 6 )
  RETURN()
 ENDIF
 //
 GotoWindow( 2 )
 HWindow() // 1, 2, 7, 3, 6, 4, 5
 IF ( I == 7 )
  RETURN()
 ENDIF
 //
 GotoWindow( 7 )
 HWindow() // 1, 2, 7, 8, 3, 6, 4, 5
 IF ( I == 8 )
  RETURN()
 ENDIF
 //
 GotoWindow( 2 )
 HWindow() // 1, 2, 9, 7, 8, 3, 6, 4, 5
 IF ( I == 9 )
  RETURN()
 ENDIF
 //
 GotoWindow( 1 )
 HWindow() // 1, 10, 2, 9, 7, 8, 3, 6, 4, 5
 IF ( I == 10 )
  RETURN()
 ENDIF
 //
 GotoWindow( 10 )
 HWindow() // 1, 10, 11, 2, 9, 7, 8, 3, 6, 4, 5
 IF ( I == 11 )
  RETURN()
 ENDIF
 //
 GotoWindow( 11 )
 HWindow() // 1, 10, 11, 12, 2, 9, 7, 8, 3, 6, 4, 5
 IF ( I == 12 )
  RETURN()
 ENDIF
 //
 GotoWindow( 10 )
 HWindow() // 1, 10, 13, 11, 12, 2, 9, 7, 8, 3, 6, 4, 5
 IF ( I == 13 )
  RETURN()
 ENDIF
 //
 GotoWindow( 1 )
 HWindow() // 1, 14, 10, 13, 11, 12, 2, 9, 7, 8, 3, 6, 4, 5
 IF ( I == 14 )
  RETURN()
 ENDIF
 //
 GotoWindow( 14 )
 HWindow() // 1, 14, 15, 10, 13, 11, 12, 2, 9, 7, 8, 3, 6, 4, 5
 IF ( I == 15 )
  RETURN()
 ENDIF
 //
 GotoWindow( 1 )
 HWindow() // 1, 16, 14, 15, 10, 13, 11, 12, 2, 9, 7, 8, 3, 6, 4, 5
 IF ( I == 16 )
  RETURN()
 ENDIF
 //
 Warn( "I", ":", " ", "split window horizontally: unhandled value. Maximum is 16. Please check." )
 //
 RETURN()
 //
END

INTEGER PROC FNWindowSetSplitSizeHorizontalExistEqualB( INTEGER maxI, INTEGER maxWidthI, INTEGER maxHeigthI )
 INTEGER B = FALSE
 //
 INTEGER minI = 1
 INTEGER I = 0
 //
 PushPosition()
 PushBlock()
 //
 FOR I = minI TO maxI
  //
  //
  CASE I
    //
   WHEN 1
    //
    // do nothing
    //
   WHEN 2
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 3
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 4
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 5
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 6
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 7
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 8
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 9
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 9 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 10
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 10 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 9 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 11
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 10 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 11 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 9 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 12
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 10 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 11 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 12 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 9 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 13
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 10 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 13 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 11 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 12 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 9 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 14
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 14 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 10 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 13 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 11 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 12 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 9 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 15 // the last window to the right is smaller. No root cause found yet for this issue [kn, ri, fr, 14-05-2021 12:25:05]
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 14 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 15 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 10 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 13 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 11 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 12 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 9 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   WHEN 16
    //
    GotoWindow( 1 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 16 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 14 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 15 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 10 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 13 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 11 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 12 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 2 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 9 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 7 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 8 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 3 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 6 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 4 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
    GotoWindow( 5 )
    SetWindowWidth( maxWidthI )
    SetWindowHeight( maxHeigthI / maxI )
    //
   OTHERWISE
    //
    Warn( "FNWindowSetSplitSizeHorizontalEqualB(", " ", "case", " ", ":", " ", I, ": not known" )
    //
    B = FALSE
    //
    RETURN( B )
    //
  ENDCASE
  //
 ENDFOR
 //
 PopBlock()
 PopPosition()
 //
 B = TRUE
 //
 RETURN( B )
 //
END



On Saturday, May 15, 2021, 01:59:45 PM GMT+2, Carlo Hogeveen <t...@ecarlo.nl> wrote:

>> Challenge: anyone can create a better (short) one (preferably also equal sized split windows)?

>> [ ... deleted example code ... ]

 

Rephrasing it in my own words: Your example program asks for a number of windows to split the TSE screen into, hardcoded either horizontally or vertically, and currently results in not equally size windows in either case.

 

No, I cannot come up with a better short version of what your example does.

 

Yes, it is possible to create a long version that does create equally sized windows.

It requires thinking outside of the box (window? :-) using 1, 3 or 4 of these steps depending on how badly you want an exact solution:

 

1.

After splitting a  window (repeatedly) we can use the ResizeWindow() statement to close the difference(s) in size to at most 1 row or column.

Note this TSE bug: ResizeWindow(_RIGHT_, 1) decreases the current window’s size instead of increasing it, but we can use a negative value to correct for that.

 

2.

We can pre-calculate the total number of available editing columns and rows before and after splitting the screen once or repeatedly.

This requires taking into account whether these settings are turned on or off: menu line, help line, line numbers, borders.

Note that if borders is turned off, then the first HWindow() creates 2 window bars and each following HWindow() only 1.

 

3.

For a not-maximized TSE screen we can get and set the total number of screen rows and columns with GetMaxRowsCols() and SetVideoRowsCols().

Given step 2 we can calculate which screen sizes support equal sizes for all our split windows, set such a smaller or larger screen size, and then apply step 1, in this case to get exactly equal window sizes.

 

4.

If we absolutely positively want a certain large number of split windows and our current font (size) does not support this, then we could also programmatically change our font (size) to one that does.

 

 

knud van eeden

unread,
May 15, 2021, 10:58:26 AM5/15/21
to tse...@freelists.org, SemWare TSE Pro Text Editor
>> Challenge: anyone can create a better (short) one (preferably also equal sized split windows)?

PROC Main()
 INTEGER N = 5 // change this to a value 1, 2, 3, 4 or 5, higher values will not work
 OneWindow()
 DO N TIMES
  GotoWindow( N )
  HWindow()
 ENDDO
END

This would possibly be the shortest (iterative) (unequal size) version, but it will only create maximum 5 split windows.
It works because the first 1, 2, 3, 4, 5 split windows can be created in that order. When inside split window 5 it then
stops because the split window 5 is already at it lowest possible size (that is 1/2 . 1/2 . 1/2 . 1/2, or thus 1/16 (on my monitor).
So any attempts to further split e.g. to window 6, 7, 8, 9, ... while located inside window 5 will fail and do nothing anymore.

with friendly greetings
Knud van Eeden



knud van eeden

unread,
May 15, 2021, 12:18:42 PM5/15/21
to tse...@freelists.org, SemWare TSE Pro Text Editor
>> Challenge: anyone can create a better (short) one (preferably also equal sized split windows)?

PROC PROC1( INTEGER N, INTEGER B )
 INTEGER I = 0
 STRING s1[255] = "1 2 3 4 5 3 2 7 2 1 10 11 10 1 14 1"
 STRING s3[255] = ""
 OneWindow()
 FOR I = 2 TO N
  s3 = GetToken( s1, " ", I )
  GotoWindow( Val( s3 ) )
  IF ( B )
   VWindow()
  ELSE
   HWindow()
  ENDIF
 ENDFOR
END

PROC Main()
 STRING s1[255] = "10"
 STRING s2[255] = "v"
 IF ( NOT ( Ask( "total windows (choose between 2 and 16) = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) RETURN() ENDIF
 IF ( NOT ( Ask( "vertical or horizontal (choose v or h) = ", s2, _EDIT_HISTORY_ ) ) AND ( Length( s2 ) > 0 ) ) RETURN() ENDIF
 PROC1( Val( s1 ), EquiStr( s2, "v" ) )
END

===

This will create up to 16 unequal sized split horizontal or vertical windows.

===

Note: Remains now to make those split TSE windows also equal in size, working on that...

with friendly greetings
Knud van Eeden



knud van eeden

unread,
May 15, 2021, 4:57:00 PM5/15/21
to tse...@freelists.org, SemWare TSE Pro Text Editor
>> Challenge: anyone can create a better (short) one (preferably also equal sized split windows)?

This will create up to 16 EQUAL SIZED split (horizontal or vertical) TSE windows.

Method: 

1. Go first to the split window number as given in the order as pre-given in the below string s1
2. Do a splitwindow there in each window (=VWindow() if vertical, HWindow() if horizontal)
3. In the mean time store the numbers of the windows in order in some string and add the last new window
at the correct position in that string
4. All this will first create unequally sized split windows
5. When finished create the equally sized split windows
6. This by going to each of those split windows in the *same* order as stored in that string
7. Inside the split window set the width to the total length divided by ( total amount of split windows ).
   That will make it equal for all. Similar for the height.

PROC PROC1( INTEGER N, INTEGER I1, INTEGER I2, INTEGER B )
 INTEGER I = 0
 INTEGER J = 0
 STRING s1[255] = "1 2 3 4 5 3 2 7 2 1 10 11 10 1 14 1"
 STRING s2[255] = "1"
 STRING s3[255] = ""
 OneWindow()
 FOR I = 2 TO N
  s3 = GetToken( s1, " ", I )
  GotoWindow( Val( s3 ) )
  IF ( B )
   VWindow()
  ELSE
   HWindow()
  ENDIF
  J = StrFind( s3, s2, "" )
  IF ( J > 0 )
   s2 = LeftStr( s2, J + Length( s3 ) - 1 ) + " " + Str( I ) + " " + RightStr( s2, Length( s2 ) - J - Length( s3 ) + 1 )
  ELSE
   s2 = s2 + " " + s3
  ENDIF
 ENDFOR
 FOR I = 1 TO N
  s3 = GetToken( s2, " ", I )
  GotoWindow( Val( s3 ) )
  IF ( B )
   SetWindowWidth( I1 / N )
   SetWindowHeight( I2 )
  ELSE
   SetWindowWidth( I1 )
   SetWindowHeight( I2 / N )
  ENDIF
 ENDFOR
END

PROC Main()
 STRING s1[255] = "3"
 STRING s2[255] = "v"
 INTEGER I1 = 0
 INTEGER I2 = 0
 OneWindow()
 I1 = Query( windowCols ) // gives maximum of columns in the current window
 I2 = Query( windowRows ) // gives maximum of rows in the current window
 IF ( NOT ( Ask( "total windows (choose between 2 and 16) = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) RETURN() ENDIF
 IF ( NOT ( Ask( "vertical or horizontal (choose v or h) = ", s2, _EDIT_HISTORY_ ) ) AND ( Length( s2 ) > 0 ) ) RETURN() ENDIF
 PROC1( Val( s1 ), I1, I2, EquiStr( s2, "v" ) )
END

knud van eeden

unread,
May 16, 2021, 8:10:54 AM5/16/21
to SemWare TSE Pro Text Editor, TSE Editor List


> Carlo Hogeveen wrote: For me the below macro does not work most of the time

The root cause should be here, 

STRING s1[255] = "1 2 3 4 5 3 2 7 2 1 10 11 10 1 14 1"

because there is hardcoded the split window GotoWindow() order to go to create the split windows. Maybe e.g. window 14 can never be created.

If it even with starting with a fully expanded TSE screen does not work, then that algorithm can thus not be used out of the box in general is the conclusion.

I work with TSE on a very large monitor, something like 55 inch.

knud van eeden

unread,
May 16, 2021, 10:46:19 AM5/16/21
to tse...@freelists.org, SemWare TSE Pro Text Editor
> Carlo Hogeveen wrote: For me the below macro does not work most of the time.

Probably very important is to always start with a full, maximized Microsoft Windows window in which TSE is running. 

It is not expected to work in a non-maximized screen.

I double checked on another very small screen (15 inch), but it worked all OK here.

Up to 16 split equal vertical windows could be created with no immediate issues on the 15 inch screen.

If sometimes rather unequal window sizes, assumed at this moment that that is something within the TSE software, because one uses only GotoWindow(), VWindow() and HWindow() and resizing TSE variables, probably not much that can be done about that without complicating the source code substantially (like repeatedly looping through the split windows and checking/resizing). 

For example even creating the split window *manually* sometimes showed actually unequal sizes on my monitor (for some of the windows).

If the above still does not work out, then not sure what is going on, maybe some:

1. Using line numbers (that is a setting in TSE)
This seems to influence the split window size, e.g. non-line number spit window besides line number split window seems to give more space to the line number split window (I do not use line numbers in general, also not during this testing).

2. Rounding errors (but considered very unlikely root cause)

Thanks

knud van eeden

unread,
May 16, 2021, 11:34:53 AM5/16/21
to tse...@freelists.org, SemWare TSE Pro Text Editor
Carlo Hogeveen wrote: For me the below macro does not work most of the time.

using the below automated 'unit testing' (usage: run it, and it will create 1 to 16 split equal windows vertically or horizontally automatically, to continue press any key) the following can be confirmed here:

1. Running this same below source code on the large 50 inch monitor does not show any issues 

(except that the horizontal split window seem not to be equal most of the times.
But using the same steps for the vertical split windows shows OK thus. 
Thus it must be an internal issue with the TSE software is currently assumed).

2. Vertical split windows should be working OK on the 15 inch monitor.

3. Horizontal windows certainly have issues on the 15 inch monitor and do not work as expected.

a. Starting from split window 5, it usually shows at least one window less (e.g. 4 windows versus 5 windows.

b.. Also the horizontal window sizes are very unequal.

Assumed still at this moment is this is also probably an internal issue with the TSE software, that is HWindow() behaves slightly different compared to VWindow(). Possibly proven by the fact that the splitting steps done are really basically the same, only replacing VWindow() (for the vertical split windows) with HWindows() (for the horizontal split windows), but thus given a different effects and outcome (one works, the other not).


---

Information for the general reader only: "Unit tests are typically automated tests written and run by software developers to ensure that a section of an application (known as the "unit") meets its design and behaves as intended. In procedural programming, a unit could be an entire module, but it is more commonly an individual function or procedure."

---
 STRING s2[255] = "h"
 INTEGER I1 = 0
 INTEGER I2 = 0
 INTEGER I = 0
 OneWindow()
 I1 = Query( windowCols ) // gives maximum of columns in the current window
 I2 = Query( windowRows ) // gives maximum of rows in the current window
 FOR I = 2 TO 16
  Warn( s1 )
  s1 = Str( I )
  s2 = "v"
  PROC1( Val( s1 ), I1, I2, EquiStr( s2, "v" ) )
  UpDateDisplay() // IF WaitForKeyPressed( 0 ) ENDIF // Activate if using a loop
 ENDFOR
 FOR I = 2 TO 16
 Warn( s1 )
  s1 = Str( I )
  s2 = "h"
  PROC1( Val( s1 ), I1, I2, EquiStr( s2, "v" ) )
  UpDateDisplay() // IF WaitForKeyPressed( 0 ) ENDIF // Activate if using a loop
 ENDFOR
END



Reply all
Reply to author
Forward
0 new messages