Skip to content

Commit

Permalink
add the hints view for the keyboard shortcuts of change font size
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverAgain11 committed Dec 22, 2023
1 parent 53df35d commit 24fd3a1
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
C4DE3D6D2AC00EB500C2B85D /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = C4DE3D6C2AC00EB500C2B85D /* Localizable.xcstrings */; };
C98CAE75239F4619005F7DCA /* EasydictHelper.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = C90BE309239F38EB00ADE88B /* EasydictHelper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
DC3C643F2B187119008EEDD8 /* ChangeFontSizeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */; };
DC6D9C872B352EBC0055EFFC /* FontSizeHintView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -680,6 +681,7 @@
C90BE309239F38EB00ADE88B /* EasydictHelper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EasydictHelper.app; sourceTree = BUILT_PRODUCTS_DIR; };
C99EEB182385796700FEE666 /* Easydict-debug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Easydict-debug.app"; sourceTree = BUILT_PRODUCTS_DIR; };
DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeFontSizeView.swift; sourceTree = "<group>"; };
DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontSizeHintView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1992,6 +1994,7 @@
isa = PBXGroup;
children = (
DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */,
DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */,
);
path = ChangeFontSizeView;
sourceTree = "<group>";
Expand Down Expand Up @@ -2457,6 +2460,7 @@
03D8A6592A42A1A300D9A968 /* EZAppModel.m in Sources */,
036E7D7B293F4FC8002675DF /* EZOpenLinkButton.m in Sources */,
03008B2E2941956D0062B821 /* EZURLSchemeHandler.m in Sources */,
DC6D9C872B352EBC0055EFFC /* FontSizeHintView.swift in Sources */,
03B0232429231FA6001C7E63 /* NSUserDefaults+MM.m in Sources */,
03542A5E2938F05B00C34C33 /* EZLanguageModel.m in Sources */,
03F639952AA6CFBB009B9914 /* EZBingConfig.m in Sources */,
Expand Down
51 changes: 51 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,23 @@
}
}
},
"hints_keyboard_shortcuts_font_size" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Font size can be changed using the ⌘ +/- shortcut in the Translation and OCR windows."
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "支持在翻译窗口和 OCR 窗口通过快捷键⌘ +/-修改字体大小"
}
}
}
},
"Illegal parameter supplied to encryption/decryption algorithm" : {
"comment" : "Error reason",
"localizations" : {
Expand Down Expand Up @@ -1356,6 +1373,23 @@
}
}
},
"large" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Large"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "大"
}
}
}
},
"lastest_version" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -2132,6 +2166,23 @@
}
}
},
"small" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Small"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "小"
}
}
}
},
"snip_translate" : {
"localizations" : {
"en" : {
Expand Down
14 changes: 12 additions & 2 deletions Easydict/Feature/PerferenceWindow/EZSettingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ @interface EZSettingViewController () <NSComboBoxDelegate>

@property (nonatomic, strong) NSTextField *fontSizeLabel;
@property (nonatomic, strong) ChangeFontSizeView *changeFontSizeView;
@property (nonatomic, strong) FontSizeHintView *fontSizeHintView;

@property (nonatomic, strong) NSArray<NSString *> *enabledTTSServiceTypes;

Expand Down Expand Up @@ -493,6 +494,9 @@ - (void)setupUI {
[self.contentView addSubview:changeFontSizeView];
self.changeFontSizeView = changeFontSizeView;

self.fontSizeHintView = [FontSizeHintView new];
[self.contentView addSubview:self.fontSizeHintView];

[self updatePreferredLanguagesPopUpButton];

self.showQueryIconButton.mm_isOn = self.config.autoSelectText;
Expand Down Expand Up @@ -775,12 +779,18 @@ - (void)updateViewConstraints {
make.left.equalTo(self.fontSizeLabel.mas_right).offset(self.horizontalPadding);
make.centerY.equalTo(self.fontSizeLabel);
make.width.mas_equalTo(200);
make.height.mas_equalTo(60);
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);
}];

[self.separatorView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.separatorView);
make.top.equalTo(self.fontSizeLabel.mas_bottom).offset(1.5 * self.verticalPadding);
make.top.equalTo(self.fontSizeHintView.mas_bottom).offset(1.5 * self.verticalPadding);
make.height.equalTo(self.separatorView);
}];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// FontSizeHintView.swift
// Easydict
//
// Created by yqing on 2023/12/22.
// Copyright © 2023 izual. All rights reserved.
//

import AppKit
import Foundation

@objc public class FontSizeHintView: NSView {
private lazy var minLabel: NSTextField = .init(labelWithString: NSLocalizedString("small", comment: ""))

private lazy var maxLabel: NSTextField = .init(labelWithString: NSLocalizedString("large", comment: ""))

private lazy var hintLabel: NSTextField = .init(wrappingLabelWithString: NSLocalizedString("hints_keyboard_shortcuts_font_size", comment: ""))

override public init(frame frameRect: NSRect) {
super.init(frame: frameRect)

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

hintLabel.font = .systemFont(ofSize: 11)

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)

NSLayoutConstraint.activate([
sizeLabelStackView.widthAnchor.constraint(equalToConstant: 205),
sizeLabelStackView.heightAnchor.constraint(equalToConstant: 20),
])

NSLayoutConstraint.activate([
verticalStackView.leftAnchor.constraint(equalTo: leftAnchor),
verticalStackView.topAnchor.constraint(equalTo: topAnchor),
verticalStackView.rightAnchor.constraint(equalTo: rightAnchor),
])

NSLayoutConstraint.activate([
bottomAnchor.constraint(equalTo: verticalStackView.bottomAnchor),
])
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

0 comments on commit 24fd3a1

Please sign in to comment.