cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing View from Container

GMeur
Senior

Hello,

I'm a complete beginner of TouchGFX as I've just started exploring what it's got under the hood. I'm rather perplexed as to how I can access an element of a given screen from a container of said screen.

Let me elaborate. In the main screen, I've two containers C1 and C2. One (C1) that's invisible by default and that I'd like to render visible from a button click of C2. How can I accomplish that simply ? I'm sure it's straightforward but I don't know which function I've got to use for that. Note that both containers are statically loaded.

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

Hi @GMeur​,

Here it is. A project that defines a screen with two custom containers (Both CustomContainer1). CustomContainer1 has a background and a ClickListener Box. When the Box is pressed, the CustomContainer catches this in an internal handler and then calls a Callback (set by the view) to communicate it's identity back. Based on this identity (The first or the second custom container) it will show/hide the custom containers.

I've written some comments in the code - Let me know if you need more information.

Best regards,

Martin

View solution in original post

3 REPLIES 3
Martin KJELDSEN
Chief III

Hi @GMeur​,

Screens have a root container that you add drawables to (Like Containers). The children are not aware of each other. What you want to do is have your C1 button call back to it's parent view and in that handler decide what to do. In this case, show C2.

I've already promised someone else i'd provide an example of how to make this coupling between containers and view. It's not something that's well integrated into the designer, sending arbitrary signals between elements. I will update this post once i get it done!

Hope that helps

Best regards,

Martin

Martin KJELDSEN
Chief III

Hi @GMeur​,

Here it is. A project that defines a screen with two custom containers (Both CustomContainer1). CustomContainer1 has a background and a ClickListener Box. When the Box is pressed, the CustomContainer catches this in an internal handler and then calls a Callback (set by the view) to communicate it's identity back. Based on this identity (The first or the second custom container) it will show/hide the custom containers.

I've written some comments in the code - Let me know if you need more information.

Best regards,

Martin

GMeur
Senior

Thanks. Very clear. It helps me a lot :)