Commit 6c1a6d16 by Daniel Dahan

editor: added textViewEdgeInsets / Preset to Editor

parent 14b5e11a
...@@ -56,6 +56,11 @@ public protocol EditorDelegate { ...@@ -56,6 +56,11 @@ public protocol EditorDelegate {
} }
open class Editor: View { open class Editor: View {
/// Will layout the view.
open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview
}
/// TextStorage instance that is observed while editing. /// TextStorage instance that is observed while editing.
open fileprivate(set) var textStorage: TextStorage! open fileprivate(set) var textStorage: TextStorage!
...@@ -65,6 +70,21 @@ open class Editor: View { ...@@ -65,6 +70,21 @@ open class Editor: View {
/// A reference to the NSLayoutManager. /// A reference to the NSLayoutManager.
open fileprivate(set) var layoutManager: NSLayoutManager! open fileprivate(set) var layoutManager: NSLayoutManager!
/// A preset wrapper around textViewEdgeInsets.
open var textViewEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet {
textViewEdgeInsets = EdgeInsetsPresetToValue(preset: textViewEdgeInsetsPreset)
}
}
/// A reference to textViewEdgeInsets.
@IBInspectable
open var textViewEdgeInsets = EdgeInsets.zero {
didSet {
layoutSubviews()
}
}
/// Reference to the TextView. /// Reference to the TextView.
open fileprivate(set) var textView: TextView! open fileprivate(set) var textView: TextView!
...@@ -102,6 +122,15 @@ open class Editor: View { ...@@ -102,6 +122,15 @@ open class Editor: View {
return matches.filter { nil == seen.updateValue(true, forKey: $0) } return matches.filter { nil == seen.updateValue(true, forKey: $0) }
} }
open override func layoutSubviews() {
super.layoutSubviews()
guard willLayout else {
return
}
textView.frame = CGRect(x: textViewEdgeInsets.left, y: textViewEdgeInsets.top, width: width - textViewEdgeInsets.left - textViewEdgeInsets.right, height: height - textViewEdgeInsets.top - textViewEdgeInsets.bottom)
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method it is recommended to override the prepare method
...@@ -141,7 +170,7 @@ extension Editor { ...@@ -141,7 +170,7 @@ extension Editor {
/// Prepares the textView. /// Prepares the textView.
fileprivate func prepareTextView() { fileprivate func prepareTextView() {
textView = TextView(textContainer: textContainer) textView = TextView(textContainer: textContainer)
layout(textView).edges() addSubview(textView)
} }
/// Prepares the regular expression for matching. /// Prepares the regular expression for matching.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment