fix: layout issues in macOS client torrent inspector window (#4366)

This commit is contained in:
SweetPPro
2022-12-17 05:27:37 +11:00
committed by GitHub
parent 0824c2da6d
commit 5d5893036d
9 changed files with 117 additions and 283 deletions

View File

@@ -48,24 +48,15 @@ static CGFloat const kStackViewSpacing = 8.0;
@property(nonatomic) IBOutlet NSTextField* fPeersConnectLabel;
@property(nonatomic) IBOutlet NSTextField* fPeersConnectField;
//remove when we switch to auto layout
@property(nonatomic) IBOutlet NSTextField* fTransferBandwidthSectionLabel;
@property(nonatomic) IBOutlet NSTextField* fPrioritySectionLabel;
@property(nonatomic) IBOutlet NSTextField* fPriorityLabel;
@property(nonatomic) IBOutlet NSTextField* fSeedingLimitsSectionLabel;
@property(nonatomic) IBOutlet NSTextField* fRatioLabel;
@property(nonatomic) IBOutlet NSTextField* fInactivityLabel;
@property(nonatomic) IBOutlet NSTextField* fAdvancedSectionLabel;
@property(nonatomic) IBOutlet NSTextField* fMaxConnectionsLabel;
@property(nonatomic, copy) NSString* fInitialString;
@property(nonatomic) IBOutlet NSStackView* fOptionsStackView;
@property(nonatomic) IBOutlet NSView* fSeedingView;
@property(nonatomic, readonly) CGFloat currentHeight;
@property(nonatomic, readonly) CGFloat horizLayoutHeight;
@property(nonatomic, readonly) CGFloat horizLayoutWidth;
@property(nonatomic, readonly) CGFloat vertLayoutHeight;
@property(nonatomic, readwrite) CGFloat fHeightChange;
@property(nonatomic, readwrite) CGFloat fCurrentHeight;
@property(nonatomic, readonly) CGFloat fHorizLayoutHeight;
@property(nonatomic, readonly) CGFloat fHorizLayoutWidth;
@property(nonatomic, readonly) CGFloat fVertLayoutHeight;
@end
@@ -83,6 +74,8 @@ static CGFloat const kStackViewSpacing = 8.0;
- (void)awakeFromNib
{
[self checkWindowSize];
[self setGlobalLabels];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(setGlobalLabels) name:@"UpdateGlobalOptions" object:nil];
@@ -96,47 +89,29 @@ static CGFloat const kStackViewSpacing = 8.0;
[NSNotificationCenter.defaultCenter removeObserver:self];
}
- (CGFloat)currentHeight
{
return NSHeight(self.view.frame);
}
- (CGFloat)horizLayoutHeight
- (CGFloat)fHorizLayoutHeight
{
return NSHeight(self.fPriorityView.frame) + 2 * kStackViewInset;
}
- (CGFloat)horizLayoutWidth
- (CGFloat)fHorizLayoutWidth
{
return NSWidth(self.fPriorityView.frame) + NSWidth(self.fSeedingView.frame) + (2 * kStackViewInset) + kStackViewSpacing;
}
- (CGFloat)vertLayoutHeight
- (CGFloat)fVertLayoutHeight
{
return NSHeight(self.fPriorityView.frame) + NSHeight(self.fSeedingView.frame) + (2 * kStackViewInset) + kStackViewSpacing;
}
- (CGFloat)changeInWindowHeight
- (CGFloat)fHeightChange
{
CGFloat difference = 0;
if (NSWidth(self.view.window.frame) >= self.horizLayoutWidth + 1)
{
self.fOptionsStackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
difference = NSHeight(self.view.frame) - self.horizLayoutHeight;
}
else
{
self.fOptionsStackView.orientation = NSUserInterfaceLayoutOrientationVertical;
difference = NSHeight(self.view.frame) - self.vertLayoutHeight;
}
return difference;
return self.oldHeight - self.fCurrentHeight;
}
- (NSRect)viewRect
{
CGFloat difference = self.changeInWindowHeight;
CGFloat difference = self.fHeightChange;
NSRect windowRect = self.view.window.frame, viewRect = self.view.frame;
if (difference != 0)
@@ -148,12 +123,40 @@ static CGFloat const kStackViewSpacing = 8.0;
return viewRect;
}
- (void)checkLayout
{
if (NSWidth(self.view.window.frame) >= self.fHorizLayoutWidth + 1)
{
self.fOptionsStackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
self.fCurrentHeight = self.fHorizLayoutHeight;
}
else
{
self.fOptionsStackView.orientation = NSUserInterfaceLayoutOrientationVertical;
self.fCurrentHeight = self.fVertLayoutHeight;
}
}
- (void)checkWindowSize
{
self.oldHeight = self.fCurrentHeight;
[self checkLayout];
if (self.oldHeight != self.fCurrentHeight)
{
[self updateWindowLayout];
}
}
- (void)updateWindowLayout
{
CGFloat difference = self.changeInWindowHeight;
if (difference != 0)
if (self.fCurrentHeight != 0)
{
[self checkLayout];
CGFloat difference = self.fHeightChange;
NSRect windowRect = self.view.window.frame;
windowRect.origin.y += difference;
windowRect.size.height -= difference;