Skip to content

Commit

Permalink
refactor: rewrite FontSizeHintView with SnapKit (#274)
Browse files Browse the repository at this point in the history
* perf: add comment for EZErrorTypeNone

* chore: add library SwiftShell

* chore: add library SnapKit

* refactor: rewrite FontSizeHintView with SnapKit
  • Loading branch information
tisfeng authored Dec 25, 2023
1 parent 00c7d88 commit 4d6d0cc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 37 deletions.
34 changes: 34 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
03008B2E2941956D0062B821 /* EZURLSchemeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 03008B2D2941956D0062B821 /* EZURLSchemeHandler.m */; };
03008B3F29444B0A0062B821 /* NSView+EZAnimatedHidden.m in Sources */ = {isa = PBXBuildFile; fileRef = 03008B3E29444B0A0062B821 /* NSView+EZAnimatedHidden.m */; };
03022F1C2B35DEBA00B63209 /* Hue in Frameworks */ = {isa = PBXBuildFile; productRef = 03022F1B2B35DEBA00B63209 /* Hue */; };
03022F1F2B36CF3100B63209 /* SwiftShell in Frameworks */ = {isa = PBXBuildFile; productRef = 03022F1E2B36CF3100B63209 /* SwiftShell */; };
03022F222B36D1A400B63209 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 03022F212B36D1A400B63209 /* SnapKit */; };
030570E22ADB919900C9905E /* EZAppleScriptManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 030570E12ADB919900C9905E /* EZAppleScriptManager.m */; };
0309E1ED292B439A00AFB76A /* EZTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0309E1EC292B439A00AFB76A /* EZTextView.m */; };
0309E1F0292B4A5E00AFB76A /* NSView+EZGetViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0309E1EF292B4A5E00AFB76A /* NSView+EZGetViewController.m */; };
Expand Down Expand Up @@ -704,7 +706,9 @@
buildActionMask = 2147483647;
files = (
2721E4D02AFE920700A059AC /* Alamofire in Frameworks */,
03022F1F2B36CF3100B63209 /* SwiftShell in Frameworks */,
03FD68BB2B1DC59600FD388E /* CryptoSwift in Frameworks */,
03022F222B36D1A400B63209 /* SnapKit in Frameworks */,
B87AC7E36367075BA5D13234 /* Pods_Easydict.framework in Frameworks */,
03022F1C2B35DEBA00B63209 /* Hue in Frameworks */,
03B63ABF2A86967800E155ED /* CoreServices.framework in Frameworks */,
Expand Down Expand Up @@ -2060,6 +2064,8 @@
2721E4CF2AFE920700A059AC /* Alamofire */,
03FD68BA2B1DC59600FD388E /* CryptoSwift */,
03022F1B2B35DEBA00B63209 /* Hue */,
03022F1E2B36CF3100B63209 /* SwiftShell */,
03022F212B36D1A400B63209 /* SnapKit */,
);
productName = Bob;
productReference = C99EEB182385796700FEE666 /* Easydict-debug.app */;
Expand Down Expand Up @@ -2103,6 +2109,8 @@
2721E4CE2AFE920700A059AC /* XCRemoteSwiftPackageReference "Alamofire" */,
03FD68B92B1DC59600FD388E /* XCRemoteSwiftPackageReference "CryptoSwift" */,
03022F1A2B35DEBA00B63209 /* XCRemoteSwiftPackageReference "Hue" */,
03022F1D2B36CF3100B63209 /* XCRemoteSwiftPackageReference "SwiftShell" */,
03022F202B36D1A300B63209 /* XCRemoteSwiftPackageReference "SnapKit" */,
);
productRefGroup = C99EEB192385796700FEE666 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -2867,6 +2875,22 @@
minimumVersion = 5.0.1;
};
};
03022F1D2B36CF3100B63209 /* XCRemoteSwiftPackageReference "SwiftShell" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/kareman/SwiftShell";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.1.0;
};
};
03022F202B36D1A300B63209 /* XCRemoteSwiftPackageReference "SnapKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/SnapKit/SnapKit";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.6.0;
};
};
03FD68B92B1DC59600FD388E /* XCRemoteSwiftPackageReference "CryptoSwift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/krzyzanowskim/CryptoSwift";
Expand All @@ -2891,6 +2915,16 @@
package = 03022F1A2B35DEBA00B63209 /* XCRemoteSwiftPackageReference "Hue" */;
productName = Hue;
};
03022F1E2B36CF3100B63209 /* SwiftShell */ = {
isa = XCSwiftPackageProductDependency;
package = 03022F1D2B36CF3100B63209 /* XCRemoteSwiftPackageReference "SwiftShell" */;
productName = SwiftShell;
};
03022F212B36D1A400B63209 /* SnapKit */ = {
isa = XCSwiftPackageProductDependency;
package = 03022F202B36D1A300B63209 /* XCRemoteSwiftPackageReference "SnapKit" */;
productName = SnapKit;
};
03FD68BA2B1DC59600FD388E /* CryptoSwift */ = {
isa = XCSwiftPackageProductDependency;
package = 03FD68B92B1DC59600FD388E /* XCRemoteSwiftPackageReference "CryptoSwift" */;
Expand Down
18 changes: 18 additions & 0 deletions Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@
"revision" : "b9d920cee4ba795fefb828d130744eee1e3d2feb",
"version" : "5.0.1"
}
},
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SnapKit/SnapKit",
"state" : {
"revision" : "f222cbdf325885926566172f6f5f06af95473158",
"version" : "5.6.0"
}
},
{
"identity" : "swiftshell",
"kind" : "remoteSourceControl",
"location" : "https://github.com/kareman/SwiftShell",
"state" : {
"revision" : "99680b2efc7c7dbcace1da0b3979d266f02e213c",
"version" : "5.1.0"
}
}
],
"version" : 2
Expand Down
10 changes: 6 additions & 4 deletions Easydict/Feature/PerferenceWindow/EZSettingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -772,20 +772,22 @@ - (void)updateViewConstraints {

[self.fontSizeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.autoGetSelectedTextLabel);
make.top.equalTo(self.showAppleDictionaryQuickLinkButton.mas_bottom).offset(self.verticalPadding);
make.top.equalTo(self.showAppleDictionaryQuickLinkButton.mas_bottom).offset(20);
}];

