Getting the height of a macOS toolbar

Following on from this (solved) post, I have a toolbar on my window and, using declares, have set the toolbar style to “unified compact” and the window’s mask to “full size content view”.

The issue I’m having now is I don’t know how tall the toolbar is. When designing the window’s layout in Xojo’s layout editor, I just have to guess where the top of the content is:

I can’t put my content at the top of the window as seen in Xojo’s IDE because then the content overlaps the toolbar (since I’ve altered things with declares).

Rather than hard code a value for where the actual bottom of the tool bar is, is there an accessible property of the toolbar I can use? Using the toolbar’s height gives 0 that doesn’t work. I asked ChatGPT and it suggested using the visibleHeight property of NSToolbar so I’m guessing there is a way to get this information with declares.

Does anyone know how to do this?

dim ToolbarHeight as Integer = theWindow.Bounds.Height - theWindow.height + 1
if ToolbarHeight = 1 then Return -1'going FullScreen
1 Like

Thanks @Beatrix_Willius but no matter the window size, theWindow.Bounds.Height and theWindow.Height are always the same.

you can try:

Var compensation As Integer = display.displayAt(0).Height - theWindow.bounds.Height
This give the remainder of the display size, maybe you can get the content height trough window.height and compare that with “compensation” ?

Maybe it will give you some difference?

Possibly because there are no items on the toolbar?

1 Like

Yep. That was it :man_facepalming:

1 Like

It looks like you’re real close to getting your design all squared away, but you might also want to peak at https://github.com/thommcgrath/Beacon/blob/master/Project/Views/MainWindow.xojo_window as I’m using the same technique. I also have code their (albeit using MBS) to solve the click vs drag-to-move issue of the title bar area.

Thanks @Thom - that’s very helpful.