rust-sfml icon indicating copy to clipboard operation
rust-sfml copied to clipboard

Creating Fonts on the heap

Open dfannius opened this issue 8 years ago • 1 comments

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<Font>, 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.

dfannius avatar Jul 27 '17 20:07 dfannius

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.

crumblingstatue avatar Jul 27 '17 20:07 crumblingstatue