Adding NSVisualEffectViewMBS to Canvas

Any advice for making this work better? My goal is to just give the vibrancy effect to this canvas. I want the canvas to still behave as normal, following Xojo locking rules, positioning, and so on.

#if TargetMacOS
  Var View As New NSVisualEffectViewMBS(0, 0, Self.Width, Self.Height)
  View.BlendingMode = NSVisualEffectViewMBS.NSVisualEffectBlendingModeBehindWindow
  View.Material = NSVisualEffectViewMBS.NSVisualEffectMaterialAppearanceBased
  View.State = NSVisualEffectViewMBS.NSVisualEffectStateFollowsWindowActiveState
  View.AutoresizesSubviews = True
  View.AutoresizingMask = NSViewMBS.NSViewMaxXMargin Or NSViewMBS.NSViewHeightSizable
  
  Var ContentView As NSViewMBS = Self.NSViewMBS
  Var RootView As NSViewMBS = ContentView.Superview
  ContentView.RemoveFromSuperviewWithoutNeedingDisplay
  
  View.AddSubview(ContentView)
  RootView.AddSubview(View)
#endif

The issue, I believe, is the ContentView in this case is the canvas itself, and RootView is the window it is placed on. So when I move the canvas in Xojo, I’m actually moving the canvas inside the vibrancy view. Since the unmodified canvas has no child views, I can’t place the vibrancy view inside the canvas without obscuring the contents.

I think you confuse some views here.
Canvas.NSViewMBS gives the canvas view. The parent of that is the content view of the window or the view of a container.

So I would guess you could put a visual effects view in that view with the frame of the canvas and then put the canvas inside, but with the frame having x and y being zero.

Isn’t that what I’ve done though? ContentView is the canvas, RootView is the window. So I’m removing the canvas from the window, adding it to an NSVisualEffectView, and adding that NSVisualEffectView back to the window. It works… until the window needs to resize.

I imagine I may need to make my source list a container control.

Some thoughts.

This material is deprecated, use it for 10.10 to 10.13, from 10.14 onwards use the new material constants. If you’re making a sidebar, you can use the NSVisualEffectMaterialValue.sideBar_ELCap material, and still get support for 10.11 +

If you’re placing this view on the window, use the mask NSViewMinYMargin to adopt logical locking from the top, as opposed to the bottom of the window.

Again if placing on the window, you can use the frame NSViewFrame of canvas when creating the Visual Effect View, if you’re injecting into a Canvas, you can use the bounds of the canvas NSViewBounds.

You can save a step here, by simply adding the Visual Effect View to the NSWindowContentView of the window, under the canvas.
NSViewAddSubviewPositionedRelativeTo( <NSWindowContentView>, <visualEffectView>, NSWindowBelow, <canvasView> )

But it won’t move with the canvas.

Of course you can, you can also just embed the visual effect view into the canvas, and then stack canvases on top in the Xojo IDE. Just make sure that when you inject the effect view, you insert it below the first child view (using NSViewAddSubviewPositionedRelativeTo).

Hope this helps, there is a pre-made sidebar canvas in the Ohanaware App Kit.

Edit: I forgot to mention that there’s also a pre-made source list control, which is Listbox based (for easy integration) that supports system supplied images ( also SF Symbols on Big Sur) with optional colorization. A Xojo compatible ScrollView that you can wrap the source list in, which supports elastic scrolling on the macOS. Because it’s all Xojo source code, you can customize it to your hearts desire.

I have a couple of improvements coming, which include getting the system source list size and control over the elasticity.

Thanks. The container route seems to play nicest with Xojo. I can just drop it on the window, and everything works. All the logic stays self contained, rather than having to worry about keeping the positions of two objects in sync.

I wasn’t aware of the new material types. I was just referencing the MBS docs.

No worries, glad I could help. There’s nothing wrong with either method (IMHO), just what works for you.

Apple deprecated a whole bunch with 10.14, they’d previously snuck some in 10.11, but added a whole bunch more with 10.14. Their argument was you should be using the material for the control/interface you want, rather than the color, took some getting used.