`ui.label("static string")` is a very common use case,
and currently egui clones the string in these cases.
This PR introduces a new type:
``` rust
pub enum Estring {
Static(&'static str),
Owned(Arc<str>),
}
```
which is used everywhere text is needed, with
`impl Into<Estring>` in the API for e.g. `ui.label`.
This reduces the number of copies drastically and speeds up
the benchmark demo_with_tessellate__realistic by 17%.
This hurts the ergonomics of egui a bit, and this is a breaking change.
For instance, this used to work:
``` rust
fn my_label(ui: &mut egui::Ui, text: &str) {
ui.label(text);
}
```
This must now either be changed to
``` rust
fn my_label(ui: &mut egui::Ui, text: &str) {
ui.label(text.to_string());
}
```
(or the argument must be changed to either
`text: &'static str` or `text: String`)
This PR introduces a completely rewritten text layout engine which is simpler and more powerful. It allows mixing different text styles (heading, body, etc) and formats (color, underlining, strikethrough, …) in the same layout pass, and baked into the same `Galley`.
This opens up the door to having a syntax-highlighed code editor, or a WYSIWYG markdown editor.
One major change is the color is now baked in at layout time. However, many widgets changes text color on hovered. But we need to do the text layout before we know if it is hovered. Therefor the painter has an option to override the text color of a galley.
## Performance
Text layout alone is about 20% slower, but a lot of that is because more tessellation is done upfront. Text tessellation is now a lot faster, but text layout + tessellation still lands at a net loss of 5-10% in performance. There are however a few tricks to speed it up (like using `smallvec`) which I am saving for later. Text layout is also cached, meaning that in most cases (when all text isn't changing each frame) text tessellation is actually more important (and that's more than 2x faster!).
Sadly, the actual text cache lookup is significantly slower (300ns -> 600ns). That's because the `TextLayoutJob` is a lot bigger (it has more options, like underlining, fonts etc), so it is slower to hash and compare. I have an idea how to speed this up, but I need to do some other work before I can implement that.
All in all, the performance impact on `demo_with_tesselate__realistic` is about 5-6% in the red. Not great; not terrible. The benefits are worth it, but I also think with some work I can get that down significantly, hopefully down to the old levels.