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

Impl from Box<str> for WidgetText, RichText #5309

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

dimtpap
Copy link
Contributor

@dimtpap dimtpap commented Oct 27, 2024

Box<str> is an immutable heap-allocated string slice.
This PR makes it more convenient to use them in labels for example.

Before this PR

let text: Box<str> = "Hello".into();
ui.label(text.into_string());

let text_ref: &Box<str> = &"Hello".into();
ui.label(text_ref.clone().into_string());
// or
ui.label(text_ref.as_ref());
// or
ui.label(&**text_ref);

After this PR

let text: Box<str> = "Hello".into();
ui.label(text);

let text_ref: &Box<str> = &"Hello".into();
ui.label(text_ref);
  • I have followed the instructions in the PR template

Copy link
Collaborator

@lucasmerlin lucasmerlin left a comment

Choose a reason for hiding this comment

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

Nice!

crates/egui/src/widget_text.rs Show resolved Hide resolved
@lucasmerlin lucasmerlin added feature New feature or request egui labels Oct 27, 2024
Copy link

Preview available at https://egui-pr-preview.github.io/pr/5309-widgettext-from-boxstr
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

@emilk emilk merged commit ebb4646 into emilk:master Oct 29, 2024
25 of 26 checks passed
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
`Box<str>` is an immutable heap-allocated string slice.
This PR makes it more convenient to use them in labels for example.

Before this PR
```rust
let text: Box<str> = "Hello".into();
ui.label(text.into_string());

let text_ref: &Box<str> = &"Hello".into();
ui.label(text_ref.clone().into_string());
// or
ui.label(text_ref.as_ref());
// or
ui.label(&**text_ref);
```
After this PR
```rust
let text: Box<str> = "Hello".into();
ui.label(text);

let text_ref: &Box<str> = &"Hello".into();
ui.label(text_ref);
```

* [x] I have followed the instructions in the PR template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants