I’m trying to get a toolbar on my project that the user can choose to show text or not and icons big, small and none. I think I recall it requires declares, but can’t find them anywhere.
But how do I set a property so the toolbar shows large or small icons, or incons and no text for example? That’s where I am confused.
I may be wrong, but you cant with this ToolBar.
You may think at some third party ToolBar or I may be wrong.
Someone ?
Yes, I think it needs declares on macOS. I know I did it once way back in RealBasic, but I don’t have the code for that project anymore.
from https://forum.xojo.com/36311-setting-toolbar-height/0#p296941
[code]Declare Function toolbar Lib “Cocoa” Selector “toolbar” (NSWindow As Ptr) As Ptr
Dim toolbarPtr As Ptr = toolbar(Ptr(Self.Handle))
Declare Sub setShowsBaselineSeparator Lib “Cocoa” Selector “setShowsBaselineSeparator:” _
(NSToolbar As Ptr, flag As Boolean)
setShowsBaselineSeparator(toolbarPtr, false)
Declare Sub setDisplayMode Lib “Cocoa” Selector “setDisplayMode:” _
(NSToolbar As Ptr, NSToolbarDisplayMode As UInteger)
Const ToolbarDisplayModeDefault = 0
Const ToolbarDisplayModeIconAndLabel = 1
Const ToolbarDisplayModeIconOnly = 2
Const ToolbarDisplayModeLabelOnly = 3
setDisplayMode(toolbarPtr, ToolbarDisplayModeIconOnly)
Declare Sub setSizeMode Lib “Cocoa” Selector “setSizeMode:” _
(NSToolbar As Ptr, NSToolbarSizeMode As UInteger)
Const NSToolbarSizeModeDefault = 0
Const NSToolbarSizeModeRegular = 1
Const NSToolbarSizeModeSmall = 2
setSizeMode(toolbarPtr, NSToolbarSizeModeSmall)[/code]
you can also make a containercontrol containing your icons and texts, and embed it at the top of the window.
Great, thanks. Now just double-checking.
I created a module called Generic.Toolbar and in it a method named NativeToolBar (probably sould rename that, but it’s just a macOS app for me only) with the parameters (w as Window, d as UInteger, s as UInteger)
In it I pasted all the above replacing a few things with the parameters variables like this:
[code] Declare Function toolbar Lib “Cocoa” Selector “toolbar” (NSWindow As Ptr) As Ptr
Dim toolbarPtr As Ptr = toolbar(Ptr(w.Handle))
Declare Sub setShowsBaselineSeparator Lib "Cocoa" Selector "setShowsBaselineSeparator:" _
(NSToolbar As Ptr, flag As Boolean)
setShowsBaselineSeparator(toolbarPtr, false)
Declare Sub setDisplayMode Lib "Cocoa" Selector "setDisplayMode:" _
(NSToolbar As Ptr, NSToolbarDisplayMode As UInteger)
Const ToolbarDisplayModeDefault = 0
Const ToolbarDisplayModeIconAndLabel = 1
Const ToolbarDisplayModeIconOnly = 2
Const ToolbarDisplayModeLabelOnly = 3
setDisplayMode(toolbarPtr, d)
Declare Sub setSizeMode Lib "Cocoa" Selector "setSizeMode:" _
(NSToolbar As Ptr, NSToolbarSizeMode As UInteger)
Const NSToolbarSizeModeDefault = 0
Const NSToolbarSizeModeRegular = 1
Const NSToolbarSizeModeSmall = 2
setSizeMode(toolbarPtr, s)[/code]
Then my window code has this code in its open event (which I know I could call later from a menuitem for example so the user can change it):
GenericToolbar.NativeToolBar(self,3,0)
Is that more or less the correct way to do this? It seems to work…