Add WrapMode to TextView/TextEditor
Some checks failed
SwiftLint / SwiftLint (pull_request) Has been cancelled
Some checks failed
SwiftLint / SwiftLint (pull_request) Has been cancelled
This commit is contained in:
parent
daa922d33b
commit
0af3864058
22
Sources/Core/Model/Enumerations/WrapMode.swift
Normal file
22
Sources/Core/Model/Enumerations/WrapMode.swift
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import CAdw
|
||||||
|
|
||||||
|
/// Wrap modes for `TextView`/`TextEditor`
|
||||||
|
public enum WrapMode: GtkWrapMode, RawRepresentable {
|
||||||
|
case none // GTK_WRAP_NONE
|
||||||
|
case char // GTK_WRAP_CHAR
|
||||||
|
case word // GTK_WRAP_WORD
|
||||||
|
case wordChar // GTK_WRAP_WORD_CHAR
|
||||||
|
|
||||||
|
public var rawValue: GtkWrapMode {
|
||||||
|
switch self {
|
||||||
|
case .none: GTK_WRAP_NONE
|
||||||
|
case .char: GTK_WRAP_CHAR
|
||||||
|
case .word: GTK_WRAP_WORD
|
||||||
|
case .wordChar: GTK_WRAP_WORD_CHAR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public init?(rawValue: GtkWrapMode) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Sources/Core/Model/Extensions/GtkWrapMode.swift
Normal file
9
Sources/Core/Model/Extensions/GtkWrapMode.swift
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import CAdw
|
||||||
|
|
||||||
|
/// Add ExpressibleByIntegerLiteral conformance to make GtkWrapMode usable as
|
||||||
|
// a RawValue in an enum.
|
||||||
|
extension GtkWrapMode: @retroactive ExpressibleByIntegerLiteral {
|
||||||
|
public init(integerLiteral value: Int) {
|
||||||
|
self.init(UInt32(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,6 +19,8 @@ public struct TextView: AdwaitaWidget {
|
|||||||
var padding = 0
|
var padding = 0
|
||||||
/// The edges affected by the padding.
|
/// The edges affected by the padding.
|
||||||
var paddingEdges: Set<Edge> = []
|
var paddingEdges: Set<Edge> = []
|
||||||
|
/// The (word) wrap mode used when rendering the text.
|
||||||
|
var wrapMode: WrapMode = .none
|
||||||
|
|
||||||
/// Initialize a text editor.
|
/// Initialize a text editor.
|
||||||
/// - Parameter text: The editor's content.
|
/// - Parameter text: The editor's content.
|
||||||
@ -74,9 +76,23 @@ public struct TextView: AdwaitaWidget {
|
|||||||
if paddingEdges.contains(.trailing) {
|
if paddingEdges.contains(.trailing) {
|
||||||
gtk_text_view_set_right_margin(storage.opaquePointer?.cast(), padding.cInt)
|
gtk_text_view_set_right_margin(storage.opaquePointer?.cast(), padding.cInt)
|
||||||
}
|
}
|
||||||
|
// update the wrapping mode
|
||||||
|
gtk_text_view_set_wrap_mode(storage.opaquePointer?.cast(), wrapMode.rawValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the wrapMode for the text view.
|
||||||
|
///
|
||||||
|
/// Available wrap modes are `none`, `char`, `word`, `wordChar`. Please refer to the
|
||||||
|
/// corresponding `GtkWrapMode` documentation for the details on how they work.
|
||||||
|
///
|
||||||
|
/// - Parameter mode: The `WrapMode` to set.
|
||||||
|
public func wrapMode(_ mode: WrapMode) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.wrapMode = mode
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the text view's content.
|
/// Get the text view's content.
|
||||||
/// - Parameter buffer: The text view's buffer.
|
/// - Parameter buffer: The text view's buffer.
|
||||||
/// - Returns: The content.
|
/// - Returns: The content.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user