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

Support for text styling / rich text #156

Open
Toqozz opened this issue Jan 14, 2020 · 3 comments
Open

Support for text styling / rich text #156

Toqozz opened this issue Jan 14, 2020 · 3 comments
Labels
Milestone

Comments

@Toqozz
Copy link

Toqozz commented Jan 14, 2020

There is currently no way to style individual parts of text within a text block -- you can only change the style of the entire block.

I've seen a couple different ways of doing this on the user end:

From a user perspective, I personally prefer markup strings in the text.

glyph_brush already supports text styling using glyph_brush_layout, so implementation should just be a matter of parsing the text in whatever format to a Vec<SectionText>.

@hecrj
Copy link
Member

hecrj commented Jan 14, 2020

I think we should tackle this together with #34, once we figure out font fallback and text shaping (see #33).

String markup will force us to implement some kind of parser, while setting state is quite a side-effect heavy approach.

I personally like the approach of elm-ui. It's explicit, self-contained, and composable.

@hecrj hecrj added the feature New feature or request label Jan 14, 2020
@hecrj hecrj added this to the 1.0.0 milestone Jan 14, 2020
@Toqozz
Copy link
Author

Toqozz commented Jan 15, 2020

I like the elm-ui example, but I worry that it won't be as ergonomic in rust. The glyph_brush api uses a similar approach:

let glyphs = Layout::default().calculate_glyphs(
    &fonts,
    &SectionGeometry {
        screen_position: (150.0, 50.0),
        ..SectionGeometry::default()
    },
    &[
        SectionText {
            text: "hello ",
            scale: Scale::uniform(20.0),
            ..SectionText::default()
        },
        SectionText {
            text: "glyph_brush_layout",
            scale: Scale::uniform(25.0),
            font_id: FontId(1),
            color: [0.0, 1.0, 0.0, 1.0],
        },
    ],
);

@hecrj
Copy link
Member

hecrj commented Jan 15, 2020

We currently use the builder pattern to configure widgets. I'd use the same strategy here.

However, we are not quite close to implementing this yet. The API could change considerably before we get to tackle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants