JustSid / JUInspectorView

A shameless Xcode 4 inspector view clone.
59 stars 6 forks source link

Is there a way to have dynamic height views in an inspector? #4

Open brendand opened 11 years ago

brendand commented 11 years ago

I have a couple of inspectors on the right side in a panel. The top one is a fixed size, but I'd like the bottom view to stretch to fit the remaining space of the surrounding view. The reason for that is I have a table view in the bottom inspector panel and if the window is resized enough, you can't scroll the table view to see the bottom rows. This is because the inspector panel seems to want only a fixed height panel. It would be great if it could size so that my table view would always show the bottom of its content no matter how tall or short the inspector panel is.

JustSid commented 11 years ago

Mhhh, I guess a dirty solution would be to call arrangeViews on the container every time the frame of the inspector pane changes. But honestly, the whole layouting is terrible and should be rewritten (possibly using auto-layout, but I fear that the adaption of it isn't really there yet).

Anyways, for now, arrangeViews should work mayhaps, let me know. And I guess I'll use this as an opportunity to actually rewrite this project and make it more modern and flexible.

brendand commented 11 years ago

I just tried this, but couldn't get it working.

Here's what I did:

I first told my view controller's view to post frame changed notifications:

[self.view setPostsFrameChangedNotifications:YES];

Then I observed them:

[defaultCenter addObserver:self
          selector:@selector(handleViewBoundsChanged:)
          name:NSViewFrameDidChangeNotification
        object:self.view];

and then I handled them:

- (void)handleViewBoundsChanged:(NSNotification *)notification {
    [self.inspectorContainer arrangeViews];
}

Is that what you were suggesting? My handleViewBoundsChanged method did get called whenever I resized my window. But nothing changed.

Could there be a magical incantation through the use of auto resizing masks that would make this work? I'm not using Auto-layout in my app.

Thanks!

Brendan

JustSid commented 11 years ago

Yup, that's pretty much what I meant, however, you also need to update the frame of the inspector as well, and then call arrangeViews. They are in a scrollview, so auto-resizing masks won't work here, iirc.

You can put them out of the scrollview and into a normal view and then use auto-resizing masks, but that would require you to rewrite a few bits and pieces since the inspector container depends on being inside a clipping view. Calculating the required height, setting it and then calling arrangeViews is pretty dirty, but it should work for now and is the simplest to implement, so I would go with that.

brendand commented 11 years ago

I used to have it in a scrollView, but I took it out because the user could get into a situation where the inspector wasn't tall enough for both my panels to be in view at the same time, they could scroll the inspector so the table view area was the only thing in view, but then couldn't get back up because the table view was now taking the scroll events.

I'll try putting it back into a scrollview and then see what happens.

Thanks for your help with this and thanks for making this component. It's very useful.

brendand commented 11 years ago

Ok, so I added the following code:

- (void)handleViewBoundsChanged:(NSNotification *)notification {
    NSSize inspectorFrameSize = self.inspectorContainer.frame.size;
    inspectorFrameSize.height = self.view.frame.size.height - self.toolsControl.frame.size.height;
    [self.inspectorContainer setFrameSize:inspectorFrameSize];
    [self.inspectorContainer arrangeViews];
}

But it didn't seem to have any effect.

My inspectorContainer is of class JUInspectorViewContainer

I think I may need to just switch to a couple of regular views. The top one containing my static height views that I swap in with different inspectors, and my bottom view that has my scrollable NSTableViews. It's too bad because I like the collapsible inspector panels that you have. The way it should work I guess is that if I collapse the top panel, the bottom panel shouldn't just move up, but it should stretch to fill the space made available by the collapsed top panel view.