Hi,
i want to place my toolbar icons in different positions than left-aligned. Like it is on most OS X Apps.
See Safari Browser to see what i mean.
Is this possible with PureBasic?
toolbar icon positions
- thinkitsimple
- User
- Posts: 89
- Joined: Mon Aug 13, 2012 6:12 pm
- Location: Berlin, Germany
- Contact:
toolbar icon positions
Michael
PureBasic 5.51, macOS 10.12.2 Sierra
PureBasic 5.51, macOS 10.12.2 Sierra
Re: toolbar icon positions
Do you want to display left aligned, centered and right aligned buttons in the toolbar? I have already demonstrated how to display a right aligned button in the toolbar here (2nd code example).
For your conveniance I have extended that example to display a left aligned, centered and right aligned button. The trick is to insert a flexible space item (NSToolbarFlexibleSpaceItem) between two toolbar buttons:
For your conveniance I have extended that example to display a left aligned, centered and right aligned button. The trick is to insert a flexible space item (NSToolbarFlexibleSpaceItem) between two toolbar buttons:
Code: Select all
#NSToolbarSizeModeRegular = 1
OpenWindow(0, 270, 100, 450, 100,
"ToolBar with left aligned, centered and right aligned button")
CreateImage(0, 24, 24)
StartDrawing(ImageOutput(0))
Box(0, 0, 24, 24, $FF0000)
Box(4, 4, 16, 16, $FFFF)
StopDrawing()
CreateImage(1, 24, 24)
StartDrawing(ImageOutput(1))
Box(0, 0, 24, 24, $FF)
Box(4, 4, 16, 16, $FFFF)
StopDrawing()
CreateImage(2, 24, 24)
StartDrawing(ImageOutput(2))
Box(0, 0, 24, 24, $32CD32)
Box(4, 4, 16, 16, $FFFF)
StopDrawing()
CreateToolBar(0, WindowID(0))
CocoaMessage(0, ToolBarID(0), "setSizeMode:", #NSToolbarSizeModeRegular)
ToolBarImageButton(0, ImageID(0))
ToolBarImageButton(1, ImageID(1))
ToolBarImageButton(2, ImageID(2))
; ----- Count visible and invisible toolbar items
ItemCount = CocoaMessage(0, CocoaMessage(0, ToolBarID(0), "items"), "count")
If OSVersion() <= #PB_OS_MacOSX_10_6
; ----- Remove rightmost separator
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1
EndIf
; ----- Remove rightmost space
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1
; ----- Remove rightmost flexible space
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1
; ----- Insert flexible space between 1st and 2nd button
CocoaMessage(0, ToolBarID(0),
"insertItemWithItemIdentifier:$", @"NSToolbarFlexibleSpaceItem",
"atIndex:", 1)
; ----- Insert flexible space between 2nd and 3rd button
CocoaMessage(0, ToolBarID(0),
"insertItemWithItemIdentifier:$", @"NSToolbarFlexibleSpaceItem",
"atIndex:", 3)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: toolbar icon positions
Also investing is how to store the position and Icons if it is edit by user???
…The toolbar is always editable by right mouse click.
…The toolbar is always editable by right mouse click.
macOS Catalina 10.15.7
- thinkitsimple
- User
- Posts: 89
- Joined: Mon Aug 13, 2012 6:12 pm
- Location: Berlin, Germany
- Contact:
Re: toolbar icon positions
Thanks Shardik,
your code example does exactly what i was look for.
your code example does exactly what i was look for.
Michael
PureBasic 5.51, macOS 10.12.2 Sierra
PureBasic 5.51, macOS 10.12.2 Sierra