0

I need a graphical indication of signed "wrongness" of something, i.e. 0 is perfect, -1.0 is completely wrong in one direction, 0.3 is partly correct, but skewed to the right, 1.0 is completely wrong in the other direction. Sort of like a volt-meter.

I've searched and searched and the closest I've found was this thread: Bi-directional level indicator, but that seems to have ended abruptly, and the solution proposed doesn't seem to fit the poster's (or my) requirements.

I can't draw, but I've tried doing some crude mock-ups in IB to illustrate what I mean. The outer regions would be colored differently and there'd probably be axis information and other stuff in a final implementation. (Apparantly I'm not allowed to post images. I'll try ascii art instead)

Spot on:

[....|....]

Completely wrong to the left:

[|||||....]

Completely wrong to the right:

[....|||||]

Partly wrong:

[....|||..]

Now, I suppose I have a few options:

  1. Subclass NSLevelIndicator (or NSLevelIndicatorCell) I don't mind this, but I'm not quite sure how to do it. From searching the web I've found answers to questions such as changing style (rounded corners, fx) and reverse of critical coloring, but such solutions seem to imply a complete override of the drawing functions, which means you lose whatever NSLevelIndicator(Cell) is doing for you with the gradients and all. I had hoped it was possible to manipulate various variables and stay clear of the actual drawing.

  2. Create a custom view I'm not graphically minded in any way, but I suppose a start would be Apples custom view guide: Subclassing NSView. I'd like to use standard UI components as much as possible, as I'm sure Apple has better UI designers than me. I've done a custom 2D graph view earlier, which I think is OK, but that is really more of a custom view in my opinion.

  3. Borrow someone else's implementation (or look through for inspiration) I have searched but haven't found anything, which is odd as I would assume this would be a common setup. It doesn't have to resemble the NSLevelIndicator as such. It could be a volt-meter or similar.

So which approach do I take? If 1 or 3 I need some guiding. If 2 I would like to know if the Apple documentation is sufficient for a novice like myself, or if I need further information.

PS: Asking multiple questions in the same post is probably not wise, but consider it a bonus question. When subclassing NS* stuff, how do you know which methods to override? Apple's class reference only lists public methods as far as I can tell. What I do is create a subclass and then type "self." and see what appears, but that's not very easy to sort through.

  • In response to your PS question: you typically shouldn't override non-public methods in Cocoa classes. In general, you'll subclass less in Cocoa than in other frameworks/languages (although there are classes like `NSView` that are designed to be subclassed). – Gabriel Roth Apr 21 '14 at 14:29
  • Thanks. That makes sense. The examples I've seen overwrite drawRect, initWithFrame and such. I guess that's not the road I should take. – user1493187 Apr 21 '14 at 15:56
  • Oh, apparently I've been unclear. Overriding those methods is standard! See e.g. https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/drawRect: But that's a public method, it's declared right in the NSView.h file. – Gabriel Roth Apr 21 '14 at 19:52
  • No, you were quite clear. I should have realized those methods were from NSView. I'm glad I kept this sillyness as a post script. Thanks again. – user1493187 Apr 21 '14 at 21:29

1 Answers1

0

It is strange, maybe this is a recent apple update. But now NSLevelIndicator supports negative values as minimum. So one just need to set minimum value to -n and maximum to n. The 0 will be at the middle.

EdgarK
  • 870
  • 7
  • 10