Skip to content

Commit

Permalink
Splitting the ruler padding into leading and trailing padding (#10)
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Wahl <[email protected]>
  • Loading branch information
Eliulm authored Jan 24, 2023
1 parent 78f39b8 commit deab1ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Sources/STTextView/STLineNumberRulerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ open class STLineNumberRulerView: NSRulerView {
@Invalidating(.display)
open var font: NSFont = NSFont(descriptor: NSFont.monospacedDigitSystemFont(ofSize: NSFont.labelFontSize, weight: .regular).fontDescriptor.withSymbolicTraits(.condensed), size: NSFont.labelFontSize) ?? NSFont.monospacedSystemFont(ofSize: NSFont.labelFontSize, weight: .regular)

/// The horizontal padding of the ruler view.
/// The insets of the ruler view.
@Invalidating(.display)
open var rulePadding: CGFloat = 6

open var rulerInsets: STRulerInsets = STRulerInsets(leading: 6.0, trailing: 6.0)
/// The text color of the line numbers.
@Invalidating(.display)
open var textColor: NSColor = .secondaryLabelColor
Expand Down Expand Up @@ -167,8 +167,8 @@ open class STLineNumberRulerView: NSRulerView {
// Adjust ruleThickness based on last (longest) value
if let lastLine = lines.last {
let ctLineWidth = CTLineGetTypographicBounds(lastLine.ctLine, nil, nil, nil)
if ruleThickness < (ctLineWidth + (rulePadding * 2)) {
self.ruleThickness = max(self.ruleThickness, ctLineWidth + (self.rulePadding * 2))
if ruleThickness < (ctLineWidth + (rulerInsets.leading + rulerInsets.trailing)) {
self.ruleThickness = max(self.ruleThickness, ctLineWidth + (rulerInsets.leading + rulerInsets.trailing))
}
}

Expand All @@ -177,7 +177,7 @@ open class STLineNumberRulerView: NSRulerView {
let ctLineWidth = ceil(CTLineGetTypographicBounds($0.ctLine, nil, nil, nil))

return (
textPosition: $0.textPosition.moved(dx: ruleThickness - (ctLineWidth + rulePadding), dy: -baselineOffset),
textPosition: $0.textPosition.moved(dx: ruleThickness - (ctLineWidth + rulerInsets.trailing), dy: -baselineOffset),
ctLine: $0.ctLine
)
}
Expand Down
13 changes: 13 additions & 0 deletions Sources/STTextView/Utility/STLineNumberTypes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Created by Elias Wahl on 14.01.23.
import Foundation

public struct STRulerInsets: Equatable {
public let leading: CGFloat
public let trailing: CGFloat

public init(leading: CGFloat, trailing: CGFloat) {
self.leading = leading
self.trailing = trailing
}

}

0 comments on commit deab1ae

Please sign in to comment.