2024-12-11 12:29 AM
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.
Solved! Go to Solution.
2024-12-11 12:46 AM
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 */
}
2024-12-11 12:46 AM
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 */
}
2024-12-11 02:26 AM
2024-12-11 03:58 AM
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.
2024-12-11 04:00 AM
Thanks for your help @ferro . I think the problem has been resolved.
2024-12-11 10:11 AM - edited 2024-12-11 10:12 AM
@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:
Answer - layers:
2024-12-11 11:08 AM
@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.
2024-12-11 11:15 AM
"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.
2024-12-11 11:17 AM - edited 2024-12-11 11:17 AM
@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
And mark the comment that answered your question.
2024-12-11 11:18 AM
"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.