diff --git a/Easydict/objc/ViewController/View/ResultView/EZResultView.m b/Easydict/objc/ViewController/View/ResultView/EZResultView.m index 2e25776c4..cf76ad2c3 100644 --- a/Easydict/objc/ViewController/View/ResultView/EZResultView.m +++ b/Easydict/objc/ViewController/View/ResultView/EZResultView.m @@ -10,6 +10,7 @@ #import "EZHoverButton.h" #import "EZLoadingAnimationView.h" #import "NSImage+EZSymbolmage.h" +#import "NSObject+EZWindowType.h" @interface EZResultView () @@ -215,8 +216,6 @@ - (void)setup { [self.serviceNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.serviceIcon.mas_right).offset(2); make.centerY.equalTo(self.topBarView).offset(0); - - make.width.mas_lessThanOrEqualTo(127); // the lenght of "Built-In AI Translate" }]; [self.serviceModelButton mas_makeConstraints:^(MASConstraintMaker *make) { @@ -268,7 +267,6 @@ - (void)setResult:(EZQueryResult *)result { mm_weakify(self); - CGFloat modelButtonWidth = 0; if ([self isBaseOpenAIService:result.service]) { EZBaseOpenAIService *service = (EZBaseOpenAIService *)result.service; self.serviceModelButton.title = service.model; @@ -279,14 +277,7 @@ - (void)setResult:(EZQueryResult *)result { mm_strongify(self); [self showModelSelectionMenu:button]; }]; - - [self.serviceModelButton sizeToFit]; - modelButtonWidth = MIN(self.serviceModelButton.width, 105); // the length of "gpt-4-turbo-preview" } - [self.serviceModelButton mas_updateConstraints:^(MASConstraintMaker *make) { - make.width.mas_equalTo(modelButtonWidth); - }]; - [self.wordResultView refreshWithResult:result]; @@ -311,6 +302,46 @@ - (void)setQueryTextBlock:(void (^)(NSString *_Nonnull))clickTextBlock { #pragma mark - +- (void)updateConstraints { + [self.serviceNameLabel mas_updateConstraints:^(MASConstraintMaker *make) { + // 127 is the lenght of "Built-In AI Translate" + make.width.mas_lessThanOrEqualTo(127 * [self windowWidthRatio]); + }]; + + CGFloat modelButtonWidth = 0; + if ([self isBaseOpenAIService:self.result.service]) { + [self.serviceModelButton sizeToFit]; + // 105 is the length of "gpt-4-turbo-preview" + modelButtonWidth = MIN(self.serviceModelButton.width, 105 * [self windowWidthRatio]); + } + + [self.serviceModelButton mas_updateConstraints:^(MASConstraintMaker *make) { + make.width.mas_equalTo(modelButtonWidth); + }]; + + [super updateConstraints]; +} + +- (CGFloat)windowWidthRatio { + CGFloat minimumWindowWidth = [EZLayoutManager.shared minimumWindowSize:self.windowType].width; + return self.width / minimumWindowWidth; +} + +#pragma mark - Public Methods + +- (void)updateLoadingAnimation { + [self startOrStopLoadingAnimation:self.result.isLoading]; +} + +- (void)startOrStopLoadingAnimation:(BOOL)isLoading { + if (isLoading) { + self.errorImageView.hidden = YES; + } + [self.loadingView startLoading:isLoading]; +} + +#pragma mark - Update UI + - (void)updateWordResultViewHeight:(CGFloat)wordResultViewHeight { if (self.result.HTMLString.length) { self.result.webViewManager.wordResultViewHeight = wordResultViewHeight; @@ -336,20 +367,6 @@ - (void)updateWordResultViewHeight:(CGFloat)wordResultViewHeight { // NSLog(@"%@, result view height: %@", result.serviceType, @(viewHeight)); } -#pragma mark - Public Methods - -- (void)updateLoadingAnimation { - [self startOrStopLoadingAnimation:self.result.isLoading]; -} - -- (void)startOrStopLoadingAnimation:(BOOL)isLoading { - if (isLoading) { - self.errorImageView.hidden = YES; - } - [self.loadingView startLoading:isLoading]; -} - -#pragma mark - - (void)updateAllButtonStatus { [self updateErrorImage]; diff --git a/Easydict/objc/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m b/Easydict/objc/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m index 3a414e75c..013e7f93b 100644 --- a/Easydict/objc/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m +++ b/Easydict/objc/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m @@ -834,6 +834,8 @@ - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(null } EZResultView *resultCell = [self resultCellAtRow:row]; + resultCell.windowType = self.windowType; + return resultCell; }