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

Option to truncate text in Label #1727

Closed
AlanRace opened this issue Jun 10, 2022 · 2 comments · Fixed by #3244
Closed

Option to truncate text in Label #1727

AlanRace opened this issue Jun 10, 2022 · 2 comments · Fixed by #3244
Assignees
Labels
feature New feature or request
Milestone

Comments

@AlanRace
Copy link
Contributor

AlanRace commented Jun 10, 2022

Label currently ignores the max size when adding via add_sized. This only seems to be taken into account when wrap is set to true. I would ideally like to set a maximum size for the label and then simply have it not display any text that doesn't fit in the specified width (possibly replacing it with ... to indicate the full label is not being displayed).

ui.horizontal(|ui| {
    ui.add_sized([100.0, 10.0], egui::Label::new("My very long description"));
    ui.button("Remove");
}

Regardless of the specified width in add_sized, the label is displayed in full.

As a proposed solution, perhaps an API similar to the below:

/// Describes how to handle exceeding allocated size for the widget (label)
enum ExceedDimension {
     /// Force extend the dimension (e.g. width/height) of the label so that all text is displayed
     Extend,
     /// Wrap the text so that it fits within the specified width, but 
     /// potentially extends the height past the requested size
     Wrap,
     /// Truncate text so that it fits within the specified bounds
     Truncate,
}

// ...

ui.horizontal(|ui| {
    ui.add_sized(
        [100.0, 10.0], 
        egui::Label::new("My very long description").on_exceed_width(ExceedDimension::Truncate)
    );
    ui.button("Remove");
}

Alternatively, maybe there is a different way to achieve what I am trying to achieve - essentially as in the example above, I would like to always have the button visible at the cost of the full description. This appears in a SidePanel so I want the width to be tied to the current width of the SidePanel (minus the width of the button) so that the button always appears at the very right of the screen/panel.

@AlanRace AlanRace added the bug Something is broken label Jun 10, 2022
@emilk emilk changed the title Label ignores maximum size when using add_sized Option to truncate text in Label Jul 21, 2022
@emilk
Copy link
Owner

emilk commented Jul 21, 2022

Truncating with would be a nice option to have.

@abey79
Copy link
Collaborator

abey79 commented Aug 9, 2023

I concur, I would really like to have this feature :)

@abey79 abey79 added feature New feature or request and removed bug Something is broken labels Aug 9, 2023
@emilk emilk added this to the 0.23.0 milestone Aug 10, 2023
@emilk emilk self-assigned this Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants