mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
Merge pull request #172 from BennyKJohnson/bootstrap-layout-engine
This commit is contained in:
commit
81f21e2094
10 changed files with 301 additions and 21 deletions
|
@ -30,6 +30,7 @@
|
|||
#import <Foundation/NSKeyedArchiver.h>
|
||||
#import <AppKit/NSLayoutAnchor.h>
|
||||
#import <AppKit/NSView.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
|
||||
@class NSControl, NSAnimation, NSArray, NSMutableArray, NSDictionary;
|
||||
|
||||
|
@ -183,6 +184,14 @@ APPKIT_EXPORT_CLASS
|
|||
|
||||
@end
|
||||
|
||||
@interface NSWindow (NSConstraintBasedLayoutCoreMethods)
|
||||
|
||||
- (void) _bootstrapAutoLayout;
|
||||
|
||||
- (void) layoutIfNeeded;
|
||||
|
||||
@end
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
@class NSViewController;
|
||||
|
||||
@class GSWindowDecorationView;
|
||||
@class GSAutoLayoutEngine;
|
||||
|
||||
/*
|
||||
* Window levels are taken from MacOS-X
|
||||
|
@ -240,6 +241,7 @@ APPKIT_EXPORT_CLASS
|
|||
id _firstResponder;
|
||||
id _futureFirstResponder;
|
||||
NSView *_initialFirstResponder;
|
||||
GSAutoLayoutEngine *_layoutEngine;
|
||||
PACKAGE_SCOPE
|
||||
id _delegate;
|
||||
@protected
|
||||
|
|
|
@ -356,6 +356,7 @@ GSXibLoading.m \
|
|||
GSXibKeyedUnarchiver.m \
|
||||
GSXib5KeyedUnarchiver.m \
|
||||
GSHelpAttachment.m \
|
||||
GSAutoLayoutEngine.m \
|
||||
GSAutoLayoutVFLParser.m
|
||||
|
||||
# Turn off NSMenuItem warning that NSMenuItem conforms to <NSObject>,
|
||||
|
@ -671,7 +672,8 @@ GSXibElement.h \
|
|||
GSXibLoading.h \
|
||||
GSXibKeyedUnarchiver.h \
|
||||
GSHelpAttachment.h \
|
||||
GSAutoLayoutVFLParser.h
|
||||
GSAutoLayoutVFLParser.h \
|
||||
GSAutoLayoutEngine.h
|
||||
|
||||
libgnustep-gui_HEADER_FILES = ${GUI_HEADERS}
|
||||
|
||||
|
|
48
Source/GSAutoLayoutEngine.h
Normal file
48
Source/GSAutoLayoutEngine.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* Copyright (C) 2023 Free Software Foundation, Inc.
|
||||
|
||||
By: Benjamin Johnson
|
||||
Date: 28-2-2023
|
||||
This file is part of the GNUstep Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#import "AppKit/NSLayoutConstraint.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class NSView;
|
||||
@class NSLayoutConstraint;
|
||||
|
||||
#ifndef _GS_AUTO_LAYOUT_ENGINE_H
|
||||
#define _GS_AUTO_LAYOUT_ENGINE_H
|
||||
|
||||
@interface GSAutoLayoutEngine : NSObject
|
||||
|
||||
- (void) addConstraint: (NSLayoutConstraint *)constraint;
|
||||
|
||||
- (void) addConstraints: (NSArray *)constraints;
|
||||
|
||||
- (void) removeConstraint: (NSLayoutConstraint *)constraint;
|
||||
|
||||
- (void) removeConstraints: (NSArray *)constraints;
|
||||
|
||||
- (NSRect) alignmentRectForView: (NSView *)view;
|
||||
|
||||
- (NSArray *) constraintsForView: (NSView *)view;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
60
Source/GSAutoLayoutEngine.m
Normal file
60
Source/GSAutoLayoutEngine.m
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* Copyright (C) 2023 Free Software Foundation, Inc.
|
||||
|
||||
By: Benjamin Johnson
|
||||
Date: 28-2-2023
|
||||
This file is part of the GNUstep Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#import "GSAutoLayoutEngine.h"
|
||||
#include "AppKit/NSLayoutConstraint.h"
|
||||
|
||||
@implementation GSAutoLayoutEngine
|
||||
|
||||
- (void) addConstraint: (NSLayoutConstraint *)constraint
|
||||
{
|
||||
// FIXME Add constraint to solver
|
||||
}
|
||||
|
||||
- (void) addConstraints: (NSArray *)constraints
|
||||
{
|
||||
// FIXME Add constraints to solver
|
||||
}
|
||||
|
||||
- (void) removeConstraint: (NSLayoutConstraint *)constraint
|
||||
{
|
||||
// FIXME Remove constraint from solver
|
||||
}
|
||||
|
||||
- (void) removeConstraints: (NSArray *)constraints
|
||||
{
|
||||
// FIXME Remove constraints from solver
|
||||
}
|
||||
|
||||
- (NSRect) alignmentRectForView: (NSView *)view
|
||||
{
|
||||
// FIXME Get alignment rect for view from solver
|
||||
return NSMakeRect (0, 0, 0, 0);
|
||||
}
|
||||
|
||||
- (NSArray *) constraintsForView: (NSView *)view
|
||||
{
|
||||
// FIXME Get constraints for view
|
||||
return [NSArray array];
|
||||
}
|
||||
|
||||
@end
|
|
@ -31,11 +31,13 @@
|
|||
#import "AppKit/NSAnimation.h"
|
||||
#import "AppKit/NSLayoutConstraint.h"
|
||||
#import "NSViewPrivate.h"
|
||||
#import "NSWindowPrivate.h"
|
||||
#import "AppKit/NSWindow.h"
|
||||
#import "AppKit/NSApplication.h"
|
||||
#import "NSAutoresizingMaskLayoutConstraint.h"
|
||||
#import "GSFastEnumeration.h"
|
||||
#import "GSAutoLayoutVFLParser.h"
|
||||
#import "GSAutoLayoutEngine.h"
|
||||
|
||||
static NSMutableArray *activeConstraints = nil;
|
||||
// static NSNotificationCenter *nc = nil;
|
||||
|
@ -652,16 +654,91 @@ static NSMutableArray *activeConstraints = nil;
|
|||
|
||||
@implementation NSView (NSConstraintBasedLayoutInstallingConstraints)
|
||||
|
||||
- (GSAutoLayoutEngine*) _getOrCreateLayoutEngine
|
||||
{
|
||||
if (![self window])
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
if (![[self window] _layoutEngine])
|
||||
{
|
||||
[[self window] _bootstrapAutoLayout];
|
||||
}
|
||||
|
||||
return [[self window] _layoutEngine];
|
||||
}
|
||||
|
||||
- (void) addConstraint: (NSLayoutConstraint *)constraint
|
||||
{
|
||||
// FIXME: Implement adding constraint to layout engine
|
||||
if (![self _getOrCreateLayoutEngine])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
[[self _layoutEngine] addConstraint: constraint];
|
||||
}
|
||||
|
||||
- (void) addConstraints: (NSArray*)constraints
|
||||
{
|
||||
FOR_IN (NSLayoutConstraint*, constraint, constraints)
|
||||
[self addConstraint: constraint];
|
||||
END_FOR_IN (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
|
||||
|
||||
@implementation NSWindow (NSConstraintBasedLayoutCoreMethods)
|
||||
|
||||
- (void) layoutIfNeeded
|
||||
{
|
||||
[self updateConstraintsIfNeeded];
|
||||
[[self contentView] _layoutViewAndSubViews];
|
||||
}
|
||||
|
||||
- (void) updateConstraintsIfNeeded
|
||||
{
|
||||
[[self contentView] updateConstraintsForSubtreeIfNeeded];
|
||||
}
|
||||
|
||||
- (void) _bootstrapAutoLayout
|
||||
{
|
||||
GSAutoLayoutEngine *layoutEngine = [[GSAutoLayoutEngine alloc] init];
|
||||
[self _setLayoutEngine: layoutEngine];
|
||||
RELEASE(layoutEngine);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -79,7 +79,9 @@
|
|||
#import "GSBindingHelpers.h"
|
||||
#import "GSFastEnumeration.h"
|
||||
#import "GSGuiPrivate.h"
|
||||
#import "GSAutoLayoutEngine.h"
|
||||
#import "NSViewPrivate.h"
|
||||
#import "NSWindowPrivate.h"
|
||||
|
||||
/*
|
||||
* We need a fast array that can store objects without retain/release ...
|
||||
|
@ -635,7 +637,7 @@ GSSetDragTypes(NSView* obj, NSArray *types)
|
|||
|
||||
_needsUpdateConstraints = YES;
|
||||
_translatesAutoresizingMaskIntoConstraints = YES;
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -5140,7 +5142,18 @@ static NSView* findByTag(NSView *view, NSInteger aTag, NSUInteger *level)
|
|||
|
||||
- (void) layout
|
||||
{
|
||||
// FIXME: Implement asking layout engine for the alignment rect of each subview and set the alignment rect of each sub view
|
||||
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
|
||||
|
@ -5149,20 +5162,6 @@ static NSView* findByTag(NSView *view, NSInteger aTag, NSUInteger *level)
|
|||
[self _layoutViewAndSubViews];
|
||||
}
|
||||
|
||||
- (void) _layoutViewAndSubViews
|
||||
{
|
||||
if (_needsLayout)
|
||||
{
|
||||
[self layout];
|
||||
_needsLayout = NO;
|
||||
}
|
||||
|
||||
NSArray *subviews = [self subviews];
|
||||
FOR_IN (NSView *, subview, subviews)
|
||||
[subview _layoutViewAndSubViews];
|
||||
END_FOR_IN (subviews);
|
||||
}
|
||||
|
||||
- (void) setNeedsLayout: (BOOL) needsLayout
|
||||
{
|
||||
if (!needsLayout)
|
||||
|
@ -5212,6 +5211,30 @@ static NSView* findByTag(NSView *view, NSInteger aTag, NSUInteger *level)
|
|||
_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];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSView (__NSViewPrivateMethods__)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define _GNUstep_H_NSViewPrivate
|
||||
|
||||
#import "AppKit/NSView.h"
|
||||
#import "GSAutoLayoutEngine.h"
|
||||
|
||||
@interface NSView (KeyViewLoop)
|
||||
- (void) _setUpKeyViewLoopWithNextKeyView: (NSView *)nextKeyView;
|
||||
|
@ -42,6 +43,10 @@
|
|||
|
||||
- (void) _setNeedsUpdateConstraints: (BOOL)needsUpdateConstraints;
|
||||
|
||||
- (void) _layoutViewAndSubViews;
|
||||
|
||||
- (GSAutoLayoutEngine*) _layoutEngine;
|
||||
|
||||
@end
|
||||
|
||||
#endif // _GNUstep_H_NSViewPrivate
|
||||
|
|
|
@ -89,8 +89,10 @@
|
|||
#import "GSGuiPrivate.h"
|
||||
#import "GSToolTips.h"
|
||||
#import "GSIconManager.h"
|
||||
#import "GSAutoLayoutEngine.h"
|
||||
#import "NSToolbarFrameworkPrivate.h"
|
||||
#import "NSViewPrivate.h"
|
||||
#import "NSWindowPrivate.h"
|
||||
|
||||
#define GSI_ARRAY_TYPES 0
|
||||
#define GSI_ARRAY_TYPE NSWindow *
|
||||
|
@ -923,6 +925,8 @@ many times.
|
|||
DESTROY(_lastDragView);
|
||||
DESTROY(_screen);
|
||||
|
||||
TEST_RELEASE(_layoutEngine);
|
||||
|
||||
/*
|
||||
* FIXME This should not be necessary - the views should have removed
|
||||
* their drag types, so we should already have been removed.
|
||||
|
@ -6156,6 +6160,20 @@ current key view.<br />
|
|||
}
|
||||
@end
|
||||
|
||||
@implementation NSWindow (NSConstraintBasedLayoutCorePrivateMethods)
|
||||
|
||||
- (GSAutoLayoutEngine*) _layoutEngine
|
||||
{
|
||||
return _layoutEngine;
|
||||
}
|
||||
|
||||
- (void) _setLayoutEngine: (GSAutoLayoutEngine*)layoutEngine
|
||||
{
|
||||
ASSIGN(_layoutEngine, layoutEngine);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
BOOL GSViewAcceptsDrag(NSView *v, id<NSDraggingInfo> dragInfo)
|
||||
{
|
||||
NSPasteboard *pb = [dragInfo draggingPasteboard];
|
||||
|
|
36
Source/NSWindowPrivate.h
Normal file
36
Source/NSWindowPrivate.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* Copyright (C) 2023 Free Software Foundation, Inc.
|
||||
|
||||
By: Benjamin Johnson
|
||||
Date: 28-2-2023
|
||||
This file is part of the GNUstep Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GNUstep_H_NSWindowPrivate
|
||||
#define _GNUstep_H_NSWindowPrivate
|
||||
|
||||
#import "AppKit/NSWindow.h"
|
||||
|
||||
@interface NSWindow (NSConstraintBasedLayoutCorePrivateMethods)
|
||||
|
||||
- (GSAutoLayoutEngine*) _layoutEngine;
|
||||
|
||||
- (void) _setLayoutEngine: (GSAutoLayoutEngine*)layoutEngine;
|
||||
|
||||
@end
|
||||
|
||||
#endif // _GNUstep_H_NSWindowPrivate
|
Loading…
Reference in a new issue