Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Buffer::set_rich_text method #149

Merged
merged 6 commits into from
Sep 11, 2023
Merged

Conversation

tigregalis
Copy link
Contributor

@tigregalis tigregalis commented Jun 27, 2023

  • Buffer::set_rich_text is a new convenience method, similar to the convenience method Buffer::set_text, for populating a buffer from an iterator of styled spans (a pair of &str and Attrs); it handles line splitting and the creation of BufferLines and AttrsLists
  • The Buffer::set_text method now delegates to Buffer::set_rich_text
  • The rich_text example now uses Buffer::new_empty() and Buffer::set_rich_text
use cosmic_text::{Attrs, Buffer, Family, FontSystem, Metrics, Shaping};

let mut font_system = FontSystem::new();
let mut buffer = Buffer::new_empty(Metrics::new(32.0, 44.0));
let mut buffer = buffer.borrow_with(&mut font_system);
let attrs = Attrs::new().family(Family::Serif);
buffer.set_rich_text(
    [
        ("hello, ", attrs),
        ("cosmic\ntext", attrs.family(Family::Monospace)),
    ],
    Shaping::Advanced,
);

Copy link
Contributor

@genusistimelord genusistimelord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, this does simplify the rich example quiet a bit.

@jackpot51 jackpot51 merged commit 1eab951 into pop-os:main Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants