OS X Control Tip - Native Yosemite Add/Del Buttons

I have been combing Mac OS Lib lately for little tidbits of cool OS X “stuff” and I came across the native Add/Delete buttons. Technically it is a segmented control and it looks absolutely fantastic in my app.

My App Example:

  1. Add the entire Mac OS Lib project to your project

  2. Add a “Segmented control” into your project on the IDE

  3. Add the “Action” and “Open” events to the segmented control

  4. Add the following to your “Open” event

  me.Items( 0 ).Icon = SystemIcons.AddTemplate
  me.ImageForSegment( 0 ).Template = True
  me.Items( 1 ).Icon = SystemIcons.RemoveTemplate
  me.ImageForSegment( 1 ).Template = True
  1. Add the following code to your “Action” event
If itemIndex = 0  Then
   // THIS THE INDEX FOR THE ADD (PLUS) BUTTON SEGMENT

  // Add your code here when users click the add button

Elseif itemIndex = 1 Then
    // THIS THE INDEX FOR THE DELETE (MINUS) BUTTON SEGMENT

   // Add your code here when users click the delete button
End If

That is it! :slight_smile:

Additional Links:

Mac OS Lib project:
https://github.com/macoslib/macoslib

I use the exact same image templates in App Wrapper 3, just not a segmented control (regular pushbuttons without the border).

By using these template images, on Mavericks, they appear engraved.

Awesome Sam thanks for Sharing!!! I never even though of using a pushbutton without a border. Awesome!

The last article I did for xDev was about getting some of these cool interface things going with your apps, using the system images sure does make life easier to generate consistent applications across the different versions of Aqua (although I still think should’a called the new interface Crayola).

The only downside to using system images, is that they’re not there on Windows or Linux. So if you’re targeting other platforms, you need to manually generate some graphics. Maybe a Windows guru can come in and help obtain some Windows system graphics.

[quote=142076:@Sam Rowlands]The last article I did for xDev was about getting some of these cool interface things going with your apps, using the system images sure does make life easier to generate consistent applications across the different versions of Aqua (although I still think should’a called the new interface Crayola).

The only downside to using system images, is that they’re not there on Windows or Linux. So if you’re targeting other platforms, you need to manually generate some graphics. Maybe a Windows guru can come in and help obtain some Windows system graphics.[/quote]

I am not a guru but have dabbed enough with the new API to tell you that apart from fundamentals such as windows and buttons that are styled by the system, there is no equivalent to the system supplied pictures. Well. Not quite. Windows uses fonts such as Segoe UI to provide symbols, and the closest they have of the Apple HIG for that is here:
http://msdn.microsoft.com/en-us/library/windows/apps/jj841126.aspx

Pushbutton.Open

Me.Bordered = False

I assume you are using this code to not have the borders on the pushbutton Sam?

[quote=142083:@Mike Cotrone]Pushbutton.Open

Me.Bordered = False

I assume you are using this code to not have the borders on the pushbutton Sam?[/quote]
Seems about right, the actual function name is “setBordered:”?

You also may want to check out setBackgroundStyle:

Also for displaying images you may want to take another look at the ImageWell, with the right declares it works a treat, although sadly not x-plat.

Mike,
It looks awesome and I tried the example from your opening post but I’m missing something.
With ‘Segmented Control’, do you mean an actual Xojo Segmented Control? If so, the standard segmented control doesn’t have a ‘ImageForSegment’ property so how does that work?
Also, with MacOSLib pasted in my project, ‘SystemIcons’ isn’t found.

[quote=202243:@Marco Hof]Mike,
It looks awesome and I tried the example from your opening post but I’m missing something.
With ‘Segmented Control’, do you mean an actual Xojo Segmented Control? If so, the standard segmented control doesn’t have a ‘ImageForSegment’ property so how does that work?
Also, with MacOSLib pasted in my project, ‘SystemIcons’ isn’t found.[/quote]

Hi Marco,

Yes I used the actual Segmented Control in Xojo.

This is a screen shot from one of my apps:

Can you share your code example that is giving you issues?

FWIW My final Arista Navigator release didn’t use the systemIcons as I found they weren’t retina friendly for me. I added two Mac Like + and - images both at @1 and @2.

Well, there isn’t a lot of code to show. :slight_smile:

When I do:

  • New project
  • Copy the complete macoslib directory
  • Paste the complete macoslib directory in the new project
  • Add a segmented control
  • Paste this code in the ‘Open’ method of the segmented control:
me.Items( 0 ).Icon = SystemIcons.AddTemplate
me.ImageForSegment( 0 ).Template = True
me.Items( 1 ).Icon = SystemIcons.RemoveTemplate
me.ImageForSegment( 1 ).Template = True
  • Hit run
  • Then I get these errors:

So I guess I’m missing something.

And I find it weird that images are more retina friendly than the SystemIcons. I assumed that these were native.

[quote=202249:@Marco Hof]Well, there isn’t a lot of code to show. :slight_smile:

When I do:

  • New project
  • Copy the complete macoslib directory
  • Paste the complete macoslib directory in the new project
  • Add a segmented control
  • Paste this code in the ‘Open’ method of the segmented control:
me.Items( 0 ).Icon = SystemIcons.AddTemplate
me.ImageForSegment( 0 ).Template = True
me.Items( 1 ).Icon = SystemIcons.RemoveTemplate
me.ImageForSegment( 1 ).Template = True
  • Hit run
  • Then I get these errors:

So I guess I’m missing something.

And I find it weird that images are more retina friendly than the SystemIcons. I assumed that these were native.[/quote]

Here is my final code specifically for my Segmented Control via Arista Navigator. It is different that my original post here.

(I am Using RetinaKit)
SegmentedControl.Open Event:

  Dim theAdd as HIDPIPicture = HIDPIPicture.imageNamed( "AddPlus" )
  Me.setIcon(0,theAdd)
  
  Dim theRemove as HIDPIPicture = HIDPIPicture.imageNamed( "RemoveMinus" )
  Me.setIcon(1,theRemove)
  
  Dim theS as SegmentedControlItem
  theS =Me.Items(1)
  theS.Enabled = False