Fade out scrollbar when not needed

I want to fade out a single scrollbar like it does in macOS in most lists (Finder). How to to that? (without MBS, please)

This workes for a TextArea but not with a sinle scrollbar
https://forum.xojo.com/26687-textarea-scrollbar-issue/0#p220679

For that you need a NSScrollView. Without MBS this is pretty heavy to implement (read: not easy).

I’m sure you don’t need NSScrollView, but just NSScroller…

You can try this: https://github.com/maxvalle/OverlayScrollbars

It’s just a fake scrollbar I made time ago, but works decently well.

NSScroller is what Xojo uses now. For “correct” scrollbars, you really do need an NSScrollView.

Sorry… that makes zero sense… Since a NSScrollView is actually two NSSCrollers and a contentarea

It would be easier to apply declares to an NSScroller, than it would be to have to “remove” the other pieces

[quote=409916:@Dave S]Sorry… that makes zero sense… Since a NSScrollView is actually two NSSCrollers and a contentarea

It would be easier to apply declares to an NSScroller, than it would be to have to “remove” the other pieces[/quote]
The scrollbars in a NSScrollView behave differently than standard NSScrollers.

Even with MBS, the biggest problem with a NSScrollView and Xojo, is that is really messes with what Xojo expects (especially coordinates), there are some things you can do to improve it, but then you’ll always be fighting the Xojo view system.

Not to mention that with really complicated interfaces, it’s actually much slower to use a NSScrollView (even with Apple’s magic caching behind the scenes) and you get actually get better performance by using a regular NSScroller.

p.s. The TextArea uses a NSScrollView.

Not in my experience… I have implemented both, and other than the fact the NSScrollView has TWO scrollers and a content area, the “scrollbar” parts work the same… and the only “coordiante” issue might be that NS controls expect the Y coordinate to be 0 at the bottom, but X coodinates should be fine

That’s an understatement.

@Dave S NSScrollView uses scroll indicators that disappear and resize when not in use. They support the “snapback / overscroll” functionality from iOS too. Plus lots of subtle things, like showing the indicator when two fingers are placed on a trackpad, but not moved.

You could replicate the behavior with a Xojo Canvas using the MouseWheel event and lots of declares to look at the NSEvent. I have a class ArtisanKit/Project/ArtisanKit/ScrollEvent.xojo_code at master · thommcgrath/ArtisanKit · GitHub to get most of those properties, but you’d still need to implement all the functionality yourself. It is no small undertaking. I can make a good custom scrollbar in about an hour, but replicating NSScrollView… I’ve put effort into it and ultimately decided my time was better spent elsewhere.

yes… but the OP wants a Scrollbar, not a ScrollView… so everything that the ScrollView adds is over-head (and all that can be added to a NSScroller as well if desired/required)

You cannot overscroll with NSScroller. Nor do they have a transparent background. And the intent of the original request is to get closer to the modern design. NSScroller is just what we’re stuck working with.

To get back to that original request, I think fading it out is a little optimistic. It might be more realistic to slide the scrollbar away. Follow the link in my last reply, those declares can be used to know when to show the scrollbar, and a timer to decide when to hide it. Windows and Linux support will be a little more tricky, as you won’t be able to show the scrollbar until a scroll actually starts.

welll… yeah they do (or rather can)… but I’m just basing that on the last month or so of studying various NSControls and playing with them in their native environment… but at this point it seems that any knowledge I have to impart is just going to be past over… so I will cease and desist at this point

Or… you could share that information? I’d be happy to be proven wrong.

self.alphaValue = x // THIS IS NOT AN XOJO STATEMENT

This is a native property of NSScroller… now with Xojo it might take a declare to expose it, and I will leave that as an exercise for the masses.

And yes I know it works… I just tested it

this makes the whole thing transparent… but do a “google search” and there are topics on just the “background”… this I have not implemented, as I have no current need at the moment

That’s not the same thing… like… at all. That is a property of NSView that makes the entire view, in this case both the track and thumb, translucent. A proper scroll indicator in NSScrollView has no track at all and a translucent thumb. You can’t replicate that with NSScroller.

However, in the context of this request, it could be used in combination with AnimationKit to smoothly fade the scrollbar in and out. It won’t look native, but it is what @Ratchet Lombax is asking for.

The declare would look something like Declare Sub SetAlphaValue Lib "Cocoa.framework" Selector "setAlphaValue:" (Target As Ptr, Value As CGFloat)

The target value would be the scrollbar’s handle property. Also, I just wrote this declare here, it is not tested.

Thom… as I said… yes, that affects the entire scrollbar… and that seems to be what the OP asked.

but also like I said… there are many articles that indicate how to affect just the background…

I’m using CustomEditField and the problem is, it does not have it’s own scrollbars. You have to add single scrollbars (vertical/horizontal) and connect them to the EditField. Works fine, but I want to have the modern look of the scrollbars, what means:

  1. The scrollbars appear to be inside the EditField
  2. The scrollbars have no background, only the sliders are visible
  3. The scrollbars disapear when not used

That’s how it looks now:

With AnimationKit I’m able to fade them out. Great :slight_smile:
Still the other problem, I had in another thread: https://forum.xojo.com/50554-remove-scrollbar-border/p1#p409885
(It’s not the border, it’s the background I want to remove. Sorry, first it seemed it just had a border…

Yeah, that’s what we figured. Unfortunately, there’s not really an option to get a native scroller for it.

[quote=409943:@Ratchet Lombax]I’m using CustomEditField and the problem is, it does not have it’s own scrollbars. You have to add single scrollbars (vertical/horizontal) and connect them to the EditField. Works fine, but I want to have the modern look of the scrollbars, what means:

  1. The scrollbars appear to be inside the EditField
  2. The scrollbars have no background, only the sliders are visible
  3. The scrollbars disapear when not used
    [/quote]

You forget the bounce effect which is native behaviour (and something every macOS user expect).
That’s only possible with NSScrollView.

So basically:
If you need a fake looking (and behaving) scroller, then use the NSScroller with some tricks to make it look ‘right’.
If you need a native working scroller, you need NSScrollView. I have some examples the implement a Listbox and containers. It works perfect but as Sam says, it does mess up the Xojo way. Up to now it always kept working, but if Xojo changes some things, it can break.

On a side note:
If you are using the Xojo Listbox (which isn’t native), you definitely need to check Thomas Templemanns NSTableView replacement which is truly amazing. I now use it instead of the (on macOS dreadful looking) Listbox for my macOS projects.

Do some search here to find the NSScrollView and NSTableView. Imo they are essential for creating a decent, full native, modern looking macOS app with Xojo. In other words, your app will not look alienate to macOS users.

@Ratchet: The link to the XScrollView project by Jim I posted in your other thread should do the trick for you. You can attach a native ScrollView to every Rect- or ContainerControl, which means you should be able to use your custom EditField the way you are planning.