Skip to content

Commit

Permalink
feat: More convenient inits for rich text.
Browse files Browse the repository at this point in the history
  • Loading branch information
laosb committed Feb 21, 2024
1 parent a098c5e commit 6eeb716
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/EasyRichText/Models/ERTRichText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public extension ERTRichText {
self.init(attributedString: attributedString)
}

init(string: String) {
self.init()
self.segments = [.init(text: string)]
}

func nsAttributedString(defaultFont: CTFont) -> NSAttributedString {
ERTAttributedStringBridge.default.nsAttributedString(for: attributedString(defaultFont: defaultFont))
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/EasyRichText/Models/ERTSegment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public protocol ERTSegment: Codable, Hashable {
func attributedString(defaultFont: CTFont) -> AttributedString
}

public extension ERTSegment {
init(text: String) {
self.init(text: text, attributeContainer: .init())
}
}

public protocol ERTForegroundColorSegment: Codable, Hashable {
associatedtype ForegroundColor: ERTColor

Expand Down

0 comments on commit 6eeb716

Please sign in to comment.