Skip to content

Commit

Permalink
Remove horizontal padding
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Apr 4, 2021
1 parent ce836f6 commit 421f3bd
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions SquirrelPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ @interface SquirrelView : NSView
@property(nonatomic, readonly) NSRect contentRect;
@property(nonatomic, readonly) BOOL isDark;
@property(nonatomic, strong, readonly) SquirrelTheme *currentTheme;
@property(nonatomic, readonly) CGFloat textFrameWidth;
@property(nonatomic, assign) CGFloat seperatorWidth;

- (BOOL)isFlipped;
Expand Down Expand Up @@ -218,6 +217,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect {
}
// Use textStorage to store text and manage all text layout and draws
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:NSZeroSize];
textContainer.lineFragmentPadding = 0.0;
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[layoutManager addTextContainer:textContainer];
_text = [[NSTextStorage alloc] init];
Expand All @@ -230,18 +230,10 @@ - (instancetype)initWithFrame:(NSRect)frameRect {
return self;
}

// The textStorage layout will have a 5px empty edge on both sides
- (CGFloat)textFrameWidth {
return [_text.layoutManagers[0] boundingRectForGlyphRange:NSMakeRange(0, 0) inTextContainer:_text.layoutManagers[0].textContainers[0]].origin.x;
}

// Get the rectangle containing entire contents, expensive to calculate
- (NSRect)contentRect {
NSRange glyphRange = [_text.layoutManagers[0] glyphRangeForTextContainer:_text.layoutManagers[0].textContainers[0]];
NSRect rect = [_text.layoutManagers[0] boundingRectForGlyphRange:glyphRange inTextContainer:_text.layoutManagers[0].textContainers[0]];
CGFloat frameWidth = self.textFrameWidth;
rect.origin.x -= frameWidth;
rect.size.width += frameWidth * 2;
return rect;
}

Expand Down Expand Up @@ -359,7 +351,7 @@ - (void)multilineRectForRange:(NSRange)charRange leadingRect:(NSRect *)leadingRe
*leadingRect = NSZeroRect;
*bodyRect = boundingRect;
*trailingRect = NSZeroRect;
if (boundingRect.origin.x <= self.textFrameWidth +1 && fullRangeInBoundingRect.location < glyphRange.location) {
if (boundingRect.origin.x <= 1 && fullRangeInBoundingRect.location < glyphRange.location) {
*leadingRect = [layoutManager boundingRectForGlyphRange:NSMakeRange(fullRangeInBoundingRect.location, glyphRange.location-fullRangeInBoundingRect.location) inTextContainer:textContainer];
if (!nearEmptyRect(*leadingRect)) {
bodyRect->size.height -= leadingRect->size.height;
Expand Down Expand Up @@ -480,7 +472,6 @@ - (void)addGapBetweenHorizontalCandidates:(NSRect *)rect {

// All draws happen here
- (void)drawRect:(NSRect)dirtyRect {
double textFrameWidth = self.textFrameWidth;
NSBezierPath *backgroundPath;
NSBezierPath *borderPath;
NSBezierPath *highlightedPath;
Expand Down Expand Up @@ -515,8 +506,8 @@ - (void)drawRect:(NSRect)dirtyRect {
// Draw highlighted Rect
if (_highlightedRange.length > 0 && theme.highlightedStripColor != nil) {
NSRect innerBox = backgroundRect;
innerBox.size.width -= (theme.edgeInset.width + 1 + textFrameWidth) * 2;
innerBox.origin.x += theme.edgeInset.width + 1 + textFrameWidth;
innerBox.size.width -= (theme.edgeInset.width + 1) * 2;
innerBox.origin.x += theme.edgeInset.width + 1;
if (_preeditRange.length == 0) {
innerBox.origin.y += theme.edgeInset.height + 1;
innerBox.size.height -= (theme.edgeInset.height + 1) * 2;
Expand Down Expand Up @@ -593,8 +584,8 @@ - (void)drawRect:(NSRect)dirtyRect {
[self multilineRectForRange:_highlightedPreeditRange leadingRect:&leadingRect bodyRect:&bodyRect trailingRect:&trailingRect];

NSRect innerBox = preeditRect;
innerBox.size.width -= (theme.edgeInset.width + 1 + textFrameWidth) * 2;
innerBox.origin.x += theme.edgeInset.width + 1 + textFrameWidth;
innerBox.size.width -= (theme.edgeInset.width + 1) * 2;
innerBox.origin.x += theme.edgeInset.width + 1;
innerBox.origin.y += theme.edgeInset.height + 1;
if (_highlightedRange.length == 0) {
innerBox.size.height -= (theme.edgeInset.height + 1) * 2;
Expand Down Expand Up @@ -876,7 +867,7 @@ - (void)show {
}

//Break line if the text is too long, based on screen size.
CGFloat textWidth = _view.text.size.width + _view.textFrameWidth * 2;
CGFloat textWidth = _view.text.size.width;
NSFont *currentFont = theme.attrs[NSFontAttributeName];
CGFloat fontScale = currentFont.pointSize / 12;
CGFloat textWidthRatio = MIN(1.0, 1.0 / (theme.vertical ? 4 : 3) + fontScale / 12);
Expand Down

0 comments on commit 421f3bd

Please sign in to comment.