Conversation
600c168 to
3da113d
Compare
druid/examples/styled_text.rs
Outdated
| .env_scope(|env: &mut druid::Env, data: &AppData| { | ||
| env.set(MY_CUSTOM_TEXT_SIZE, data.size); | ||
| if data.mono { | ||
| env.set(theme::FONT_NAME, "monospace"); |
There was a problem hiding this comment.
The current thinking on "idiomatic" druid (a WIP) is to use a custom key and override that (like with MY_CUSTOM_TEXT_SIZE) instead of overriding a default key
There was a problem hiding this comment.
Trying to set the custom font name to the current theme name causes errors due to borrowing the env when I borrow the font name. I think adjustments may need to be made to the current env system to make this work.
There was a problem hiding this comment.
you might need to clone the name before passing it back in or something?
Curious to see what your problem was.
druid/src/env.rs
Outdated
| } | ||
| } | ||
|
|
||
| impl Into<Value> for &$ty { |
There was a problem hiding this comment.
Just flagging this as interesting, I don't understand this enough to comment usefully.
There was a problem hiding this comment.
This is where we just about reach the limit of my experience and understanding of the system. Without that it's impossible to use into to turn a Key<&str> into a KeyOrValue<&str>, since you can't into a &str into a Value, and it's not possible to use KeyOrValue<String> since the Key<T> and KeyOrValue<T> have to match. I'm certain there are more elegant ways to do this, but I don't understand the system well enough to know how to implement them.
There was a problem hiding this comment.
I think you want a Key<String>, which can be borrowed as a &str with a lifetime derived from the value. This is similar to how you can use a &str to check if an item exists in a HashSet<String>?
Or to clarify more: a Key<String> will return a &str when you get it from the env.
There was a problem hiding this comment.
I started a topic in zulip to discuss implementation details.
cmyr
left a comment
There was a problem hiding this comment.
This seems generally reasonable; it's slightly annoying that we need the 'static lifetime but I can't really think of a viable workaround, unless we store all strings as Arc<str> and just clone them instead of trying to get fancy with references.
druid/examples/styled_text.rs
Outdated
| format!( | ||
| "Size {:.1}{}: {}", | ||
| data.size, | ||
| if data.mono { " mono" } else { "" }, |
There was a problem hiding this comment.
huh, I'm surprised that rustfmt doesn't break this up.
In any case, as this starts to get longer I think I would consider just implementing Display (or some to_label_text() method) for our AppData type, and then this can be clearer.
druid/examples/styled_text.rs
Outdated
| .env_scope(|env: &mut druid::Env, data: &AppData| { | ||
| env.set(MY_CUSTOM_TEXT_SIZE, data.size); | ||
| if data.mono { | ||
| env.set(theme::FONT_NAME, "monospace"); |
There was a problem hiding this comment.
you might need to clone the name before passing it back in or something?
Curious to see what your problem was.
druid/examples/styled_text.rs
Outdated
| ) | ||
| }) | ||
| .with_text_color(theme::PRIMARY_LIGHT) | ||
| .with_text_size(MY_CUSTOM_TEXT_SIZE) |
There was a problem hiding this comment.
I think this should be trying to use the with_font method we've added?
|
@thecodewarrior I think this is on reasonable shape; would you like to rebase and address feedback and I can take another look? |
178cd07 to
0f8a8aa
Compare
|
I think I've addressed all your comments. The example now uses a custom key (doing |
cmyr
left a comment
There was a problem hiding this comment.
cool, this looks good; one comment inline.
druid/src/widget/label.rs
Outdated
|
|
||
| /// Builder-style method for setting the font. | ||
| /// | ||
| /// The argument can be a `&'static str`, `String`, or [`Key<&'static str>`]. |
There was a problem hiding this comment.
Can you verify that this actually doesn't work with a non-static str? I would expect it to.
0f8a8aa to
b36625c
Compare
|
Yup, it works with a plain |
|
@thecodewarrior ping on this? seems like it was very close to ready to go. |
…l-font # Conflicts: # druid/examples/styled_text.rs
|
Everything should be ready to go. Were there any other changes that you wanted before you merged? |
Issue #774
This adds an option to
Labelto configure which font it uses. It's a simple implementation using aKeyOrValue<&'static str>. While it's likely possible to adjust the system to not need the cumbersome&'static str(which also doesn't allow dynamic strings), I have neither the Rust experience nor the depth of understanding of the current system necessary to know how to do that elegantly.