Apple Mail's Splitter Behavior

Hi,
I’m trying to emulate the splitter behavior of Apple Mail, but I’m having trouble getting to work smoothly. Please see my test project here.

I need to resize the canvas so that it’s backdrop is filled in, but the way I’m doing it is slow to fill. Also, when resizing the window, the splitter won’t move the listbox above it properly.

I’m using imSplitter which I believe was contributed by forum member @Oliver Osswald Thank you, Oliver.

Don’t use a backdrop but the paint event instead.

Well, this confuses me because I read on the forum that when a canvas is used a container, nothing should be placed in Paint event. Drawing a white background in the Paint event could cause flickering. I think this was recommended by @Michel Bujardet For that reason, I went with a backdrop.

On the Mac you have to do a lot to cause flickering. Haven’t seen ever problems with paint events of canvases in a container and I use these everywhere. On the dark side things are different. For which platform do you develop?

Mostly OS X.

Use the paint event
OS X is inherently double buffered and you REALLY have to work hard to make it flicker
Drawing in the paint event and calling invalidate or refresh IN the paint event is likely to do it

Thanks Norman. I had it like that and it did work, so I’ll put it back.

Any idea on how to get the splitter to move and resize the upper listbox when the window resizes, like Apple Mail?

write code in the window resized and resizing events to move things around as needed

thats how I’d do it

It’s already been written and it’s in the test project I posted, but it’s acting wonky. I thought maybe someone could take a look and point me in the right direction.

What do you mean with "get the splitter to move and resize the upper listbox "?

On Mac you will be fine with Paint.

Lots of redundant code in here.

All works fine with most taken out.

Try this:
Add Canvas.Paint event
code:

g.forecolor = &cffc0c0 //Salmon color for the moment so that you can see what is being painted g.fillrect 0,0,g.width,g.height

REMOVE the code in Splitter1, SplitterMoved event //ResizeCanvas()

REMOVE the code in Window1.Resizing
//ResizeCanvas()
//Splitter1.MoveSplitter()

REMOVE the code in ResizeCanvas
//Dim pic as Picture
//
//pic = New picture(Canvas1.width, Max( Canvas1.height, 1 ), 32)
//pic.graphics.forecolor = &cFFFFFF
//pic.graphics.fillrect(0,0,pic.width,pic.height)
//Canvas1.Backdrop = pic

REMOVE this recursive line from Splitter MouseDrag
//MouseDrag(X,Y)

REMOVE this recursive line from Splitter.Paint
//Paint(g)

All works nicely for me afterwards…

Jeff, thanks for your help. However, most of this has already been done. Norman commented on moving the redraw of the canvas into the Paint event. Sorry I should have updated the test project. Thanks for spotting the recursive lines though!

The problem I’m having difficulty with is that when the splitter is dragged all the way to the bottom of the window.

If the user first resizes the window larger. Then drags the splitter all the way to the bottom of the window. Then resizes the window back up, the splitter doesn’t stay docked at the bottom of the window. You have to expand the window again to find it. Apple Mail does it correctly.

The test project has been updated.

So dont you just need code to check the splitter top relative to the height of the window.
In the resizing / resized event of the window, move the splitter if it is too far down.

I don’t know imsplitter but the Windows Resizing event should somehow trigger things.

I’ve dropped in my own splitter. It calls .Update from the Window .Resizing event.
MailSplitterTest.xojo_binary_project.zip

[quote=245182:@Michel Bujardet]
Michel Bujardet 20 hours ago Beta Testers, Xojo Pro
@Mark Scardingo Well, this confuses me because I read on the forum that when a canvas is used a container, nothing should be placed in Paint event. Drawing a white background in the Paint event could cause flickering. I think this was recommended by @Michel Bujardet For that reason, I went with a backdrop.
On Mac you will be fine with Paint.[/quote]
There can be some situations where the paint event is a bit too slow, like when loading a not-yet-initialized NSImage to draw it in the paint event, and turning on double buffering may lead to a white background instead of a transparent one.
In that cases, I have found flicker is removed when you make the underlying NSView have a layer with a Wantslayer = true call by declare.

I never explicitly turn on double buffering on Mac. Heck, even on Windows that non transparency mess is hardly tolerable.

But indeed, backdrop is the solution to alleviate flicker on Windows.

I found out my issue was simply because of top and bottom locks being off on the listbox and canvas. Locks always get me.

[quote=245184:@Jeff Tullin]Lots of redundant code in here.

REMOVE this recursive line from Splitter MouseDrag
//MouseDrag(X,Y)

REMOVE this recursive line from Splitter.Paint
//Paint(g)

[/quote]

I realize now that this was probably not redundant code, rather @Oliver Osswald probably wanted to raise those events. Maybe he can chime in?

Thanks