Viewport

class Viewport(content: Widget, width: Int?, height: Int? = null, scrollRight: Int = 0, scrollDown: Int = 0) : Widget

Crop or pad another content widget to a fixed size, and optionally scroll visible portion of the widget within that size.

If width or height are larger than the size of the content widget, the extra space will be filled with spaces.

You can specify scrollRight and scrollDown to scroll the viewport across the content. Negative values will scroll the widget to the right or up, respectively.

Example

val text = Text(
"""
123
456
7890
""".trimIndent()
)

val viewport1 = Viewport(text, width = 2, height = 2, scrollRight = 1, scrollDown = 1)
terminal.println(Panel(viewport1))

val viewport2 = Viewport(text, width = 2, height = 2, scrollRight = -1, scrollDown = -1)
terminal.println(Panel(viewport2))

Will print the following:

╭──╮
│56│
│89│
╰──╯
╭──╮
│ │
│ 1│
╰──╯

Constructors

Link copied to clipboard
constructor(content: Widget, width: Int?, height: Int? = null, scrollRight: Int = 0, scrollDown: Int = 0)

Functions

Link copied to clipboard
open override fun measure(t: Terminal, width: Int): WidthRange
Link copied to clipboard
open override fun render(t: Terminal, width: Int): Lines
Link copied to clipboard
fun Widget.withPadding(padding: Padding, padEmptyLines: Boolean = true): Widget

Add padding around this widget.

fun Widget.withPadding(padEmptyLines: Boolean = true, padding: Padding.Builder.() -> Unit): Widget
fun Widget.withPadding(all: Int, padEmptyLines: Boolean = true): Widget
fun Widget.withPadding(top: Int, right: Int, bottom: Int, left: Int, padEmptyLines: Boolean = true): Widget