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

\t tab escape sequence support in text #9761

Open
ickshonpe opened this issue Sep 11, 2023 · 5 comments
Open

\t tab escape sequence support in text #9761

ickshonpe opened this issue Sep 11, 2023 · 5 comments
Labels
A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible

Comments

@ickshonpe
Copy link
Contributor

ickshonpe commented Sep 11, 2023

What problem does this solve or what need does it fill?

from the display_and_visibility example:

 let bottom_frame = commands.spawn(NodeBundle {
        style: Style {
            flex_direction: FlexDirection::Row,
            align_items: AlignItems::Start,
            justify_content: JustifyContent::Start,
            column_gap: Val::Px(10.),
            ..Default::default()
        },
        ..default() })
        .with_children(|builder| {
            let text_style = TextStyle {
                font: asset_server.load("fonts/FiraSans-Bold.ttf"),
                font_size: 20.0,
                color: Color::WHITE,
            };
            builder.spawn(TextBundle {
                text: Text::from_section(
                    "Display::None\nVisibility::Hidden\nVisibility::Inherited",
                    TextStyle { color: HIDDEN_COLOR, ..text_style.clone() }
                ).with_alignment(TextAlignment::Center),
                ..Default::default()
            });
            builder.spawn(TextBundle {
                text: Text::from_section(
                    "-\n-\n-",
                    TextStyle { color: Color::DARK_GRAY, ..text_style.clone() }
                ).with_alignment(TextAlignment::Center),
                ..Default::default()
            });
            builder.spawn(TextBundle::from_section(
                "The UI Node and its descendants will not be visible and will not be allotted any space in the UI layout.\nThe UI Node will not be visible but will still occupy space in the UI layout.\nThe UI node will inherit the visibility property of its parent. If it has no parent it will be visible.",
                text_style
            ));
        }).id();

In order to format the text it is displayed in three vertical columns. It's extremely unclear what this code is meant to do without running the example to see the displayed output.

A more natural way to write this would be to use tab escape sequences:

commands.spawn(
        TextBundle::from_section(
            "Display::None\t-\tThe UI Node and its descendants will not be visible and will not be allotted any space in the UI layout.\n\
            Visibility::Hidden\t-\tThe UI Node will not be visible but will still occupy space in the UI layout.\n\
            Visibility::Inherited\t-\tThe UI node will inherit the visibility property of its parent. If it has no parent it will be visible.",
        TextStyle {
            font: asset_server.load("fonts/FiraSans-Bold.ttf"),
            font_size: 20.0,
            color: Color::WHITE,
        }).with_alignment(TextAlignment::Center),
    );

What solution would you like?

It seems tricky to add tabs from within bevy_text itself and glyph_brush_layout ignores \t.
Maybe the cosmic text implementation will support tabs, I'm not sure.

@ickshonpe ickshonpe added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Sep 11, 2023
@rparrett
Copy link
Contributor

Rendering tabs would be nice. But I don't know if I've ever seen an implementation that would render as expected. I think there's usually some sort of column width limitation if tabs are supported at all.

Here's a selection of examples from a few apps on this machine:

image

The bottom is cosmic-text's editor-libcosmic example, so I don't think it can save us in this instance.

@rparrett rparrett added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Sep 11, 2023
@ickshonpe
Copy link
Contributor Author

Yeah it's not a great example, maybe using grid would be a better approach there.

I'm starting to have some really terrible ideas about how to hack tabs into current bevy, need to find something useful to do before I waste my time implementing them.

@nicoburns nicoburns added the A-Text Rendering and layout for characters label May 16, 2024
@rparrett
Copy link
Contributor

rparrett commented Aug 22, 2024

On Bevy main:
image

It looks like support for tabs was added in cosmic-text 0.12
https://github.com/pop-os/cosmic-text/blob/main/CHANGELOG.md#0120---2024-06-18

@rparrett rparrett reopened this Aug 22, 2024
@rparrett
Copy link
Contributor

I would like to test in a cosmic-text example again to see if being able to modify the tab width would get the behavior you were after.

@rparrett
Copy link
Contributor

rparrett commented Aug 23, 2024

It does seem that this would be fixable if we exposed the tab width option for cosmic buffers.

(Text above modified to only include first tab of each line, and tab width set to 11)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

3 participants