Mojave System Accent Color

  1. 6 months ago

    Controls like checkboxes, popup menus do respect the users accent color choice, is there a way to get this for custom controls?
    I can find the HighlightColor but not something like AccentColor.

  2. Ulrich B

    Dec 30 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    https://xojo.gitbook.io/add-ons/cstruecolors/documentation/nscoloraddition#controlaccent_color-as-color .
    Or MBS or probably MacOSLib or Declares.

  3. @Ulrich B, thanks for the link. I've tried with macOSlib, there's a appearance-class, but this one is still carbon and does not fire if returning to default blue. As xojo provides the highlight color I've just made a method returning the color hard coded dependent of the highlight color, fine enough for now. But I think xojo should provide this property.

  4. 3 weeks ago

    Horst J

    May 29 Pre-Release Testers, Xojo Pro Europe, Germany, Stuttgart

    If you have MBS Plugins, you can use this:

    Public Function GetSystemAccentColor() as Color
    dim ns as new NSButtonMBS
    dim n as NSColorMBS
    n = ns.backgroundColor.controlAccentColor
    return n.colorValue
    End Function

  5. Thomas E

    May 29 Pre-Release Testers

    oh really: A big Plugin for just getting a color?

    I prefer a few declares:

    Public Function controlAccentColor() as Color
      Declare Function NSClassFromString  Lib "AppKit" (aClassName As CFStringRef) As Ptr
      Declare Function controlAccentColor Lib "AppKit" selector "controlAccentColor" (ob_id As Ptr) As Ptr
      Declare Function getRedComponent    Lib "AppKit" selector "redComponent"(ob_id As Ptr) As CGFloat
      Declare Function getGreenComponent  Lib "AppKit" selector "greenComponent"(ob_id As Ptr) As CGFloat
      Declare Function getBlueComponent   Lib "AppKit" selector "blueComponent"(ob_id As Ptr) As CGFloat
      Declare Function getAlphaComponent  Lib "AppKit" selector "alphaComponent"(ob_id As Ptr) As CGFloat
      Declare Function colorUsingColorSpaceName Lib "AppKit" selector "colorUsingColorSpaceName:"(ob_id As Ptr, csName As CFStringRef) As Ptr
      
      Dim c As Ptr = controlAccentColor(NSClassFromString("NSColor"))
      c = colorUsingColorSpaceName(c, "NSCalibratedRGBColorSpace")
      
      Dim r As Integer = getRedComponent(c)*255
      Dim g As Integer = getGreenComponent(c)*255
      Dim b As Integer = getBlueComponent(c)*255
      Dim a As Integer = 256-getAlphaComponent(c)*255
      
      Return RGB(r, g, b, a)
    End Function
  6. Tim P

    May 29 Pre-Release Testers Rochester, NY

    I like how simple plugins make things, I've used MBS in several projects. But if you don't have them the declare is very helpful, thank you! To those using the declare and plugin, keep in mind that controlAccentColor is 10.14+ so wrap it in an "respondsToSelector" check.

    What I don't understand is why we don't have access to the color via Xojo code. Listbox clearly has access to it, so why isn't it exposed to us? :(

  7. Thomas E

    May 29 Pre-Release Testers

    @Tim P To those using the declare and plugin, keep in mind that controlAccentColor is 10.14+ so wrap it in an "respondsToSelector" check.

    Good catch. Thank you.

    What I don't understand is why we don't have access to the color via Xojo code. Listbox clearly has access to it, so why isn't it exposed to us? :(

    Full ACK

or Sign Up to reply!