How to retrieve "path" within a widget?

Hi,

I’m making a custom widget such a knob, which some fancy text. I’d like to setup a custom font:

mFont = APP->window->loadFont(path + "res/fonts/MyFont.ttf");

But I’m not sure how to take the path variable. Within a module, I simply do path = asset::plugin(pluginInstance, ""), but within the widget, I don’t have the instance of the plugin.

I don’t want to pass it to it (separation of context). Is there any “static” call that I can use from within the Widget to retrieve the module path?

Thanks :slight_smile:

How I personnaly do it is to pass the font as a constructor argument :

TextLabel(const std::shared_ptr<Font> font) {
    ...
}

This is the correct way.

mFont = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/MyFont.ttf"));

Why not? You need to define it as a global and set it. See any plugin for an example.

I’m within a Knob.hpp file. I have the path within plugin.cpp, as the Plugin *pluginInstance; variabile. Can’t access from Knob.hpp :open_mouth:

Typically you declare that global in plugin.hpp which should be included by all module source code files. E.g. https://github.com/VCVRack/ESeries/blob/v1/src/plugin.hpp#L7

1 Like

Ah extern, I see what you mean! Got it, thanks!