Re: Can NSView and NSImageView respond to Mouse Clicks?
Sean McBride
On Thu, 20 Sep 2018 11:36:10 +0200, Dave said:
Basically, I want to detect a Mouse Down on an NSView Subclass and whenSuggestion: open NSView.h and search for "menu", there are API like menuForEvent: and willOpenMenu: that look useful for your case. Cheers, Sean
|
|
Re: Updating to Xcode 10
Alex Zavatone
Did you change your linked library to the new C++ one?
toggle quoted messageShow quoted text
On Sep 20, 2018, at 2:32 AM, John Brownie <john_brownie@sil.org> wrote:
|
|
Re: Adjusting Font Size to fit View Rectangle
On 20 Sep 2018, at 2:51 am, Dave <dave@looktowindward.com> wrote:UILabel has `adjustsFontSizeToFitWidth` and `minimumScaleFactor` properties that aim to support that type of thing automatically. Could you employ it? b
|
|
Re: Updating to Xcode 10
I build a lot of C++ and I don’t think I’ve ever seen that. Are you overriding the header search path or specifying any exotic compiler flags already? And double-check that you’ve got a valid SDK selected. ‘-std=libc++’ seems fishy to me, since the value of -std is supposed to be a language version like “c++11”. —Jens
|
|
Re: Adjusting Font Size to fit View Rectangle
Alex Zavatone
You also might want to check the height of a descender appears below the bounding NSTextField.
toggle quoted messageShow quoted text
On Sep 20, 2018, at 5:21 AM, Dave <dave@looktowindward.com> wrote:
|
|
Re: Segue
I'm not sure I am understanding your problem correctly, but I am wondering about the exact layout of your storyboard. Specifically, are you using a UISplitViewController? The Push (Detail) segue is specific to it.
On an iPhone (particularly in portrait mode), the push-detail segue looks like a simple push, but it is not. You can see this when running on an iPad in Simulator, where you will see both the TableViewController and the Detail controller (in whole or with part of it covered by the TableViewController) side by side. The push detail segue brings the detail controller to the front, covering (hiding) the TableViewController. On a phone, this just looks like a push. If you don't have a split-view controller, then the segue can't do that (i.e., it can't call UISplitViewController.showDetailViewController) and is apparently doing a simple UIViewController.present instead. If I'm off on a mistaken tangent here, please excuse the waste of bandwidth. Rick Aurbach
|
|
Re: Adjusting Font Size to fit View Rectangle
Sandor Szatmari
Yes, I’m sure single line (text field) instead of multiline (text view) can be accomplished with less rigor. Let me know if you find anything interesting.
toggle quoted messageShow quoted text
Sandor
On Sep 20, 2018, at 09:12, Dave <dave@...> wrote:
|
|
Re: Adjusting Font Size to fit View Rectangle
Alex Zavatone
I do think that based on your requirements, there will have been others who have solved this. I just found a few solutions on Stack Overflow that could be adopted to MacOS.
toggle quoted messageShow quoted text
Will send off list.
On Sep 20, 2018, at 4:51 AM, Dave <dave@looktowindward.com> wrote:
|
|
Re: Adjusting Font Size to fit View Rectangle
Dave
Hi,
toggle quoted messageShow quoted text
I think it should work ok on iOS, will find out soon, there maybe some differences in method names etc. I should have been more clear, this is for a single line, it should work for multiple lines too, but probably not as well as your suggestion, which is overkill for what I want it for. All the Best Dave
|
|
Re: Adjusting Font Size to fit View Rectangle
Sandor Szatmari
This was for macOS… not sure how to go about it on iOS. I’d guess it would work, but there may be an easier method. I don’t know though.
toggle quoted messageShow quoted text
I have used this method to dynamically size formatted multiline text (text that includes line breaks) to find the maximum font size for a fixed container size. Granted there may be an easier solution that I am not aware of, but I am also counting the number of line of text being laid out, so this solution works for me. 1. Get text 2. Setup your mutable paragraph style, set properties, justification, wrapping… etc. 3. Create a layout manager… set properties, hyphenation, etc. Important, set the layout mgr’s delegate (I used self for simplicity). You will receive callbacks about the layout process via delegation. 3a. Define delegate method -layoutManager:didCompleteLayoutForTextContainer:atEnd: (you will receive these callbacks where you can flag ‘clipping’ I.e. text too big) set a flag here indicating clipping has occurred. I used an iVar. 4. Create a mutable attributes dict, this contains the para style keyed on NSParagraphStyleAttributeName. (You will add/update the font later stored in this dict with different sizes later) 5. Create a text storage object with text and para style 6. Now loop… do while (notClipped && other things you care about) Loop Body a. Adjust font size b. Create new NSFont object with new size. Set font in attributes dict keyed on NSFontAttributeName c. Adjust paragraph style as needed/desired (optional) d. Reapply (Set) the updated attributes dict for the entire range of text in your text storage object -setAtteibutes:range: e. Ask the layout manager/text storage to layout the text. If the text is too big the container parameter in your callback will be nil indicating that ‘clipping’ occurred. Use nil container to flag clipping thus communicating with your loop. Rinse, repeat… till desired font size reached The text generated using this approach is displayed in widgets that are part of a complex visual graph of objects all of which are the same size and which contain dynamic multiline text. I have additional logic that counts the number of lines to ensure that there are always three lines. Each line contains a different property of the object being represented. IP, hostname, etc… Think graphical displays of networks and such, with text inside the network components. Sandor
On Sep 20, 2018, at 05:51, Dave <dave@looktowindward.com> wrote:
|
|
Adding Action Methods to Controls
Dave
Ignore this, was a silly bug in that the identifier wasn’t setup correctly!
|
|
Adding Action Methods to Controls
Dave
Hi,
I’ve created an NSButton Class and added an Action to it as so: myButton = [[NSButton alloc] initWithFrame:myButtonFrameRect]; myButton.image = myImage; myButton.imageScaling = NSImageScaleProportionallyUpOrDown; self.pCellButton = myButton; self.pCellButton.target = self; [self.pCellButton sendActionOn:NSEventMaskLeftMouseDown]; [self.pCellButton setAction:@selector(performCellSelected:)]; [self addSubview:self.pCellButton]; -(void) performCellSelected:(id) theSender { NSLog(@"performCellSelected: theSender: %@", theSender.identifier); } This works ok, EXCEPT the parameter pass in “theSender” is nil???? I would have thought it should be the NSButton object that the Action was sent from is this not the case? All the Best Dave
|
|
Re: Adjusting Font Size to fit View Rectangle
Dave
Hi,
toggle quoted messageShow quoted text
Couldn’t find it so wrote my own: (NSInteger) adjustFontSize:(NSInteger) theFontSize toFitWidth:(NSInteger) theWidth { NSInteger myFontSize; NSFont* myFont; NSSize myContentSize; myFontSize = theFontSize; while (YES) { myFont = [NSFont fontWithName:self.font.fontName size:myFontSize]; [self setFont:myFont]; myContentSize = [self.attributedStringValue size]; if (myContentSize.width < theWidth) break; myFontSize--; if (myFontSize <= 0) break; } return myFontSize; } This is on an NSTextField subclass and works a treat! All the Best Dave
On 20 Sep 2018, at 11:51, Dave <dave@looktowindward.com> wrote:
|
|
Re: Adjusting Font Size to fit View Rectangle
Dave
Hi,
toggle quoted messageShow quoted text
Those two methods alter the frame size, I want to keep the same Frame Size but reduce the Font Size of the Content until it fit into the Displayable Area. I’m 99% sure there is a method to do it but maybe its iOS only? All the Best Dave
On 20 Sep 2018, at 02:02, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:
|
|
Re: Can NSView and NSImageView respond to Mouse Clicks?
Dave
Hi,
toggle quoted messageShow quoted text
This is for NSView, I’ve not looked into NSImageView as yet. I tried adding a Gesture Recognizer which sort of work except the Handler gets calls more than nice when I mouse down. Basically, I want to detect a Mouse Down on an NSView Subclass and when it occurs display a Pop-Up Menu. Don’t understand why I'm getting multiple calls - see code below. All the Best Dave -(instancetype) initWithCoder:(NSCoder*) theDecoder { self = [super initWithCoder:theDecoder]; if (self == nil) return nil; NSLog(@"initWithCoder: %@",self.identifier); [self setupView]; return self; } -(void) setupView { NSPressGestureRecognizer* myGestureRecognizer; myGestureRecognizer = [[NSPressGestureRecognizer alloc] initWithTarget:self action:@selector(actionPressGesture:)]; myGestureRecognizer.minimumPressDuration = 0.001; myGestureRecognizer.buttonMask = 1; myGestureRecognizer.delaysPrimaryMouseButtonEvents = NO; [self addGestureRecognizer:myGestureRecognizer]; } -(void) actionPressGesture:(LTWTestViewCell*) theSender { NSLog(@"actionPressGesture: %@",self.identifier); }
On 20 Sep 2018, at 02:03, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:
|
|
Updating to Xcode 10
John Brownie
After a hiatus of some months, I'm back to programming, and just got Xcode 10 installed. When I go to build, I get all kinds of changes suggested. I make some, but then I get stuck some that I cannot work out. My project is a mixture of Objective-C, Objective-C++, C++, and a little Swift (in a separate target).
When I start to build the first target, clang gives the the warning: warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found] OK, so I add a compiler flag as suggested, and I get the following warnings: error: invalid value 'libc++' in '-std=libc++' note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard note: use 'c++11' for 'ISO C++ 2011 with amendments' standard note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard note: use 'c++14' for 'ISO C++ 2014 with amendments' standard note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard note: use 'c++17' for 'ISO C++ 2017 with amendments' standard note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard Using one of those (c++11), brings me back to the first warning. And then the compiler can't find the standard library headers (e.g. <algorithm>), anyway. One of the suggested changes was "Update C++ Standard Library", so I reverted to pre-changes and didn't make that change, which got me to the second set of warnings. Anyone have an idea how to break out of this cycle? John -- John Brownie Mussau-Emira language, New Ireland Province, Papua New Guinea Kouvola, Finland
|
|
Re: Can NSView and NSImageView respond to Mouse Clicks?
Alex Zavatone
You can add a gesture to it IIRC.
toggle quoted messageShow quoted text
On Sep 19, 2018, at 1:34 PM, Dave <dave@looktowindward.com> wrote:
|
|
Re: Adjusting Font Size to fit View Rectangle
Alex Zavatone
There are two that I am aware of. sizeToFit and sizeThatFits.
toggle quoted messageShow quoted text
On Sep 19, 2018, at 1:29 PM, Dave <dave@looktowindward.com> wrote:
|
|
Re: Can NSView and NSImageView respond to Mouse Clicks?
Andy Lee
On Sep 19, 2018, at 2:34 PM, Dave <dave@looktowindward.com> wrote:
Can the same be done with NSImageView? I’ve added an image view and connected it to an IBAction method define in my View Controller, but when I click the NSImageView nothing happens…..From the docs: <https://developer.apple.com/documentation/appkit/nsimageview?language=objc> Note--Andy
|
|
Re: Can NSView and NSImageView respond to Mouse Clicks?
Keary Suska
NSView doesn’t have action handling—you get that from NSControl. If you need action handling, you might need an NSControl subclass rather than an NSView subclass. That being said, you can call your action method “manually” in an event handler for NSView.
toggle quoted messageShow quoted text
As for NSImageView, It doesn’t look like you can specify action handling in Xcode. Have you tried calling -sendActionOn: on your image view? Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business"
On Sep 19, 2018, at 12:34 PM, Dave <dave@looktowindward.com> wrote:
|
|