-
Notifications
You must be signed in to change notification settings - Fork 12
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
How to pass a font asset handle to a style builder? #29
Comments
Hmmm, not sure why this doesn't work. That being said, there's a few things you can do right now:
|
Thanks, but I ended up inserting Element::<NodeBundle>::new()
.insert(InheritableFontStyles {
...
})
I'll try this if I ever need to override the font on a specific node.
This won't work well for me, because I want to have the font fully loaded before the game starts (I'm using bevy_asset_loader) EDIT: It looks like even when passing it as dep with To clarify, this is what my resource looks like: #[derive(AssetCollection, Clone, Resource, PartialEq, PartialOrd, Eq)]
pub struct MyAssets {
#[asset(path = "foobar.png")]
pub foobar: Handle<Image>,
// ...and tens of other asset fields
} I wonder if there's a more efficient approach that avoids cloning. |
Ok, I figured it out: #[derive(Clone, PartialEq)]
pub struct MyUi;
impl ViewTemplate for MyUi {
type View = impl View;
fn create(&self, cx: &mut Cx) -> Self::View {
let font_assets = cx.use_resource::<MyFontAssets>();
let font = font_assets.comic_sans.clone();
Element::<NodeBundle>::new().style(move |ss: &mut StyleBuilder| {
ss.font(font.clone()); // <- you need to clone it so that the closure becomes `Fn`
// See: https://doc.rust-lang.org/std/keyword.move.html
})
}
} It seems that this is more of a Rust issue, so I think I'll close this. But before that, would it be possible for |
FnOnce: Certainly worth investigating. |
I'm trying to pass a handle:
But it doesn't work because the style builder function must be
Fn
:Is there a way to make font handles work with quill?
The text was updated successfully, but these errors were encountered: