Use NSTableViewStyleFullWidth on supported macOS
This prevents the vertical candidate table view to use the inset style [1]. The full-width style serves the purpose. The inset style makes the first candidate too further away from the cursor in the composing buffer. [1] https://developer.apple.com/design/human-interface-guidelines/macos/overview/whats-new-in-macos/
This commit is contained in:
parent
9b2a2e89bc
commit
7d13ea0b41
|
@ -36,6 +36,10 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
|
||||||
static const CGFloat kCandidateTextPadding = 24.0;
|
static const CGFloat kCandidateTextPadding = 24.0;
|
||||||
static const CGFloat kCandidateTextLeftMargin = 8.0;
|
static const CGFloat kCandidateTextLeftMargin = 8.0;
|
||||||
|
|
||||||
|
static const CGFloat kCandidateTextPaddingWithMandatedTableViewPadding = 18.0;
|
||||||
|
static const CGFloat kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0;
|
||||||
|
|
||||||
|
|
||||||
@interface VTVerticalCandidateController (Private) <NSTableViewDataSource, NSTableViewDelegate>
|
@interface VTVerticalCandidateController (Private) <NSTableViewDataSource, NSTableViewDelegate>
|
||||||
- (void)rowDoubleClicked:(id)sender;
|
- (void)rowDoubleClicked:(id)sender;
|
||||||
- (BOOL)scrollPageByOne:(BOOL)forward;
|
- (BOOL)scrollPageByOne:(BOOL)forward;
|
||||||
|
@ -44,6 +48,13 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation VTVerticalCandidateController
|
@implementation VTVerticalCandidateController
|
||||||
|
{
|
||||||
|
// Total padding added to the left and the right of the table view cell text.
|
||||||
|
CGFloat _candidateTextPadding;
|
||||||
|
|
||||||
|
// The indent of the table view cell text from the left.
|
||||||
|
CGFloat _candidateTextLeftMargin;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
|
@ -65,10 +76,6 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
|
||||||
|
|
||||||
self = [self initWithWindow:panel];
|
self = [self initWithWindow:panel];
|
||||||
if (self) {
|
if (self) {
|
||||||
_candidateTextParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
||||||
[_candidateTextParagraphStyle setFirstLineHeadIndent:kCandidateTextLeftMargin];
|
|
||||||
[_candidateTextParagraphStyle setLineBreakMode:NSLineBreakByClipping];
|
|
||||||
|
|
||||||
contentRect.origin = NSMakePoint(0.0, 0.0);
|
contentRect.origin = NSMakePoint(0.0, 0.0);
|
||||||
|
|
||||||
NSRect stripRect = contentRect;
|
NSRect stripRect = contentRect;
|
||||||
|
@ -96,6 +103,9 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
|
||||||
[column setDataCell:[[[NSTextFieldCell alloc] init] autorelease]];
|
[column setDataCell:[[[NSTextFieldCell alloc] init] autorelease]];
|
||||||
[column setEditable:NO];
|
[column setEditable:NO];
|
||||||
|
|
||||||
|
_candidateTextPadding = kCandidateTextPadding;
|
||||||
|
_candidateTextLeftMargin = kCandidateTextLeftMargin;
|
||||||
|
|
||||||
[_tableView addTableColumn:column];
|
[_tableView addTableColumn:column];
|
||||||
[_tableView setIntercellSpacing:NSMakeSize(0.0, 1.0)];
|
[_tableView setIntercellSpacing:NSMakeSize(0.0, 1.0)];
|
||||||
[_tableView setHeaderView:nil];
|
[_tableView setHeaderView:nil];
|
||||||
|
@ -103,9 +113,18 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
|
||||||
[_tableView setAllowsEmptySelection:YES];
|
[_tableView setAllowsEmptySelection:YES];
|
||||||
[_tableView setDoubleAction:@selector(rowDoubleClicked:)];
|
[_tableView setDoubleAction:@selector(rowDoubleClicked:)];
|
||||||
[_tableView setTarget:self];
|
[_tableView setTarget:self];
|
||||||
|
if (@available(macOS 10.16, *)) {
|
||||||
|
[_tableView setStyle:NSTableViewStyleFullWidth];
|
||||||
|
_candidateTextPadding = kCandidateTextPaddingWithMandatedTableViewPadding;
|
||||||
|
_candidateTextLeftMargin = kCandidateTextLeftMarginWithMandatedTableViewPadding;
|
||||||
|
}
|
||||||
|
|
||||||
[_scrollView setDocumentView:_tableView];
|
[_scrollView setDocumentView:_tableView];
|
||||||
[[panel contentView] addSubview:_scrollView];
|
[[panel contentView] addSubview:_scrollView];
|
||||||
|
|
||||||
|
_candidateTextParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
||||||
|
[_candidateTextParagraphStyle setFirstLineHeadIndent:_candidateTextLeftMargin];
|
||||||
|
[_candidateTextParagraphStyle setLineBreakMode:NSLineBreakByClipping];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -113,7 +132,7 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
|
||||||
|
|
||||||
- (void)reloadData
|
- (void)reloadData
|
||||||
{
|
{
|
||||||
_maxCandidateAttrStringWidth = ceil([_candidateFont pointSize] * 2.0 + kCandidateTextPadding);
|
_maxCandidateAttrStringWidth = ceil([_candidateFont pointSize] * 2.0 + _candidateTextPadding);
|
||||||
|
|
||||||
[_tableView reloadData];
|
[_tableView reloadData];
|
||||||
[self layoutCandidateView];
|
[self layoutCandidateView];
|
||||||
|
@ -221,7 +240,7 @@ static const CGFloat kCandidateTextLeftMargin = 8.0;
|
||||||
|
|
||||||
// expand the window width if text overflows
|
// expand the window width if text overflows
|
||||||
NSRect boundingRect = [attrString boundingRectWithSize:NSMakeSize(10240.0, 10240.0) options:NSStringDrawingUsesLineFragmentOrigin];
|
NSRect boundingRect = [attrString boundingRectWithSize:NSMakeSize(10240.0, 10240.0) options:NSStringDrawingUsesLineFragmentOrigin];
|
||||||
CGFloat textWidth = boundingRect.size.width + kCandidateTextPadding;
|
CGFloat textWidth = boundingRect.size.width + _candidateTextPadding;
|
||||||
if (textWidth > _maxCandidateAttrStringWidth) {
|
if (textWidth > _maxCandidateAttrStringWidth) {
|
||||||
_maxCandidateAttrStringWidth = textWidth;
|
_maxCandidateAttrStringWidth = textWidth;
|
||||||
[self layoutCandidateView];
|
[self layoutCandidateView];
|
||||||
|
|
Loading…
Reference in New Issue