CGFloat changeFontSizeViewWidth = 200;
[self.changeFontSizeView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.fontSizeLabel.mas_right).offset(self.horizontalPadding + 2);
make.centerY.equalTo(self.fontSizeLabel);
make.width.mas_equalTo(200);
make.width.mas_equalTo(changeFontSizeViewWidth);
make.height.mas_equalTo(30);
}];

[self.fontSizeHintView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.fontSizeLabel.mas_right).offset(self.horizontalPadding);
make.top.equalTo(self.changeFontSizeView.mas_bottom).mas_offset(5);
make.width.mas_equalTo(300);
make.top.equalTo(self.changeFontSizeView.mas_bottom).mas_offset(8);
make.width.mas_equalTo(changeFontSizeViewWidth + 5);
make.height.mas_equalTo(45);
}];

[self.separatorView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
Expand Down
3 changes: 2 additions & 1 deletion Easydict/Feature/Service/Model/EZError.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ extern NSString *const EZTranslateErrorRequestResponseKey;
extern NSString *const EZTranslateErrorRequestErrorKey;

typedef NS_ENUM(NSUInteger, EZErrorType) {
EZErrorTypeNone,
EZErrorTypeNone, // 预留参数,暂未使用

EZErrorTypeAPI, // 接口异常
EZErrorTypeParam, // 参数异常
EZErrorTypeNetwork, // 网络异常
Expand Down
2 changes: 1 addition & 1 deletion Easydict/Feature/Service/Model/EZError.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ + (instancetype)errorWithType:(EZErrorType)type
NSString *errorString = nil;
switch (type) {
case EZErrorTypeNone:
errorString = @"";
errorString = @"None";
break;
case EZErrorTypeParam:
errorString = NSLocalizedString(@"error_parameter", nil);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import AppKit
import Foundation
import Hue
import SnapKit

@objc public class FontSizeHintView: NSView {
private lazy var minLabel: NSTextField = .init(labelWithString: NSLocalizedString("small", comment: ""))
Expand All @@ -21,42 +23,25 @@ import Foundation

minLabel.font = .systemFont(ofSize: 10)
maxLabel.font = .systemFont(ofSize: 14)

hintLabel.font = .systemFont(ofSize: 11)
hintLabel.textColor = NSColor(hex: "7B7C7C")

let sizeLabelStackView: NSStackView = {
let stackView = NSStackView(views: [minLabel, maxLabel])
stackView.alignment = .centerY
stackView.distribution = .equalSpacing
stackView.orientation = .horizontal
return stackView
}()

let verticalStackView: NSStackView = {
let stackView = NSStackView(views: [sizeLabelStackView, hintLabel])
stackView.alignment = .left
stackView.distribution = .fill
stackView.orientation = .vertical
stackView.spacing = 12
return stackView
}()

addSubview(verticalStackView)
addSubview(minLabel)
addSubview(maxLabel)
addSubview(hintLabel)

NSLayoutConstraint.activate([
sizeLabelStackView.widthAnchor.constraint(equalToConstant: 205),
sizeLabelStackView.heightAnchor.constraint(equalToConstant: 20),
])
hintLabel.snp.makeConstraints { make in
make.left.bottom.equalTo(self)
}

NSLayoutConstraint.activate([
verticalStackView.leftAnchor.constraint(equalTo: leftAnchor),
verticalStackView.topAnchor.constraint(equalTo: topAnchor),
verticalStackView.rightAnchor.constraint(equalTo: rightAnchor),
])
maxLabel.snp.makeConstraints { make in
make.right.top.equalTo(self)
}

NSLayoutConstraint.activate([
bottomAnchor.constraint(equalTo: verticalStackView.bottomAnchor),
])
minLabel.snp.makeConstraints { make in
make.left.equalTo(self)
make.centerY.equalTo(maxLabel)
}
}

@available(*, unavailable)
Expand Down

0 comments on commit 4d6d0cc

Please sign in to comment.