Window Splitters

How are people implementing their own splitters? I normally use a canvas and on mousedown store the x and y coordinates of the mousedown and then on mousedrag calculate the DeltaX or DeltaY and change Top or Left of the canvas as appropriate.

Thats all well and good but say I want don’t want to be able to drag the splitter less that 20px from the top of the screen, I am then putting If self.top > 20 then… blah blah blah, problem is if you drag fast enough you can drag the control past this point before If self.top > 20 then… is evaluated. Am I going about this wrong or any tips on this.

You might have a look on this:

  1. http://forums.realsoftware.com/viewtopic.php?f=1&t=44830&hilit=window+splitter

I too was looking for a decent window splitter control.

I downloaded the one from Einhugur, but when I try to run the project - I get 2 errors stating that:
WIndowSplitter1 implements the event “Open”, but its superclas “WindowSplitter” has already implemented the event :frowning:

Like this:
https://forum.xojo.com/2074-split-screen/p1#p15397

That is really nice - and much better than I could ever produce.
The only problem I can foresee, is that the user would not know it is a splitter, as there is no image such as the dot or lines, which are normally present?

Just something I notice.

[quote=85940:@Richard Summers]…
The only problem I can foresee, is that the user would not know it is a splitter, as there is no image such as the dot or lines, which are normally present?

Just something I notice.[/quote]

The splitter is a canvas and you can draw anything on it, lines, circles, whatever.
Just add some code to the imSplitter class’ paint event handler, for instance like this:

[code]Sub Paint(g As Graphics, areas() As REALbasic.Rect)
If me.HasBackColor Then
g.ForeColor=me.BackColor
g.FillRect(0,0,me.Width,me.Height)
End If

// Draw a circle as splitter handle
Dim dia As Integer = 2
Dim x As Integer = (Me.Width/2)-(dia/2)
Dim y As Integer = (Me.Height/2)-(dia/2)
g.DrawOval(x,y,dia,dia)

Paint(g)
End Sub
[/code]

Thanks Oliver - that worked perfectly.
One last question - could you advise me how I get 3 vertical lines (side by side), instead of a circle?

I have fiddled with the code but cannot get the lines to appear :frowning:
I got totally confused with the X1 X2 Y1 Y2 coordinates of DrawLine.

One way to achieve this would be:

[code]Sub Paint(g As Graphics, areas() As REALbasic.Rect)
If me.HasBackColor Then
g.ForeColor=me.BackColor
g.FillRect(0,0,me.Width,me.Height)
End If

// Draw 3 lines as splitter handle
Dim size As Integer = 20
Dim dist As Integer = 2
Dim x1,x2,y1,y2 As Integer = 0

If Me.IsHorizontalSplitter And Me.Height >= 10 Then
x1 = (Me.Width/2)-(size/2)
x2 = x1+ size
y1 = (Me.Height/2)
y2 = y1

g.DrawLine(x1,y1-dist,x2,y2-dist)
g.DrawLine(x1,y1,x2,y2)
g.DrawLine(x1,y1+dist,x2,y2+dist)

// vertical splitter

Elseif Me.IsHorizontalSplitter=False And Me.Width >= 10 Then
x1 = (Me.Width/2)
x2 = x1
y1 = (Me.Height/2)-(size/2)
y2 = y1 + size

g.DrawLine(x1-dist,y1,x2-dist,y2)
g.DrawLine(x1,y1,x2,y2)
g.DrawLine(x1+dist,y1,x2+dist,y2)

End If

Paint(g)
End Sub
[/code]

Fantastic !
Thank you for all your help Oliver - I’m sure others will also benefit from having the choice of 2 different handles :slight_smile:

THANK YOU.

Nice one Oliver, thats save me some time

I will improve, step-by-step: If anyone wishes to contribute, I put it on github:
https://github.com/oleman108/imSplitter

instead of drawing lines for the seperator
there is a triple vertical bar at unicode U+2980, the horizontal version is at U+2360

I’m sure there is demand for a customizable splitter :slight_smile:

Coloured splitter handles in particular.

I committed an update to Github which contains a new HandlesColor property, which can be set in the inspector for each splitter.

Thanks Russ, I didn’t know about these characters!

Oliver - there are numerous errors when the updated project is run in the IDE.
I have attached a screenshot link.
Screenshot

BTW, for those who are not yet using github:

Get yourself a git client from Mac Appstore, like Gitbox for instance. There you can choose -> File -> Clone Repository and then you add in the URL of the repo, like: https://github.com/oleman108/imSplitter. Continue to clone it to a local folder.

There are many other nice ones, in random order:

https://github.com/macoslib/macoslib
https://github.com/arbp/WFS
https://github.com/ktekinay/Profile-Reader
https://github.com/xojo/TextInputCanvas
https://github.com/mikecotrone/TELNET_Class_Xojo
https://github.com/mikecotrone/CalendarTimeChooser
https://github.com/joeworkman/rwsnippets
https://github.com/jcowgar/xojo-format-code
https://github.com/sworteu/Module_DutchTools
https://github.com/sworteu/ParseSocket
https://github.com/sworteu/WebTools
https://github.com/esotalk/esoTalk.git

[quote=86195:@Richard Summers]Oliver - there are numerous errors when the updated project is run in the IDE.
I have attached a screenshot link.
Screenshot[/quote]
From your screenshot I cannot see what went wrong.

I just tested and cloned https://github.com/oleman108/imSplitter to a new local repo. From there I loaded and ran SplitterTest.xojo_project , without any errors.

I am using Xojo 2014r1.1 on OSX 10.9.2

Are you running my test project or are you working on your own project, where you changed something?

If yes, then I would suggest, that you copy/paste the imSplitter class to your project (from my test project). Then you create a new class mySplitter with a Super of imSplitter. Now you drag mySplitter to your Window and use the eventhandlers of mySplitter to implement your own painting (or whatever).

Like that you can pull new updates from github and replace older versions of the imSplitter class in your code, without your own code being bothered.

Clear?

I downloaded you project and the errors displayed when I tried to run it.

And one more advantage of subclassing imSplitter would be, that then you can switch at any time to the more powerful commercial version of the Einhugur splitter. Just change the Super of your sublcassed splitter from imSplitter to WindowSplitter.

Did you download it with a git client?
Did you try only once? Maybe something went wrong during download?