Add support for line wrapping to Text
This commit is contained in:
parent
4dc5d07409
commit
9cbf88727c
@ -12,6 +12,8 @@ public struct Text: Widget {
|
||||
|
||||
/// The content.
|
||||
var text: String
|
||||
/// Whether line wrapping is allowed.
|
||||
var lineWrapping = false
|
||||
|
||||
/// Initialize a text widget.
|
||||
/// - Parameter text: The content.
|
||||
@ -26,13 +28,23 @@ public struct Text: Widget {
|
||||
public func update(_ storage: ViewStorage, modifiers: [(View) -> View]) {
|
||||
if let label = storage.view as? MarkupLabel {
|
||||
label.setText(text)
|
||||
_ = label.wrap(lineWrapping)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the container of the text widget.
|
||||
/// - Returns: The view storage.
|
||||
public func container(modifiers: [(View) -> View]) -> ViewStorage {
|
||||
.init(MarkupLabel(self.text))
|
||||
.init(MarkupLabel(self.text).wrap(lineWrapping))
|
||||
}
|
||||
|
||||
/// Line wrapping allows the text view to span multiple lines if the width is narrow.
|
||||
/// - Parameter wrap: Whether to allow line wrapping.
|
||||
/// - Returns: The text.
|
||||
public func wrap(_ wrap: Bool = true) -> Self {
|
||||
var newSelf = self
|
||||
newSelf.lineWrapping = wrap
|
||||
return newSelf
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -71,6 +71,11 @@ This is an overview of the available widgets and other components in _Adwaita_.
|
||||
| ---------------------------- | --------------------------------------------------------------------------------------- |
|
||||
| `headerBarTitle(view:)` | Customize the title view in the header bar. |
|
||||
|
||||
### `Text` Modifiers
|
||||
| Syntax | Description |
|
||||
| ---------------------------- | --------------------------------------------------------------------------------------------------- |
|
||||
| `wrap(_:)` | Enable or disable line wrapping (expanding the text view to multiple lines if the width is narrow). |
|
||||
|
||||
### `Toggle` Modifiers
|
||||
| Syntax | Description |
|
||||
| ---------------------------- | --------------------------------------------------------------------------------------- |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user