cancel
Showing results for 
Search instead for 
Did you mean: 

How do you reference the value in a TextArea from user code?

Al-E-Bags
Senior

Hi all.   I seem to be missing something fundamental here and I'm clearly looking in any direction but the right one for the appropriate information.  I want to be able to reference on screen values and use them for calculations in my code.  For example, I have 4 TextAreas on my GUI screen.  Each TextArea has 2 associated buttons (from which I can increment/decrement the values that are currently being displayed).  I need a pointer/reference to each of these values as arguments/parameters in my user functions. How do I do this?  I have been looking at the getWildcard() documentation but I can't seem to find an example of how it is used.  Can someone point me in the right direction?  Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello,

If you are increasing/decreasing the value using a button increment/decrement a variable in the button callback and use that value for your calculation. 

If you need to dispatch that value to model.cpp, you need to pass it over the presenter.

Example:

In the View.cpp:

void MainScreenView::increaseValue()
{
        temperature++;

        presenter->NewTemperatureSettingRequested(temperature);
}

void MainScreenView::decreaseValue()
{
        temperature--;

        presenter->NewTemperatureSettingRequested(temperature);
}

In the ppresenter.cpp:

void MainScreenPresenter::NewTemperatureSettingRequested(int temperature)
{
    model->NewTemperatureSettingRequested(temperature);
}

In model.cpp:

void Model::NewTemperatureSettingRequested(int temperature)
{
  /* Do what you want here or send it to the low layer for calculation */
}
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

10 REPLIES 10
SofLit
ST Employee

Hello,

If you are increasing/decreasing the value using a button increment/decrement a variable in the button callback and use that value for your calculation. 

If you need to dispatch that value to model.cpp, you need to pass it over the presenter.

Example:

In the View.cpp:

void MainScreenView::increaseValue()
{
        temperature++;

        presenter->NewTemperatureSettingRequested(temperature);
}

void MainScreenView::decreaseValue()
{
        temperature--;

        presenter->NewTemperatureSettingRequested(temperature);
}

In the ppresenter.cpp:

void MainScreenPresenter::NewTemperatureSettingRequested(int temperature)
{
    model->NewTemperatureSettingRequested(temperature);
}

In model.cpp:

void Model::NewTemperatureSettingRequested(int temperature)
{
  /* Do what you want here or send it to the low layer for calculation */
}
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
ferro
Senior III

Hi @Al-E-Bags 

in ./app folder is the value changed with buttons

ferro_0-1733912670961.png

 

Thanks @SofLit The solution seems to have been staring me in the face all along.  In error, I have been referencing  another, similarly named variable in a different function elsewhere in my code. 

void main_screenView::increase_layers()
{
	layers_count = (layers_count++ > LAYERS_UPPER_LIMIT) ? LAYERS_UPPER_LIMIT : layers_count;

	//	call the helper function
	update_layers_widgets();

	//	do something else...
}

void main_screenView::decrease_layers()
{
	layers_count = (layers_count-- <= LAYERS_LOWER_LIMIT) ? LAYERS_LOWER_LIMIT : layers_count;

	//	call the helper function
	update_layers_widgets();

	//	do something else...
}

void main_screenView::update_layers_widgets()
{
	Unicode::snprintf(layers_data_areaBuffer, 3, "%d", layers_count);

	if (layers_count < LAYERS_UPPER_LIMIT)
	{
		layers_up_btn.setTouchable(true);
	}
	else
	{
		layers_up_btn.setTouchable(false);
	}
	if (layers_count > LAYERS_LOWER_LIMIT)
	{
		layers_down_btn.setTouchable(true);
	}
	else
	{
		layers_down_btn.setTouchable(false);
	}

	// Invalidate the data areas to refresh the display
	layers_data_area.invalidate();
	layers_up_btn.invalidate();
	layers_down_btn.invalidate();

	//	do something else...
}

 I adapted the above functions from one of the TouchGFX examples a while back and then proceeded to forget all about them! I needed to re-focus and your suggestions made me do just that.  Please explain the benefits involved in dispatching these values to model.cpp and passing them over to the presenter, I'd be interested to learn. 

Thanks for your help @ferro . I think the problem has been resolved.

ferro
Senior III

@Al-E-Bags   I do not see anything in common between your question and what you say is the solution. Could you please explain ?

 

Question - buttons and changing a value:

ferro_0-1733940570690.png

 

Answer - layers:

ferro_1-1733940613225.png

 

@ferro the accepted solution actually belongs to @SofLit .  I really don't know what was going on this morning as I was trying to post my reply but the post was refused by the moderator on two separate occasions.  I had no intention of accepting my own reply as the solution however, this is how it turned out.  Perhaps @SofLit can mark his reply as the solution instead.  If so, things would make more sense.

In answer to your question, I just wasn't referencing correct variable to begin with.  The code sample that I provided was simply to illustrate that the solution I was seeking was indeed, already implemented in my code.     

 

  

"I really don't know what was going on this morning as I was trying to post my reply but the post was refused by the moderator on two separate occasions."

Okay, I see. All good. Might be some glitch in a system.


@Al-E-Bags wrote:

 Perhaps @SofLit can mark his reply as the solution instead.  If so, things would make more sense.    

  


In that case you can unmark your comment as following

SofLit_1-1733944676752.png

And mark the comment that answered your question.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

"Please explain the benefits involved in dispatching these values to model.cpp and passing them over to the presenter, I'd be interested to learn."

This is sth I would like to understand better as well, what is the motivation. I think a candidate for a separate post even though I think I saw few already exactly about MVP topic.