Skip to content

ui::TextHighlighter

Header: winui/ui/text/Inlines.hpp.

Ranges of a text block's content painted with their own background and, optionally, foreground. Ranges are start and length offsets into the block's plain text (its runs in order, paragraphs separated by one character).

Example:

// Highlight "consectetur" (offset 28, 11 characters) in yellow.
window.set_content(ui::RichText{
    .blocks            = {{.inlines = {{.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"}}}},
    .text_highlighters = std::vector<ui::TextHighlighter>{
        ui::TextHighlighter{.ranges = {{28, 11}}, .background = ui::Color::from_argb(0xFFFFFF00)}},
});

Field Type Default
ranges std::vector<Range> The spans to paint.
background Color The background painted behind every range.
foreground std::optional<Color> The text color inside the ranges; nullopt keeps each run's own.

struct Range

A span of the plain text: length characters from offset start.

Field Type Default
start std::size_t 0 The first offset covered.
length std::size_t 0 How many offsets are covered.