From 24fd3a1a3f227f36735348cbe725cbd9a5a4d53d Mon Sep 17 00:00:00 2001 From: ljk Date: Fri, 22 Dec 2023 12:01:11 +0800 Subject: [PATCH] add the hints view for the keyboard shortcuts of change font size --- Easydict.xcodeproj/project.pbxproj | 4 ++ Easydict/App/Localizable.xcstrings | 51 ++++++++++++++ .../EZSettingViewController.m | 14 +++- .../ChangeFontSizeView/FontSizeHintView.swift | 66 +++++++++++++++++++ 4 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 Easydict/Feature/ViewController/View/ChangeFontSizeView/FontSizeHintView.swift diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 6f8be4c40..a61338f08 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -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 */ @@ -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 = ""; }; + DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontSizeHintView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1992,6 +1994,7 @@ isa = PBXGroup; children = ( DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */, + DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */, ); path = ChangeFontSizeView; sourceTree = ""; @@ -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 */, diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 5982662ff..852d1870c 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -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" : { @@ -1356,6 +1373,23 @@ } } }, + "large" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Large" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "大" + } + } + } + }, "lastest_version" : { "localizations" : { "en" : { @@ -2132,6 +2166,23 @@ } } }, + "small" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Small" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "小" + } + } + } + }, "snip_translate" : { "localizations" : { "en" : { diff --git a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m index c31e0606b..be9614d7e 100644 --- a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m +++ b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m @@ -102,6 +102,7 @@ @interface EZSettingViewController () @property (nonatomic, strong) NSTextField *fontSizeLabel; @property (nonatomic, strong) ChangeFontSizeView *changeFontSizeView; +@property (nonatomic, strong) FontSizeHintView *fontSizeHintView; @property (nonatomic, strong) NSArray *enabledTTSServiceTypes; @@ -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; @@ -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); }]; diff --git a/Easydict/Feature/ViewController/View/ChangeFontSizeView/FontSizeHintView.swift b/Easydict/Feature/ViewController/View/ChangeFontSizeView/FontSizeHintView.swift new file mode 100644 index 000000000..666242fcd --- /dev/null +++ b/Easydict/Feature/ViewController/View/ChangeFontSizeView/FontSizeHintView.swift @@ -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") + } +}