cancel
Showing results for 
Search instead for 
Did you mean: 

How to access and modify each of custom container individual widget?

BParh.1
Senior III

Assume I create a custom container , containing just a box with a wild card text. Then I create 3 widget instances from this custom container. Now I want for each of container to have different text in the widcard text. How can I do this? How can I access individual widget member in each of the custom container instance?

1 ACCEPTED SOLUTION

Accepted Solutions
BParh.1
Senior III

One solution I can think of is to add one function e.g. setParamValue() in CustomContainer1 class like this, then call this in every instance of the custom container:

class CustomContainer1 : public CustomContainer1Base
{
public:
    CustomContainer1();
    virtual ~CustomContainer1() {}
 
    virtual void initialize();
    void setParamValue(float fval) {
        Unicode::snprintfFloat(
            textArea1Buffer,
            TEXTAREA1_SIZE,
            "%4.1f",
            fval);
        textArea1.resizeToCurrentText();
        textArea1.invalidate();
    }
protected:
};

View solution in original post

7 REPLIES 7
MHaji.1
Senior

Hi,

Each object which you created, has an ID (Object name), So you can access to that class with that object name. you can change your text with is object access.

Thank you @MHaji.1​ , do you happen to know the API name to access it? Or any code snippet?

BParh.1
Senior III

As an example, the generated base class:

class CustomContainer1Base : public touchgfx::Container
{
public:
    CustomContainer1Base();
    virtual ~CustomContainer1Base() {}
    virtual void initialize();
 
protected:
    FrontendApplication& application() {
        return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
    }
 
    /*
     * Member Declarations
     */
    touchgfx::Box bgParamTile;
    touchgfx::TextAreaWithOneWildcard textArea1;
 
    /*
     * Wildcard Buffers
     */
    static const uint16_t TEXTAREA1_SIZE = 7;
    touchgfx::Unicode::UnicodeChar textArea1Buffer[TEXTAREA1_SIZE];
 
private:
 
};

Then I have 3 instances of custom container, customContainer11, customContainer12, customContainer13.

Now I want to write into 'touchgfx::TextAreaWithOneWildcard textArea1' string "Hello from Container 1", "Hello from Container 2", "Hello from Container 3" to

customContainer11, customContainer12, customContainer13 respectively in on my home screen.

void HomeView::setupScreen()
{
    HomeViewBase::setupScreen();
    // TODO: write different text to different container 
  // How to do it?
}

How can I achieve this? If I just dot the object say customContainer11, I could not see member textArea1Buffer

BParh.1
Senior III

Ok so I realized instance of customed container e.g. customContainer11 cannot access the text buffer textArea1Buffer[TEXTAREA1_SIZE] since it is declared as protected in class CustomContainer1Base.

But basically my intention is to have different instances of custom container which each contain a text area. But I want to customize what is written in each of text buffer. What is the best practice for it?

BParh.1
Senior III

One solution I can think of is to add one function e.g. setParamValue() in CustomContainer1 class like this, then call this in every instance of the custom container:

class CustomContainer1 : public CustomContainer1Base
{
public:
    CustomContainer1();
    virtual ~CustomContainer1() {}
 
    virtual void initialize();
    void setParamValue(float fval) {
        Unicode::snprintfFloat(
            textArea1Buffer,
            TEXTAREA1_SIZE,
            "%4.1f",
            fval);
        textArea1.resizeToCurrentText();
        textArea1.invalidate();
    }
protected:
};

Yes you need setter methods in contaniner and for better readability in hpp only

    virtual void selit(bool sel);
    virtual void setParamValue(float fval);
    virtual void setIco(const Bitmap& bmp);
    virtual void setLabel(TypedText t);

and code for this in container cpp file.

Alexandre RENOUX
Principal

Hi BParh.1,

This is a C++ question. When you want to access some object declared in another class you need getters and setters.

Fortunately, you found out yourself and MM..1 provided you with some precisions.

If your question is answered, please close this topic by choosing Select as Best.

/Alexandre