NSAlert accessory view fill horizontal space, respecting margins
NSAlert accessory view fill horizontal space, respecting margins
- Subject: NSAlert accessory view fill horizontal space, respecting margins
- From: Tor Arne Vestbø via Cocoa-dev <email@hidden>
- Date: Wed, 2 Nov 2022 11:12:01 +0000
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=qt.io; dmarc=pass action=none header.from=qt.io; dkim=pass header.d=qt.io; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dm+qgUSuRWqwbtVZEGl5gfJuD3nEdrF2kprIlSQMI9w=; b=G6YHU+K5cvu3J0eQyHBJmhK1bfuhBHU90N45IL6J/ZgpMcPWl+lU3UDG865qbAI8v+NxGMLoP59n7AkfDHAx1TXTkWHWatxMX7KlEn/Oe2MopOrnPn7viHQwyi3lgY8jucEuEb8UfFkDd099fpwxPfa7LhmIx6NL3FYJHaP/evpdtaUXjOflXFJrRennzn6mAyrTn6WeimfZBXeLISkW086EnP+v+E9CiwNL/OU+zuaqall4njrC71K+bNds802WAI4D0QvHXjfDlC2MO2E2o2udr+0D9e8tIJMandY/gYOtmdvL8w/J7wS8pWd55UuI/KVyy+SAvl3qtp1Qv4uchQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GERPh2fGB+PMNo3UT0u+4m/f4OYlGfgUf6L+P2g4kkPXFpMO+/I84m2BsuRDDMquEe/NIvDxqV+G66DOVrNp1LdTUV7r0hXwFP312JLXyxF7YV1egDN1Qb7PGk90xeD9uyvRyX+SP/CRLDtZVW7qv0NEpI7rWW09POHF/h8cT8aRfRwEORvqKGqgqknaXg8+xIemSKJ/tXJLXOIYBuTDY2Whgljye0i134fm4nIMNT5TvCSiNCsO4w2c621zLG6RL1i2Lp8UH4FaeIblvDoyJGB7zPVV0KHM2ZzADczQbiKZCLJf4pKlwVrH2iJfnLcSumm4XR1RGeNvZ+LRIhbaxA==
- Thread-topic: NSAlert accessory view fill horizontal space, respecting margins
Hi all,
I’m trying to get the accessory view of an NSAlert to layout similarity to the
the text fields of the messageText and informativeText. That is:
* Fill the the available horizontal space of the alert, respecting margins
* Including accounting for the different margins of the normal and wide
appearance
* Overflow any content of the accessory view by increasing its height
* Never contributing to increasing the width of the alert itself
But attempts at doing this with auto layout constraints have failed me, as
merely setting translatesAutoresizingMaskIntoConstraints = NO for my view to
set up constraints seems to break the margins that NSAlert applies to the
accessory view, and I don’t know how to restore them.
Looking at the disassembly of NSAlert
(_buildLayoutConstraintsForWideAppearance e.g.) it seems to use constraint
based layout, with the accessory view is wrapped inside another view
(accessoryContainer), but if I print out the constraints of the views in play
all I see are instances of NSAutoresizingMaskLayoutConstraint. And inspecting
the views in the hierarchy, they all respond YES to
translatesAutoresizingMaskIntoConstraints. Perhaps this is a red herring, but
shouldn’t I be seeing non-autoresizing constants here?
How would one expand the accessory view to fill its superview
(accessoryContainer), in a way that keeps the accessoryContainer’s position and
margins in both normal and wide apperance?
Here’s a reproducer of some of the things I’m seeing:
#import <Cocoa/Cocoa.h>
int main()
{
bool triggerWideApperance = true;
NSString *loremIpsum = @"Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
loremIpsum = [@"" stringByPaddingToLength:(triggerWideApperance ? 5 : 1) *
loremIpsum.length withString:loremIpsum startingAtIndex:0];
NSAlert *alert = [NSAlert new];
alert.messageText = loremIpsum;
alert.informativeText = loremIpsum;
// Attempt 1: Disables the wide alert apperance, making the alert super wide
alert.accessoryView = [NSTextField wrappingLabelWithString:loremIpsum];
// Attempt 2: Retains the wide alert apperance, but loses the left margin
of the accessory view,
alert.accessoryView = [NSStackView stackViewWithViews:@[
[NSTextField wrappingLabelWithString:loremIpsum]
]];
[alert layout];
[alert runModal];
}
Thanks for any tips or insights on this!
Cheers,
Tor Arne
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden