Skip to content

Commit

Permalink
refactor: rewrite FontSizeHintView with SnapKit
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Dec 23, 2023
1 parent 75acc87 commit 02e711a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
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
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 02e711a

Please sign in to comment.