1

I have a Source-View (NSOutlineView) with two Buttons at the bottom. I added an NSBox so that the items don't "shine through" when they're behind the buttons.

This works fine when the window is active:

enter image description here

But as soon as I deactivate the window the NSBox still has that active color, rather than a dimmed version to match the NSOutlineView's background color:

enter image description here

How can I make sure that those two colors always match. Also using a specific color is a bit of a hack since the color NSOutline uses might change at some point.

Update: Apple's Mail.app as well as Things seem to have a solution for that problem. :-/

Besi
  • 22,579
  • 24
  • 131
  • 223
  • No, do you have one? :-) I am currently using the NSView to shield the buttons from the scroll view in the background. However, Apple Mail does that and Things (from Cultured Code). I wonder how they do it. – Besi Oct 22 '13 at 11:35

3 Answers3

2

@Neha put me on the right way to find a solution.

I write it in Ruby because I work with Rubymotion but it's easy to translate :)

Assuming you have a box outlet for the NSBox, you can set it to transparent when the window loses the focus and do the opposite when it becomes the key window, using the appropriate delegate methods:

  def windowDidBecomeKey(notification)
    box.setTransparent(false)
  end

  def windowDidResignKey(notification)
    box.setTransparent(true)
  end

And the result looks fine with the focus:

enter image description here

And without it:

enter image description here

siekfried
  • 2,964
  • 1
  • 21
  • 36
1

The solution is to keep a reference to the NSOutlineView's backgroundColor property as it is a special NSColor that dynamically changes depending on the key status of the parent window. Set the color of your custom view to that that reference. When the window loses/gains key status, call setNeedsDisplay: on your custom view to redraw it using the new color. Use KVO to observe NSWindowDidBecomeKeyNotification and NSWindowDidResignKeyNotification. Note that pointer to the color stays the same, but the actual color represented by the reference changes. The solution is explained here.

Andrew
  • 7,630
  • 3
  • 42
  • 51
0

In the attributes inspector of NSBox, set display to transparent

Besi
  • 22,579
  • 24
  • 131
  • 223
Neha
  • 1,751
  • 14
  • 36
  • Well but then the items "shine through" again and I wouldn't need the box in the first place – Besi Oct 15 '13 at 11:23