Page 1 of 1

toolbar icon positions

Posted: Thu Sep 03, 2015 9:34 pm
by thinkitsimple
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?

Re: toolbar icon positions

Posted: Sat Sep 05, 2015 4:53 pm
by Shardik
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:

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

Posted: Sat Sep 05, 2015 10:18 pm
by Wolfram
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.

Re: toolbar icon positions

Posted: Sun Sep 06, 2015 5:14 pm
by thinkitsimple
Thanks Shardik,

your code example does exactly what i was look for.