iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
23.41k stars 1.07k forks source link

Customizable Text/TextInput Representation #1050

Open NathanSWard opened 2 years ago

NathanSWard commented 2 years ago

Currently Text/TextInput are defined as follows:

struct Text {
    content: String,
    ..
}

struct TextInput<..> {
    placeholder: String,
    ..
}

I have come across use cases where it would be nice to use a Cow<str> or just a &'static str to avoid unnecessary memory allocations. I believe it would be beneficial to make these type generic of the string type.

e.g.

struct Text<S: AsRef<str>> {
    content: S,
    ..
}

Any thoughts? I'd be willing to make a PR for this if people are willing to accept this change :smile:

NathanSWard commented 2 years ago

Note: AsRef<str> wouldn't quite work for TextInput but there are other possible solutions :)

RamType0 commented 2 years ago

Sorry, I want this and I implemented it.