Truncate text in the beginning instead of at the end

Hello everyone!

I am working on a small visualization for a installation. Part of it is a continuously growing text. I didn’t have any problems setting up a writer with a box to render the text into. However, when the text grows to long it gets truncated at the end. I tried setting verticalAlign to 1.0, but even then the text gets truncated at the end when the box is full.

Is there any way to truncate the text at the beginning instead, so that new additions to the text are always visible?

Hi hi! Nice to see you back :slight_smile: Would it work to avoid drawing everything except the last lines?

If you have the lines in a list, you could do list.takeLast(10)or similar.

import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.loadFont
import org.openrndr.extra.textwriter.writer
import org.openrndr.math.Vector2
import org.openrndr.shape.Rectangle

fun main() = application {
    configure {
        width = 380
        height = 380
    }
    program {
        val area = Rectangle(40.0, 40.0, 300.0, 300.0)
        val font = loadFont("data/fonts/default.otf", 24.0)
        val lines = mutableListOf("")
        extend {
            drawer.clear(ColorRGBa.PINK)
            drawer.fill = null
            drawer.rectangle(area.movedBy(Vector2(-5.0, 0.0)))

            drawer.fontMap = font
            drawer.fill = ColorRGBa.BLACK

            if (lines.last().length > 25) {
                lines.add("")
            } else {
                lines[lines.lastIndex] += "[-]+ (){}".random()
            }

            writer {
                box = area
                // draw only the last 12 lines
                lines.takeLast(12).forEach {
                    newLine()
                    text(it)
                }
            }
        }
    }
}

1 Like

Ah yes, that works! Thank you!

1 Like