Re-add layout code that was mistakenly removed

This commit is contained in:
ethanc8 2024-02-05 14:43:31 -06:00
parent 882de64435
commit 61c9699021

View file

@ -5166,8 +5166,277 @@ static NSView* findByTag(NSView *view, NSInteger aTag, NSUInteger *level)
return;
}
/**
* Layout
*/
- (void) layout
{
GSAutoLayoutEngine *engine = [self _layoutEngine];
if (!engine)
{
return;
}
NSArray *subviews = [self subviews];
FOR_IN (NSView *, subview, subviews)
NSRect subviewAlignmentRect =
[engine alignmentRectForView: subview];
[subview setFrame: subviewAlignmentRect];
END_FOR_IN (subviews);
}
- (void) layoutSubtreeIfNeeded
{
[self updateConstraintsForSubtreeIfNeeded];
[self _layoutViewAndSubViews];
}
- (void) setNeedsLayout: (BOOL) needsLayout
{
if (!needsLayout)
{
return;
}
_needsLayout = needsLayout;
}
- (BOOL) needsLayout
{
return _needsLayout;
}
- (void) setNeedsUpdateConstraints: (BOOL)needsUpdateConstraints
{
// Calling setNeedsUpdateConstraints with NO should not have an effect
if (!needsUpdateConstraints)
{
return;
}
_needsUpdateConstraints = YES;
}
- (BOOL) needsUpdateConstraints
{
return _needsUpdateConstraints;
}
- (void) setTranslatesAutoresizingMaskIntoConstraints: (BOOL)translate
{
_translatesAutoresizingMaskIntoConstraints = translate;
}
- (BOOL) translatesAutoresizingMaskIntoConstraints
{
return _translatesAutoresizingMaskIntoConstraints;
}
- (NSLayoutPriority) contentCompressionResistancePriority
{
return _contentCompressionResistancePriority;
}
- (void) setContentCompressionResistancePriority: (NSLayoutPriority)priority
{
_contentCompressionResistancePriority = priority;
}
- (NSSize) intrinsicContentSize
{
return NSMakeSize(NSViewNoIntrinsicMetric, NSViewNoIntrinsicMetric);
}
- (CGFloat) baselineOffsetFromBottom
{
return 0;
}
- (CGFloat) firstBaselineOffsetFromTop
{
return 0;
}
@end
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
@implementation NSView (NSConstraintBasedLayoutCorePrivateMethods)
// This private setter allows the updateConstraints method to toggle needsUpdateConstraints
- (void) _setNeedsUpdateConstraints: (BOOL)needsUpdateConstraints
{
_needsUpdateConstraints = needsUpdateConstraints;
}
- (void) _layoutViewAndSubViews
{
if (_needsLayout)
{
[self layout];
_needsLayout = NO;
}
NSArray *subviews = [self subviews];
FOR_IN (NSView *, subview, subviews)
[subview _layoutViewAndSubViews];
END_FOR_IN (subviews);
}
- (GSAutoLayoutEngine*) _layoutEngine
{
if (![self window])
{
return nil;
}
return [[self window] _layoutEngine];
}
- (void) _layoutEngineDidChangeAlignmentRect
{
[[self superview] setNeedsLayout: YES];
}
- (GSAutoLayoutEngine*) _getOrCreateLayoutEngine
{
if (![self window])
{
return nil;
}
if (![[self window] _layoutEngine])
{
[[self window] _bootstrapAutoLayout];
}
return [[self window] _layoutEngine];
}
@end
@implementation NSView (NSConstraintBasedLayoutCoreMethods)
- (void) updateConstraintsForSubtreeIfNeeded
{
NSArray *subviews = [self subviews];
FOR_IN (NSView *, subview, subviews)
[subview updateConstraintsForSubtreeIfNeeded];
END_FOR_IN (subviews);
if ([self needsUpdateConstraints])
{
[self updateConstraints];
}
}
- (void) updateConstraints
{
if ([self translatesAutoresizingMaskIntoConstraints] &&
[self superview] != nil)
{
NSArray *autoresizingConstraints = [NSAutoresizingMaskLayoutConstraint
constraintsWithAutoresizingMask: [self autoresizingMask]
subitem: self
frame: [self frame]
superitem: [self superview]
bounds: [[self superview] bounds]];
[self addConstraints: autoresizingConstraints];
}
[self _setNeedsUpdateConstraints: NO];
}
- (NSLayoutPriority) contentCompressionResistancePriorityForOrientation: (NSLayoutConstraintOrientation)orientation {
if (orientation == NSLayoutConstraintOrientationHorizontal) {
return _compressionPriorities.horizontal;
} else {
return _compressionPriorities.vertical;
}
}
- (void) setContentCompressionResistancePriority: (NSLayoutPriority)priority forOrientation: (NSLayoutConstraintOrientation)orientation {
if (orientation == NSLayoutConstraintOrientationHorizontal) {
_compressionPriorities.horizontal = priority;
} else {
_compressionPriorities.vertical = priority;
}
}
- (NSLayoutPriority) contentHuggingPriorityForOrientation: (NSLayoutConstraintOrientation)orientation {
if (orientation == NSLayoutConstraintOrientationHorizontal) {
return _huggingPriorities.horizontal;
} else {
return _huggingPriorities.vertical;
}
}
- (void) setContentHuggingPriority: (NSLayoutPriority)priority forOrientation: (NSLayoutConstraintOrientation)orientation
{
if (orientation == NSLayoutConstraintOrientationHorizontal) {
_huggingPriorities.horizontal = priority;
} else {
_huggingPriorities.vertical = priority;
}
}
@end
@implementation NSView (NSConstraintBasedLayoutInstallingConstraints)
- (void) addConstraint: (NSLayoutConstraint *)constraint
{
if (![self _getOrCreateLayoutEngine])
{
return;
}
[[self _layoutEngine] addConstraint: constraint];
}
- (void) addConstraints: (NSArray*)constraints
{
if (![self _getOrCreateLayoutEngine])
{
return;
}
[[self _layoutEngine] addConstraints: constraints];
}
- (void) removeConstraint: (NSLayoutConstraint *)constraint
{
if (![self _layoutEngine])
{
return;
}
[[self _layoutEngine] removeConstraint: constraint];
}
- (void) removeConstraints: (NSArray *)constraints
{
if (![self _layoutEngine])
{
return;
}
[[self _layoutEngine] removeConstraints: constraints];
}
- (NSArray*) constraints
{
GSAutoLayoutEngine *engine = [self _layoutEngine];
if (!engine)
{
return [NSArray array];
}
return [engine constraintsForView: self];
}
@end
#endif
@implementation NSView (__NSViewPrivateMethods__)
/*