NSPathControl and Auto Layout - objective-c

I'm having some issues with NSPathControl and Auto Layout.
I want the path control to resize with the window. Which means, if I expand the width of the window, the NSPathControl should expand too. This works.
Now the problem is, that if I change the URL of the path control to a longer URL, the path control expands automatically. I don't want that. I want the path control width to stay the same, except when the user resizes the window.
I tried pinning the width it, but then I can't resize the window at all...
Also, when I don't pin the window of the path control, I can't make it smaller than the actual content of the sub controls, which represent the URL.
Hope that makes sense.
How can I fix this?

No need for subclassing. You can tell your view how much to resist compression. By default the priority is set to NSLayoutPriorityDefaultHigh. You are probably looking for NSLayoutPriorityDragThatCannotResizeWindow. You can set this in your XIB in the Size Inspector for the control or take a look at NSView's setContentCompressionResistancePriority:forOrientation:.

Solution
Sorry, I guess I asked to fast.
I got it working like this:
NSPathControl subclass
- (NSSize)intrinsicContentSize {
return NSMakeSize(NSViewNoInstrinsicMetric, NSViewNoInstrinsicMetric);
}

Related

Allow user to resize window such that Gtk3 TextView component can't show all text

I'm working on a GTK program in Rust (someone can probably answer this if they don't know Rust, as I can figure out how to translate between different bindings and the native C API) via the gtk-rs bindings for which I want to have a non-editable TextView who's contents are constantly updated in my code. I want the user to be able to resize the TextView to any size, after which my code will re-calculate its contents accordingly. Unfortunately, GTK prevents any resize from taking place that would hide any contents that are current in the TextView. I can't use a ScrolledWindow because I don't want visible scrollbars, and disabling the scrollbars on a ScrolledWindow prevents the resizing behavior that I want. I also tried calling set_size_request to set the size to both 1, 1, and 0, 0 after every text change, but this does not change the behavior at all either — the user still can't properly resize the TextView (by resizing the window).
How can I enable the resizing behavior that I want?
Probably this is not possible. What would be the point of resizing the text view smaller, if the user can never see the text that is outside of the viewport because you don't want scrollbars? That seems like it would confound the user's expectation of how such a component would usually work.
Maybe an approach could be that you pick a certain number of lines to show, make that the size of the viewport, and delete the old contents of the text view that scroll outside of the viewport?

wxWidget: How do change the size of the parent Sizer according to the size of the children sizers?

this is a question about wxBoxSizer. I am implementing a custom wxWidget like collapsible pane.
The problem is: I have a wxBoxSizer (Sizer1), and I add another wxBoxSizer (Sizer2) as its child. If I change the size of Sizer2, How do I make Sizer1 update it's size, automatically or manually?
I have tried to call Fit() and Layout() on Sizer1 after I call SetSize() on Sizer2, but it doesn't change the size for Sizer1.
Please help, thank you!
Layout in wxWidgets always works from top to bottom and changing the size of a sub-window or sub-sizer will never change the size of the containing window on its own. If you do want this to happen, call Fit() on the parent window to tell it that should become as big as required by its children. Notice that calling it on the panel will still not be enough, you need to do it on the top level wxFrame or wxDialog itself, unless you have some free space in it which can be used to accommodate the increasing panel size.
wxBoxSizer1 already occupies the whole panel. So unless you change the size of the panel itself, the wxBoxSizer1 wont be resized. You might want to try another size as your main sizer such as wxFlexGridSizer. Here you have more choices for precise control.

Is there a tutorial somewhere about designing a really large view and put it in scrollView using storyboard

The question may be similar with
Designing inside a scrollview in xcode 4.2 with storyboards
but none of the answer there makes sense at all.
Okay I created a new controller and I added a scrollView.
The very first thing I noticed is there is NOWHERE to specify the content size of the scrollView.
Not in attributes inspector, not in size inspector.
Then what?
I am expecting some larger than normal box where I can draw all the view I want to put in. There is no such thing either.
I am very frustated.
All the "tutorial" out there tell about how to fill scrollView using code.
Another thing I tried is to select controller go to size inspector and then choose FREEFORM.
Great. I still can't make that template big.
Should I do this in XIB instead? At least on that one I can have one huge UIView. Or what is the official way industry standard way of doing this? Is there a WWDC for this one?
Say I want to draw something like these:
I don't think you can get a tutorial on this as it is simply impossible in IB. As most people already commented out what you want to do here need to be done programmatically.
If you are using XIB you can set up all your content there. Under the size tab (in the inspector) you will need to change the height to fill all your content but you still need to set up your contentSize programmatically.
For storyboard I don't think it is possible to change the size of your scrollview in IB.

IKImageView and scroll bars

I have an NSScrollView with an IKImageView inside to display images. This seems to work.
However, if I make the window smaller than the image, the scrollbars appear as they should, but the BOTTOM of the image is locked to the bottom of the window, instead of the top of the image being locked to the top of the window. In other words, I want the image to not move on the screen when I re-size the window from the bottom right.
I understand why this is, because in All of these classes, the origin is in the lower left, not the upper left. However, It's still behaving wrong. If you look at any other product (including Preview, which I assume is written with some of these libraries) the image/content/whatever, is locked to the top not the bottom.
How do I do this?
I've looked for methods in the NSScrollView and IKImageView. I've considered capturing the scroller events and manually moving the image down or up as appropriate, but I haven't seen a way to do this (Set the selector to a method I write in the controller?) and anyway, that seems very messy...
Is there an easy way to do this?
thanks.
Solution for future reference:
Make a subclass of IKImageView with only one over-ridden method:
-isFlipped()
{
return YES;
}
This subclass will also prove useful if I find that I need to re-implement the rotate:(id) method and the setImage:(NSImage) method which exist in the class (and in the case of rotate are USED IN THE DEMO supplied by Apple) but not documented, and therefore not officially supported...

Changing how IKImageBrowserView indicates the drop position

I can make a single row IKImageBrowserView by setting the
[imageBrowser setContentResizingMask:NSViewWidthSizable];
but in this case while i drag an image inside image browser to rearrange it, the drop place highlights with horizontal line(vertical line expected).
how can this be changed?
Many thanks.
There is no defined way to do what you want.
You may be better off writing your own custom view where you can control every detail of how things are drawn. In general, Apple's controls are "as-is" and unless they provide an explicit way to control behavior or mention that you can custom an object in some way, don't count on being able to do it easily (if at all).
I would also suggest heading to http://bugreport.apple.com and making the enhancement request - it would be best if you attached a sample application demonstrating the behavior.
EDIT: You could also try out the NSCollectionView to see if it might work for you.