Skip to content
This repository was archived by the owner on Aug 24, 2025. It is now read-only.
This repository was archived by the owner on Aug 24, 2025. It is now read-only.

Improve text wrapping #2

@altsem

Description

@altsem

Currently word-wrapping can be achieved by first splitting a text into multiple "rectangles of words" via Layout::text:

let mut layout = Layout {
    meta: LayoutMeta::default(),
    children: &mut "Layzer is a zero-heap-allocation layout library for building nested layouts with discrete positioning, and sizing. It's designed for terminal UIs, text-based interfaces, and any scenario where you need to compute positions and sizes of rectangular elements."
        .split_word_bounds()
        .map(Layout::text)
        .collect::<Vec<_>>(),
};

layout.compute([20, 20]);
layout.iter()...

An idea is to instead compute the size and position (perform text wrapping) only when looking at
the text.

let mut layout = Layout {
    meta: LayoutMeta::default()
            .data("Layzer is a zero-heap-allocation layout library for building nested layouts with discrete positioning, and sizing. It's designed for terminal UIs, text-based interfaces, and any scenario where you need to compute positions and sizes of rectangular elements."),
    children: &mut [],
};

layout.compute([20, 20]); // Need to materialize the text wrapping, in order to measure the size/position
layout.iter()  // And again here

compute and iter should probably be merged into a single function...

Will likely want to support

  • Word wrap
  • Plain per-character (grapheme) wrap
  • Some kind of hybrid?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions