Skip to content

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!

@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