Skip to content

Commit 4974ac6

Browse files
committed
Public Some more Variables, Delegate Estimate Line Height
1 parent c1dce32 commit 4974ac6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ public class TextLayoutManager: NSObject {
9292

9393
/// The maximum width available to lay out lines in, used to determine how much space is available for laying out
9494
/// lines. Evals to `.greatestFiniteMagnitude` when ``wrapLines`` is `false`.
95-
var maxLineLayoutWidth: CGFloat {
95+
public var maxLineLayoutWidth: CGFloat {
9696
wrapLines ? wrapLinesWidth : .greatestFiniteMagnitude
9797
}
9898

9999
/// The width of the space available to draw text fragments when wrapping lines.
100-
var wrapLinesWidth: CGFloat {
100+
public var wrapLinesWidth: CGFloat {
101101
(delegate?.textViewportSize().width ?? .greatestFiniteMagnitude) - edgeInsets.horizontal
102102
}
103103

@@ -169,6 +169,9 @@ public class TextLayoutManager: NSObject {
169169
public func estimateLineHeight() -> CGFloat {
170170
if let _estimateLineHeight {
171171
return _estimateLineHeight
172+
} else if let estimate = renderDelegate?.estimatedLineHeight() {
173+
_estimateLineHeight = estimate
174+
return estimate
172175
} else {
173176
let string = NSAttributedString(string: "0", attributes: delegate?.layoutManagerTypingAttributes() ?? [:])
174177
let typesetter = CTTypesetterCreateWithAttributedString(string)
@@ -177,8 +180,9 @@ public class TextLayoutManager: NSObject {
177180
var descent: CGFloat = 0
178181
var leading: CGFloat = 0
179182
CTLineGetTypographicBounds(ctLine, &ascent, &descent, &leading)
180-
_estimateLineHeight = (ascent + descent + leading) * lineHeightMultiplier
181-
return _estimateLineHeight!
183+
let height = (ascent + descent + leading) * lineHeightMultiplier
184+
_estimateLineHeight = height
185+
return height
182186
}
183187
}
184188

Sources/CodeEditTextView/TextLayoutManager/TextLayoutManagerRenderDelegate.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public protocol TextLayoutManagerRenderDelegate: AnyObject {
2121
breakStrategy: LineBreakStrategy
2222
)
2323

24+
func estimatedLineHeight() -> CGFloat?
25+
2426
func lineFragmentView(for lineFragment: LineFragment) -> LineFragmentView
2527
}
2628

@@ -42,6 +44,10 @@ public extension TextLayoutManagerRenderDelegate {
4244
)
4345
}
4446

47+
func estimatedLineHeight() -> CGFloat? {
48+
nil
49+
}
50+
4551
func lineFragmentView(for lineFragment: LineFragment) -> LineFragmentView {
4652
LineFragmentView()
4753
}

0 commit comments

Comments
 (0)