cancel
Showing results for 
Search instead for 
Did you mean: 

What is best practice for formatting TextArea wildcard strings in MVP model?

wired
Senior III

I'm no MVP expert, so would like to get the opinion of those who are.

I have a slider on a screen that controls the displayed value of a parameter in a TextArea widget above the slider. The slider position is converted to a floating point value and also scaled to be useful to my backend processing. For example, if I have a parameter that increments by 0.05, a value that I want to display as 5.05 would be presented as an integer scaled by 20 from the slider (e.g. 101), and then divided by 20 to produce the formatted string for the wildcard of the TextArea.

Currently in my View's SetupScreen(), I have:

ch2Amp = presenter->getCh2Amp();
Unicode::snprintfFloat(textArea_ch2ampvalBuffer, 20, "%#.2f", ((float)ch2Amp / 20.0));

I also have a method called when the slider changes value:

void ScreenCH2AdjustView::AmpSliderChanged(int value)
{
    presenter->saveCh2Amp(value);
 
    Unicode::snprintfFloat(textAreaParamAmpBuffer, 20, "%#.2f", ((float)value / 20.0));
    textAreaParamAmp.invalidate();
}

So the slider value is saved in the model, but is scaled for display. My question is which is best form for adherence to the MVP model?

A) Perform all scaling and text formatting in the View.

B) Scale the value in the Presenter, but still create and display the formatted wildcard in the View.

C) Provide a pointer to the wildcard buffer to the Presenter, and perform all scaling and formatting of the wildcard buffer in the Presenter.

D) Something else (please suggest).

Thanks in advance for the advice.

1 REPLY 1
Yoann KLEIN
ST Employee

Hello @wired​ ,

For me, it depends if you want to use this Slider value in only one screen or several.

If you just want to get this value from a widget of one screen, then adapt this value and display it in a TextArea of the same screen, I see no issues with implementing everything in the ScreenView.cpp and saving value in the model through the presenter.

But, if you plan to display or use this value in several screens, I strongly advice you to move the scaling and formatting part in the model, and then create a virtual function in the presenter to propagate this value to the different screens afterwards. So you would just will have to redeclare this function in every screen you want and you are assured to have the same data displayed.

Of course, that's my personal opinion. As long as it works and it's robust, you should do it the way you are the most comfortable with.

Hope that this helps,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX