It is currently Thu Feb 22, 2018 6:12 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: toolbar icon positions
PostPosted: Thu Sep 03, 2015 9:34 pm 
Offline
User
User
User avatar

Joined: Mon Aug 13, 2012 6:12 pm
Posts: 89
Location: Berlin, Germany
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?

_________________
Michael

PureBasic 5.51, macOS 10.12.2 Sierra


Top
 Profile  
Reply with quote  
 Post subject: Re: toolbar icon positions
PostPosted: Sat Sep 05, 2015 4:53 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1485
Location: Germany
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:
#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


Top
 Profile  
Reply with quote  
 Post subject: Re: toolbar icon positions
PostPosted: Sat Sep 05, 2015 10:18 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 372
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: toolbar icon positions
PostPosted: Sun Sep 06, 2015 5:14 pm 
Offline
User
User
User avatar

Joined: Mon Aug 13, 2012 6:12 pm
Posts: 89
Location: Berlin, Germany
Thanks Shardik,

your code example does exactly what i was look for.

_________________
Michael

PureBasic 5.51, macOS 10.12.2 Sierra


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye