Textfields + misc

it is stored off in the widget. Or it if isn’t you can do it yourself. My goodness, just go write some code, this stuff isn’t very unusual or complicated.

I think the best way to do this is to have the text field widget keep a reference to the module. Using the same naming as above, I would create a custom text field widget:

struct CustomTextFieldWidget : LedDisplayTextField
{
  PitchLog* pitchLogModule;

  CustomTextFieldWidget() {
    LedDisplayTextField();
  }
  void step() override {
    /* this text field widget can access the module eg:
    
    if(pitchLogModule) { //dont leave out this check
      pitchLogModule->someModuleMethod();
    }
    */

   //call the inherited step method
   LedDisplayTextField::step();
  }
}

The custom widget needs to have its module set, probably in the ModuleWidget’s constructor:

struct PitchLogWidget : ModuleWidget {
	PitchLogWidget(PitchLog* module) {
		setModule(module);
        customTextFieldInstance = createWidget<CustomTextFieldWidget>(xLocation,yLocation);
        customTextFieldInstance->pitchLogModule = module;
        addChild(customTextFieldInstance);
    }
    CustomTextFieldWidget *customTextFieldInstance;
}

Welcome to the forum! It took me quite a while to figure out the correct way to manage text fields in VCV Rack modules so I totally relate to the confusion.

Ah, thank you that makes a lot more sense.

1 Like

Be warned, that your moduleWidget will be constructed without a module when it gets displayed in the browser. So you must make sure that the pitchLogModule member is not null before you try to use it.

1 Like