Skip to content
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

Creating Fonts on the heap #164

Open
dfannius opened this issue Jul 27, 2017 · 1 comment
Open

Creating Fonts on the heap #164

dfannius opened this issue Jul 27, 2017 · 1 comment
Labels

Comments

@dfannius
Copy link

I'm using rust-sfml and I'd like to encapsulate all my rendering into a Renderer struct that has methods like handle_events(), draw(), etc., so none of the rest of my code needs to worry about rendering.

https://gist.github.com/dfannius/963d17ca466ceb00373dfbb680a862e1 shows a minimal example of the issue I'm running into. I'd like the Renderer to do all its resource acquisition on construction, but if I create a Font inside new, it doesn't live long enough. I'd like to create it on the heap and give Text an Rc, but Text as currently implemented doesn't support that.

As it is, I can pass a &Font into the constructor, but that just moves the problem up one level (the Renderer can't live outside of the enclosing function).

Anyway, I don't know what the best solution is, but that is my use case.

@crumblingstatue
Copy link
Collaborator

Having a way to use Rc<Font> is desirable, but a satisfying design hasn't been reached yet.

There is a test implementation here for Texture/Sprite, the same could be done for Font/Text.

Other than that, for now, you pretty much have to load all your resources upfront, and construct anything that uses them afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants