-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vertical Writing Direction Support #441
Conversation
LEOYoon-Tsaw
commented
Aug 14, 2020
- Add vertical writing direction support, toggled by style/vertical in squirrel.yaml.
- Also add a style/baseOffset to provide flexibility in adjusting font baseline.
- Should not affect current users, purely additive.
SquirrelPanel.m
Outdated
@@ -47,7 +49,7 @@ - (void)setText:(NSAttributedString *)text | |||
} | |||
|
|||
- (void)setBackgroundColor:(NSColor *)backgroundColor { | |||
_backgroundColor = (backgroundColor != nil ? backgroundColor : [NSColor windowBackgroundColor]); | |||
NSColor * _backgroundColor = (backgroundColor != nil ? backgroundColor : [NSColor windowBackgroundColor]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: name the local variable backgroundColor
. and remove the unused property SquirrelView.backgroundColor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
SquirrelPanel.m
Outdated
@@ -128,13 +128,35 @@ @implementation SquirrelPanel { | |||
NSMutableDictionary *_commentHighlightedAttrs; | |||
NSMutableDictionary *_preeditAttrs; | |||
NSMutableDictionary *_preeditHighlightedAttrs; | |||
NSParagraphStyle *_paragraphStyle; | |||
NSParagraphStyle *_preeditParagraphStyle; | |||
NSMutableParagraphStyle *_paragraphStyle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSMutableParagraphStyle
inherits NSParagraphStyle
. No need to change the type.
SquirrelPanel.m
Outdated
NSParagraphStyle *_paragraphStyle; | ||
NSParagraphStyle *_preeditParagraphStyle; | ||
NSMutableParagraphStyle *_paragraphStyle; | ||
NSMutableParagraphStyle *_preeditParagraphStyle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to change the type.
SquirrelPanel.m
Outdated
@@ -166,20 +188,20 @@ - (void)initializeUIStyle { | |||
_preeditHighlightedAttrs[NSForegroundColorAttributeName] = [NSColor controlTextColor]; | |||
_preeditHighlightedAttrs[NSFontAttributeName] = [NSFont userFontOfSize:kDefaultFontSize]; | |||
|
|||
_paragraphStyle = [NSParagraphStyle defaultParagraphStyle]; | |||
_preeditParagraphStyle = [NSParagraphStyle defaultParagraphStyle]; | |||
_paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to copy.
SquirrelPanel.m
Outdated
_paragraphStyle = [NSParagraphStyle defaultParagraphStyle]; | ||
_preeditParagraphStyle = [NSParagraphStyle defaultParagraphStyle]; | ||
_paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; | ||
_preeditParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to copy.
SquirrelPanel.m
Outdated
// if the height is too large, it's hard to read, so need to put limit on the height. | ||
if (windowRect.size.height > NSHeight(screenRect) / 3) { | ||
windowRect.size.height = NSHeight(screenRect) / 3; | ||
windowRect.size.width = [_view.text boundingRectWithSize:NSMakeSize(windowRect.size.height - _view.edgeInset.height * 2, windowRect.size.width - _view.edgeInset.width * 2) options:NSStringDrawingUsesLineFragmentOrigin].size.height + _view.edgeInset.height * 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too long a line
SquirrelPanel.m
Outdated
@@ -225,6 +269,14 @@ - (void)show { | |||
windowRect.origin.y = NSMinY(screenRect); | |||
} | |||
// voila ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: voila is for the last step.
SquirrelPanel.m
Outdated
// rotate the view, the core in vertical mode! | ||
if (_vertical) { | ||
_view.boundsRotation = -90.0; | ||
[_view setBoundsOrigin:NSMakePoint(_view.contentSize.width + _view.edgeInset.width * 2, _view.edgeInset.height * 2)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why isn't boundsOrigin.y = 0
but _view.edgeInset.height * 2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this is better, I'm going to change it
SquirrelPanel.m
Outdated
if (_inlinePreedit) { | ||
windowRect.origin.x -= windowRect.size.width; | ||
} else { | ||
windowRect.origin.x -= windowRect.size.width - preeditSize.height - _view.edgeInset.width; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_view.edgeInset.width
or _view.edgeInset.height
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on how user interpret borderHeight in vertical mode.. There're more places to look at for the consistency. But this edgeInset.width consistency issue can be dealt after all other gardening's done.
SquirrelPanel.m
Outdated
@@ -402,70 +473,116 @@ - (void)showPreedit:(NSString *)preedit | |||
} | |||
|
|||
if (i > 0) { | |||
NSAttributedString *separator = [[NSAttributedString alloc] | |||
NSMutableAttributedString *separator = [[NSMutableAttributedString alloc] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to be mutable.
This is a great feature. I need more time to understand the changes.
|
|
…et in other modes to config section.
… color, and smooth rounded corners.
My config for testing: https://gist.github.com/lotem/4b8ce0742eac3c2a7aafed8b16e645df |
…o change arrrow key behaviour
…reedit_back_color set
…reedit_back_color set (cherry picked from commit d2a2859)
Support Dark mode
Adopts TextStorage to support general linebreak, a new slim vertical mode (horizontal=true & vertical=true), more advanced highlighting, dark mode autoswitching
Will refactor the remaining parts for a new pull |