Implementing the event/command handling

The Counter is derived from a tbx::TextChangedListener and uses the following code which is called when the text changes in the WritableField.

void Counter::text_changed(TextChangedEvent &event)
{
    // _count is the DisplayField set in the auto_created
    // code above.
    
    // The event returns the new value of the text
    // Use the tbx::to_string utility as the display
    // field expects text, not an integer.
    _count.text(to_string(event.text().length()));
}

Finally we just need to define the execute for our ReverseCommand as follows.

void ReverseCommand::execute()
{
    // _reverse is the WritableField set in the auto_created
    // code above.

    // Get the current value of the WritableField
    std::string value = _reverse.text();

    // Simple STL code to reverse a piece of text
    std::string reverse;
    reverse.append(value.rbegin(), value.rend());

    // Set the value of the WritableField with the reversed text
    _reverse.text(reverse);
}