Is it possible to get OS X scrollbars on a ListBox

Hey everyone,

A while back, Mac OS X changed its default scrollbar style to hide the scrollbar when it’s not being used, and to overlay a translucent scroll indicator that’s overlaid on top of the content when you’re actually scrolling.

Is it possible to get this type of scrollbar in Xojo’s ListBox control, instead of the default style that uses up that width all of the time?

[quote=198475:@Tom Catchesides]Hey everyone,

A while back, Mac OS X changed its default scrollbar style to hide the scrollbar when it’s not being used, and to overlay a translucent scroll indicator that’s overlaid on top of the content when you’re actually scrolling.

Is it possible to get this type of scrollbar in Xojo’s ListBox control, instead of the default style that uses up that width all of the time?[/quote]

I believe you can get something similar by hiding the regular scrollbar, and show a canvas simulating the “new scrollbar” with a grey knob in the MouseWheel event, with a timer to hide it after a second.

Thanks for the suggestion, Michel!

That approach had crossed my mind, but I was rather hoping that we might be able to tap the native scrollbar so that we benefit from any changes in its behaviour that Apple make in future.

Your suggestion would also allow us to get a similar effect on Windows, which would be a bonus except that I’m wary of ever overlaying controls on Windows because of redraw luckiness.

[quote=198479:@Tom Catchesides]Thanks for the suggestion, Michel!

That approach had crossed my mind, but I was rather hoping that we might be able to tap the native scrollbar so that we benefit from any changes in its behaviour that Apple make in future.

Your suggestion would also allow us to get a similar effect on Windows, which would be a bonus except that I’m wary of ever overlaying controls on Windows because of redraw luckiness.[/quote]

ListBox is not a native control, which explains why you do not get it automatically on Mac. But I believe my approach would work.

On Windows indeed that would probably badly flicker. Also, Windows users would not expect such a thing. It is not at all usual.

If plugins are an option then I believe Christian has several MBS examples on how to change style of a scrollbar.

https://www.monkeybreadsoftware.net/class-customnsscrollermbs.shtml

like the black one, for instance:

ListBox OverlayScrollbars by Massimo Valle

This works great! Just implemented it in an app :slight_smile:
Thanks @Massimo Valle !

For $99, Imho the best listbox addon in Xojo.

Dataview

Awesome work, Massimo. I’m going to give that approach a go!

I just played with it. It is based on the same principle as what I was describing in the second post. Beautiful implementation.

To have the scrollbar appear the same way as in regular OSX apps, set the listbox with no scrollbar in the IDE, then in its MouseWheel event :

Function MouseWheel(X As Integer, Y As Integer, deltaX as Integer, deltaY as Integer) As Boolean
  me.ScrollBarVertical = True
  HideScrollBar.mode = Timer.ModeSingle
  HideScrollBar.enabled = False
  HideScrollBar.enabled = True
End Function

HideScrollBar is a Timer dragged over the Windows set to off with a period of 1000

It is reset to enabled = False so each time MouseWheel happens the period is pushed back. The last time MouseWheel takes place it will hide the scrollbar after one second, like it happens in for instance TextArea.

Here is the action of HideScrollBar :

Sub Action() ListBox1.ScrollBarVertical = False me.enabled = False End Sub

[quote=198577:@Michel Bujardet]I just played with it. It is based on the same principle as what I was describing in the second post. Beautiful implementation.

To have the scrollbar appear the same way as in regular OSX apps, set the listbox with no scrollbar in the IDE, then in its MouseWheel event :

Function MouseWheel(X As Integer, Y As Integer, deltaX as Integer, deltaY as Integer) As Boolean
  me.ScrollBarVertical = True
  HideScrollBar.mode = Timer.ModeSingle
  HideScrollBar.enabled = False
  HideScrollBar.enabled = True
End Function

HideScrollBar is a Timer dragged over the Windows set to off with a period of 1000

It is reset to enabled = False so each time MouseWheel happens the period is pushed back. The last time MouseWheel takes place it will hide the scrollbar after one second, like it happens in for instance TextArea.

Here is the action of HideScrollBar :

Sub Action() ListBox1.ScrollBarVertical = False me.enabled = False End Sub [/quote]

When I click the mouse on the scroll bar, the program crashes.

I was experimenting with automatically showing and hiding regular ListBox scrollbars yesterday, too, and got intermittent hard crashes on Mac OS X. If I could reliably replicate it, I’d create a Feedback case.

I’ve spent the last few hours trying to track down an odd ListBox oddity which is indirectly related to adopting Massimo’s extremely helpful scrollbar class, so I thought I’d report back on here in case anyone else encounters it.

My ListBoxes used custom painting code, and on OS X I was getting frustrated because in the CellBackgroundPaint event g.Width was 1px less than Me.Width. This was leaving a 1px wide artefact on the right hand edge of the ListBox that I couldn’t get rid of.

It turns out that programmatically turning off the ListBox.ScrollBarVertical property causes this. If I leave that turned off in the layout and modify OverlayScrollBars to not care about that setting, g.Width and Me.Width are the same. If I let the OverlayScrollBars class turn off the property in its Open event handler, I get that redraw bug.

I can replicate this in a sample project, so I’ll create a Feedback case.

I could not reproduce the issue.

You may want to send a message to Massimo as well.

Just to be clear, my problem with intermittent crashes was from when I was experimenting with showing and hiding ListBox scrollbars myself: it had nothing to do with Massimo’s work.

OK. So indeed a Feedback is in order.

After playing with Massimo’s demo project, though, and in spite of it being quite polished, I would have probably done it differently. His programs depends on the values in ScrollBarVertical and ScrollBarHorizontal to display his OverlayScrollBar, so in effect, it complements the existing scrollbars rather than replace them. As a result it is not transparent, as the real scroll bars are in OS X.

And the bug you reported will exist as well.

I believe it would be better that the original scrollbars be off, and that a transparent canvas be overlaid when MouseWheel takes places in effect showing only the knob, as it happens throughout OS X.

If I find some time, I will try to do it that way.

[quote=198589:@Michel Bujardet] @Axel Schneider When I click the mouse on the scroll bar, the program crashes.

I could not reproduce the issue.[/quote]

Michael, can you please test this

[quote=198662:@Axel Schneider]Michael, can you please test this

[/quote]

It does crash very badly. And this is visibly an issue with the code. Hopefully Massimo will be able to assist…

Here is little project that includes native OSX scrollbars to a listbox with several declares. They are working natively so they are transparent, fade out, fade in, …

http://www.filedropper.com/nativeosxscrollerlistbox

but only with MBS ?