mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
Refactor layout core methods implementation to use ivars
This commit is contained in:
parent
571ad7a613
commit
75fcf49b62
5 changed files with 62 additions and 82 deletions
|
@ -167,30 +167,12 @@ APPKIT_EXPORT_CLASS
|
|||
|
||||
@end
|
||||
|
||||
@interface NSView (NSConstraintBasedCompatibility)
|
||||
|
||||
#if GS_HAS_DECLARED_PROPERTIES
|
||||
@property BOOL translatesAutoresizingMaskIntoConstraints;
|
||||
#else
|
||||
- (BOOL) translatesAutoresizingMaskIntoConstraints;
|
||||
- (void) setTranslatesAutoresizingMaskIntoConstraints: (BOOL)translatesAutoresizingMaskIntoConstraints;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@interface NSView (NSConstraintBasedLayoutCoreMethods)
|
||||
|
||||
- (void) updateConstraints;
|
||||
|
||||
- (void) updateConstraintsForSubtreeIfNeeded;
|
||||
|
||||
#if GS_HAS_DECLARED_PROPERTIES
|
||||
@property BOOL needsUpdateConstraints;
|
||||
#else
|
||||
- (BOOL) needsUpdateConstraints;
|
||||
- (void) setNeedsUpdateConstraints: (BOOL)needsUpdateConstraints;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@interface NSView (NSConstraintBasedLayoutInstallingConstraints)
|
||||
|
|
|
@ -180,6 +180,8 @@ PACKAGE_SCOPE
|
|||
BOOL _is_hidden;
|
||||
BOOL _in_live_resize;
|
||||
BOOL _needsLayout;
|
||||
BOOL _needsUpdateConstraints;
|
||||
BOOL _translatesAutoresizingMaskIntoConstraints;
|
||||
|
||||
NSUInteger _autoresizingMask;
|
||||
NSFocusRingType _focusRingType;
|
||||
|
@ -656,6 +658,20 @@ PACKAGE_SCOPE
|
|||
-(BOOL) needsLayout;
|
||||
-(void) setNeedsLayout: (BOOL)needsLayout;
|
||||
#endif
|
||||
|
||||
#if GS_HAS_DECLARED_PROPERTIES
|
||||
@property (nonatomic) BOOL needsUpdateConstraints;
|
||||
#else
|
||||
- (BOOL) needsUpdateConstraints;
|
||||
- (void) setNeedsUpdateConstraints: (BOOL)needsUpdateConstraints;
|
||||
#endif
|
||||
|
||||
#if GS_HAS_DECLARED_PROPERTIES
|
||||
@property BOOL translatesAutoresizingMaskIntoConstraints;
|
||||
#else
|
||||
- (BOOL) translatesAutoresizingMaskIntoConstraints;
|
||||
- (void) setTranslatesAutoresizingMaskIntoConstraints: (BOOL)translatesAutoresizingMaskIntoConstraints;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#import "AppKit/NSView.h"
|
||||
#import "AppKit/NSAnimation.h"
|
||||
#import "AppKit/NSLayoutConstraint.h"
|
||||
#import "NSViewPrivate.h"
|
||||
#import "AppKit/NSWindow.h"
|
||||
#import "AppKit/NSApplication.h"
|
||||
#import "NSAutoresizingMaskLayoutConstraint.h"
|
||||
|
@ -615,40 +616,8 @@ static NSMutableArray *activeConstraints = nil;
|
|||
|
||||
@end
|
||||
|
||||
@implementation NSView (NSConstraintBasedCompatibility)
|
||||
|
||||
NSString static const *translatesAutoresizingMaskKey
|
||||
= @"NSConstraintBasedCompatibility.translatesAutoresizingMaskKey";
|
||||
|
||||
- (void) setTranslatesAutoresizingMaskIntoConstraints: (BOOL)translate
|
||||
{
|
||||
NSValue *value = [NSValue valueWithBytes: &translate objCType: @encode (BOOL)];
|
||||
objc_setAssociatedObject(self, &translatesAutoresizingMaskKey, value,
|
||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (BOOL) translatesAutoresizingMaskIntoConstraints
|
||||
{
|
||||
NSValue *value
|
||||
= objc_getAssociatedObject(self, &translatesAutoresizingMaskKey);
|
||||
if (value == nil)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
BOOL translate;
|
||||
[value getValue:&translate];
|
||||
|
||||
return translate;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSView (NSConstraintBasedLayoutCoreMethods)
|
||||
|
||||
NSString static const *needsUpdateConstraintsKey
|
||||
= @"NSConstraintBasedLayoutCoreMethods.needsUpdateConstraintsKey";
|
||||
|
||||
- (void) updateConstraintsForSubtreeIfNeeded
|
||||
{
|
||||
NSArray *subviews = [self subviews];
|
||||
|
@ -675,39 +644,8 @@ NSString static const *needsUpdateConstraintsKey
|
|||
bounds: [[self superview] bounds]];
|
||||
[self addConstraints:autoresizingConstraints];
|
||||
}
|
||||
[self _setNeedsUpdateConstraints:NO];
|
||||
}
|
||||
|
||||
- (void)_setNeedsUpdateConstraints: (BOOL) needsUpdateConstraints
|
||||
{
|
||||
NSValue *value = [NSValue valueWithBytes: &needsUpdateConstraints
|
||||
objCType: @encode (BOOL)];
|
||||
objc_setAssociatedObject (self, &needsUpdateConstraintsKey, value,
|
||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (void) setNeedsUpdateConstraints: (BOOL)needsUpdateConstraints
|
||||
{
|
||||
if (!needsUpdateConstraints)
|
||||
{
|
||||
return;
|
||||
}
|
||||
[self _setNeedsUpdateConstraints:YES];
|
||||
}
|
||||
|
||||
- (BOOL) needsUpdateConstraints
|
||||
{
|
||||
NSValue *needsUpdateConstraintsValue
|
||||
= objc_getAssociatedObject (self, &needsUpdateConstraintsKey);
|
||||
if (needsUpdateConstraintsValue == nil)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
BOOL needsUpdateConstraints;
|
||||
[needsUpdateConstraintsValue getValue:&needsUpdateConstraints];
|
||||
|
||||
return needsUpdateConstraints;
|
||||
[self _setNeedsUpdateConstraints: NO];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -632,6 +632,9 @@ GSSetDragTypes(NSView* obj, NSArray *types)
|
|||
//_previousKeyView = 0;
|
||||
|
||||
_alphaValue = 1.0;
|
||||
|
||||
_needsUpdateConstraints = YES;
|
||||
_translatesAutoresizingMaskIntoConstraints = YES;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -5174,6 +5177,41 @@ static NSView* findByTag(NSView *view, NSInteger aTag, NSUInteger *level)
|
|||
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;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSView (NSConstraintBasedLayoutCorePrivateMethods)
|
||||
// This private setter allows the updateConstraints method to toggle needsUpdateConstraints
|
||||
- (void) _setNeedsUpdateConstraints: (BOOL)needsUpdateConstraints
|
||||
{
|
||||
_needsUpdateConstraints = needsUpdateConstraints;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSView (__NSViewPrivateMethods__)
|
||||
|
|
|
@ -38,4 +38,10 @@
|
|||
- (void) _insertSubview: (NSView *)sv atIndex: (NSUInteger)idx;
|
||||
@end
|
||||
|
||||
@interface NSView (NSConstraintBasedLayoutCorePrivateMethods)
|
||||
|
||||
- (void) _setNeedsUpdateConstraints: (BOOL)needsUpdateConstraints;
|
||||
|
||||
@end
|
||||
|
||||
#endif // _GNUstep_H_NSViewPrivate
|
||||
|
|
Loading…
Reference in a new issue